From c4e5a9dd97ce98e410fcdee8c5fda96f03fd8b25 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Sun, 10 Jun 2018 23:55:11 -0700 Subject: [PATCH] Avoid deprecated LinkCache::singleton() Change-Id: Ie0e5c4ef0fe6ec896378bb2433af0898655dd907 --- includes/OutputPage.php | 3 ++- includes/Title.php | 20 +++++++++---------- includes/api/ApiPageSet.php | 5 +++-- includes/api/ApiParse.php | 2 +- includes/page/WikiPage.php | 5 +++-- includes/parser/CoreParserFunctions.php | 2 +- includes/parser/LinkHolderArray.php | 6 ++++-- includes/parser/Parser.php | 2 +- includes/parser/ParserOptions.php | 9 ++++++--- maintenance/refreshLinks.php | 3 ++- tests/parser/ParserTestRunner.php | 2 +- tests/phpunit/MediaWikiTestCase.php | 4 ++-- tests/phpunit/includes/TitleMethodsTest.php | 4 +++- tests/phpunit/includes/TitleTest.php | 4 +++- .../includes/content/ContentHandlerTest.php | 6 +++--- 15 files changed, 45 insertions(+), 32 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 6700cdbb49..1dd6a41927 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1368,7 +1368,8 @@ class OutputPage extends ContextSource { ); # Add the results to the link cache - $lb->addResultToCache( LinkCache::singleton(), $res ); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); + $lb->addResultToCache( $linkCache, $res ); return $res; } diff --git a/includes/Title.php b/includes/Title.php index 9711749d33..f326e5cf5c 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -979,7 +979,7 @@ class Title implements LinkTarget { && ( !$this->mContentModel || $flags === self::GAID_FOR_UPDATE ) && $this->getArticleID( $flags ) ) { - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $linkCache->addLinkObj( $this ); # in case we already had an article ID $this->mContentModel = $linkCache->getGoodLinkFieldObj( $this, 'model' ); } @@ -3430,7 +3430,7 @@ class Title implements LinkTarget { $this->mArticleID = 0; return $this->mArticleID; } - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); if ( $flags & self::GAID_FOR_UPDATE ) { $oldUpdate = $linkCache->forUpdate( true ); $linkCache->clearLink( $this ); @@ -3460,7 +3460,7 @@ class Title implements LinkTarget { return $this->mRedirect; } - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $linkCache->addLinkObj( $this ); # in case we already had an article ID $cached = $linkCache->getGoodLinkFieldObj( $this, 'redirect' ); if ( $cached === null ) { @@ -3494,7 +3494,7 @@ class Title implements LinkTarget { $this->mLength = 0; return $this->mLength; } - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $linkCache->addLinkObj( $this ); # in case we already had an article ID $cached = $linkCache->getGoodLinkFieldObj( $this, 'length' ); if ( $cached === null ) { @@ -3522,7 +3522,7 @@ class Title implements LinkTarget { $this->mLatestID = 0; return $this->mLatestID; } - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $linkCache->addLinkObj( $this ); # in case we already had an article ID $cached = $linkCache->getGoodLinkFieldObj( $this, 'revision' ); if ( $cached === null ) { @@ -3547,7 +3547,7 @@ class Title implements LinkTarget { * @param int $newid The new Article ID */ public function resetArticleID( $newid ) { - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $linkCache->clearLink( $this ); if ( $newid === false ) { @@ -3569,7 +3569,7 @@ class Title implements LinkTarget { } public static function clearCaches() { - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $linkCache->clear(); $titleCache = self::getTitleCache(); @@ -3673,7 +3673,7 @@ class Title implements LinkTarget { $retVal = []; if ( $res->numRows() ) { - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); foreach ( $res as $row ) { $titleObj = self::makeTitle( $row->page_namespace, $row->page_title ); if ( $titleObj ) { @@ -3741,7 +3741,7 @@ class Title implements LinkTarget { ); $retVal = []; - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); foreach ( $res as $row ) { if ( $row->page_id ) { $titleObj = self::newFromRow( $row ); @@ -4940,7 +4940,7 @@ class Title implements LinkTarget { // check, if the page language could be saved in the database, and if so and // the value is not requested already, lookup the page language using LinkCache if ( $wgPageLanguageUseDB && $this->mDbPageLanguage === false ) { - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $linkCache->addLinkObj( $this ); $this->mDbPageLanguage = $linkCache->getGoodLinkFieldObj( $this, 'lang' ); } diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index 48303a5748..515ebc594c 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -771,7 +771,8 @@ class ApiPageSet extends ApiBase { // Store Title object in various data structures $title = Title::newFromRow( $row ); - LinkCache::singleton()->addGoodLinkObjFromRow( $title, $row ); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); + $linkCache->addGoodLinkObjFromRow( $title, $row ); $pageId = intval( $row->page_id ); $this->mAllPages[$row->page_namespace][$row->page_title] = $pageId; @@ -904,7 +905,7 @@ class ApiPageSet extends ApiBase { // Any items left in the $remaining list are added as missing if ( $processTitles ) { // The remaining titles in $remaining are non-existent pages - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); foreach ( $remaining as $ns => $dbkeys ) { foreach ( array_keys( $dbkeys ) as $dbkey ) { $title = Title::makeTitle( $ns, $dbkey ); diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 096122d186..3a604715bc 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -697,7 +697,7 @@ class ApiParse extends ApiBase { $hiddencats[$row->page_title] = isset( $row->pp_propname ); } - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); foreach ( $links as $link => $sortkey ) { $entry = []; diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index e1862799c3..8ed81a7e03 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -468,7 +468,7 @@ class WikiPage implements Page, IDBAccessObject { * the master DB using SELECT FOR UPDATE */ public function loadFromRow( $data, $from ) { - $lc = LinkCache::singleton(); + $lc = MediaWikiServices::getInstance()->getLinkCache(); $lc->clearLink( $this->mTitle ); if ( $data ) { @@ -1297,7 +1297,8 @@ class WikiPage implements Page, IDBAccessObject { $this->mLatest = $revision->getId(); $this->mIsRedirect = (bool)$rt; // Update the LinkCache. - LinkCache::singleton()->addGoodLinkObj( + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); + $linkCache->addGoodLinkObj( $this->getId(), $this->mTitle, $len, diff --git a/includes/parser/CoreParserFunctions.php b/includes/parser/CoreParserFunctions.php index 1ff8859cfb..5d284ab3b5 100644 --- a/includes/parser/CoreParserFunctions.php +++ b/includes/parser/CoreParserFunctions.php @@ -1162,7 +1162,7 @@ class CoreParserFunctions { } // Check the link cache, maybe something already looked it up. - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $pdbk = $t->getPrefixedDBkey(); $id = $linkCache->getGoodLinkID( $pdbk ); if ( $id != 0 ) { diff --git a/includes/parser/LinkHolderArray.php b/includes/parser/LinkHolderArray.php index 1d722c2cc3..939fe73ccd 100644 --- a/includes/parser/LinkHolderArray.php +++ b/includes/parser/LinkHolderArray.php @@ -21,6 +21,8 @@ * @ingroup Parser */ +use MediaWiki\MediaWikiServices; + /** * @ingroup Parser */ @@ -283,7 +285,7 @@ class LinkHolderArray { global $wgContLang; $colours = []; - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $output = $this->parent->getOutput(); $linkRenderer = $this->parent->getLinkRenderer(); @@ -451,7 +453,7 @@ class LinkHolderArray { $linkBatch = new LinkBatch(); $variantMap = []; // maps $pdbkey_Variant => $keys (of link holders) $output = $this->parent->getOutput(); - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $titlesToBeConverted = ''; $titlesAttrs = []; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 15ed93c5ff..586f9264e2 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -3631,7 +3631,7 @@ class Parser { $rev_id = $rev ? $rev->getId() : 0; # If there is no current revision, there is no page if ( $id === false && !$rev ) { - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $linkCache->addBadLinkObj( $title ); } diff --git a/includes/parser/ParserOptions.php b/includes/parser/ParserOptions.php index 20bd599925..59592818d0 100644 --- a/includes/parser/ParserOptions.php +++ b/includes/parser/ParserOptions.php @@ -20,6 +20,8 @@ * @file * @ingroup Parser */ + +use MediaWiki\MediaWikiServices; use Wikimedia\ScopedCallback; /** @@ -1386,11 +1388,12 @@ class ParserOptions { }; end( $wgHooks['TitleExists'] ); $key = key( $wgHooks['TitleExists'] ); - LinkCache::singleton()->clearBadLink( $title->getPrefixedDBkey() ); - return new ScopedCallback( function () use ( $title, $key ) { + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); + $linkCache->clearBadLink( $title->getPrefixedDBkey() ); + return new ScopedCallback( function () use ( $title, $key, $linkCache ) { global $wgHooks; unset( $wgHooks['TitleExists'][$key] ); - LinkCache::singleton()->clearLink( $title ); + $linkCache->clearLink( $title ); } ); } } diff --git a/maintenance/refreshLinks.php b/maintenance/refreshLinks.php index 49f1cd12f6..9ca4e986c8 100644 --- a/maintenance/refreshLinks.php +++ b/maintenance/refreshLinks.php @@ -21,6 +21,7 @@ * @ingroup Maintenance */ +use MediaWiki\MediaWikiServices; use Wikimedia\Rdbms\IDatabase; require_once __DIR__ . '/Maintenance.php'; @@ -258,7 +259,7 @@ class RefreshLinks extends Maintenance { public static function fixLinksFromArticle( $id, $ns = false ) { $page = WikiPage::newFromID( $id ); - LinkCache::singleton()->clear(); + MediaWikiServices::getInstance()->getLinkCache()->clear(); if ( $page === null ) { return; diff --git a/tests/parser/ParserTestRunner.php b/tests/parser/ParserTestRunner.php index 97175da631..60a58811d3 100644 --- a/tests/parser/ParserTestRunner.php +++ b/tests/parser/ParserTestRunner.php @@ -1281,7 +1281,7 @@ class ParserTestRunner { // Wipe some DB query result caches on setup and teardown $reset = function () { - LinkCache::singleton()->clear(); + MediaWikiServices::getInstance()->getLinkCache()->clear(); // Clear the message cache MessageCache::singleton()->clear(); diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 6bcbd938d8..a619aacce5 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -1486,7 +1486,7 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { if ( $tbl === 'page' ) { // Forget about the pages since they don't // exist in the DB. - LinkCache::singleton()->clear(); + MediaWikiServices::getInstance()->getLinkCache()->clear(); } } } @@ -1601,7 +1601,7 @@ abstract class MediaWikiTestCase extends PHPUnit\Framework\TestCase { if ( $tbl === 'page' ) { // Forget about the pages since they don't // exist in the DB. - LinkCache::singleton()->clear(); + MediaWikiServices::getInstance()->getLinkCache()->clear(); } } diff --git a/tests/phpunit/includes/TitleMethodsTest.php b/tests/phpunit/includes/TitleMethodsTest.php index 4032b3a120..e898c63124 100644 --- a/tests/phpunit/includes/TitleMethodsTest.php +++ b/tests/phpunit/includes/TitleMethodsTest.php @@ -1,5 +1,7 @@ getLinkCache(); $title1 = Title::newFromText( 'Foo' ); $linkCache->addGoodLinkObj( 23, $title1 ); diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index c81a07872e..f9ffeae924 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -1,5 +1,7 @@ getLinkCache(); $article = new Article( $title ); $page = $article->getPage(); diff --git a/tests/phpunit/includes/content/ContentHandlerTest.php b/tests/phpunit/includes/content/ContentHandlerTest.php index 309b7b1115..9a1c90fc29 100644 --- a/tests/phpunit/includes/content/ContentHandlerTest.php +++ b/tests/phpunit/includes/content/ContentHandlerTest.php @@ -101,7 +101,7 @@ class ContentHandlerTest extends MediaWikiTestCase { */ public function testGetForTitle( $title, $expectedContentModel ) { $title = Title::newFromText( $title ); - LinkCache::singleton()->addBadLinkObj( $title ); + MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title ); $handler = ContentHandler::getForTitle( $title ); $this->assertEquals( $expectedContentModel, $handler->getModelID() ); } @@ -158,7 +158,7 @@ class ContentHandlerTest extends MediaWikiTestCase { public function testGetPageLanguage( $title, $expected ) { if ( is_string( $title ) ) { $title = Title::newFromText( $title ); - LinkCache::singleton()->addBadLinkObj( $title ); + MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title ); } $expected = wfGetLangObj( $expected ); @@ -308,7 +308,7 @@ class ContentHandlerTest extends MediaWikiTestCase { $expectedModelId, $expectedNativeData, $shouldFail ) { $title = Title::newFromText( $title ); - LinkCache::singleton()->addBadLinkObj( $title ); + MediaWikiServices::getInstance()->getLinkCache()->addBadLinkObj( $title ); try { $content = ContentHandler::makeContent( $data, $title, $modelId, $format ); -- 2.20.1