Page MenuHomePhorge

No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None
diff --git a/includes/title/Title.php b/includes/title/Title.php
index c94702246ee..4f8f4bf4dfc 100644
--- a/includes/title/Title.php
+++ b/includes/title/Title.php
@@ -82,6 +82,12 @@ class Title implements Stringable, LinkTarget, PageIdentity {
/** @var MapCacheLRU|null */
private static $titleCache = null;
+ /**
+ * Cached instance of the main page title, to speed up isMainPage() checks.
+ * @var Title|null
+ */
+ private static ?Title $cachedMainPage = null;
+
/**
* Title::newFromText maintains a cache to avoid expensive re-normalization of
* commonly used titles. On a batch operation this can become a memory leak
@@ -1380,10 +1386,8 @@ class Title implements Stringable, LinkTarget, PageIdentity {
* @return bool
*/
public function isMainPage() {
- /** @var Title|null */
- static $cachedMainPage;
- $cachedMainPage ??= self::newMainPage();
- return $this->equals( $cachedMainPage );
+ self::$cachedMainPage ??= self::newMainPage();
+ return $this->equals( self::$cachedMainPage );
}
/**
@@ -2692,6 +2696,9 @@ class Title implements Stringable, LinkTarget, PageIdentity {
$linkCache->clear();
}
+ // Reset cached main page instance (T395214).
+ self::$cachedMainPage = null;
+
$titleCache = self::getTitleCache();
$titleCache->clear();
}
diff --git a/tests/phpunit/MediaWikiIntegrationTestCase.php b/tests/phpunit/MediaWikiIntegrationTestCase.php
index dc750d8056d..56013bd9d1e 100644
--- a/tests/phpunit/MediaWikiIntegrationTestCase.php
+++ b/tests/phpunit/MediaWikiIntegrationTestCase.php
@@ -541,6 +541,9 @@ abstract class MediaWikiIntegrationTestCase extends PHPUnit\Framework\TestCase {
TestUserRegistry::clear();
LoggerFactory::setContext( new LoggingContext() );
+
+ // Invalidate any Title objects cached by newFromText() or isMainPage() (T395214).
+ Title::clearCaches();
}
/**

File Metadata

Mime Type
text/x-diff
Expires
Sat, Jul 5, 5:32 AM (1 d, 42 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
227662
Default Alt Text
(1 KB)

Event Timeline