From: jenkins-bot Date: Thu, 14 Jun 2018 23:48:54 +0000 (+0000) Subject: Merge "Avoid deprecated LinkCache::singleton()" X-Git-Tag: 1.34.0-rc.0~5050 X-Git-Url: http://git.cyclocoop.org/%22.%20generer_url_ecrire%28%22sites%22%2C%22%22%29.%20%22?a=commitdiff_plain;h=84fa176c9c14cca4dee674c284deb6e6796d928a;hp=88e192b2dffe303703de01dbc40794e5f5336487;p=lhc%2Fweb%2Fwiklou.git Merge "Avoid deprecated LinkCache::singleton()" --- diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 405be1d2b2..0b2ba407eb 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1364,7 +1364,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 91d8de4921..ecbb1b6331 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' ); } @@ -3433,7 +3433,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 ); @@ -3463,7 +3463,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 ) { @@ -3497,7 +3497,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 ) { @@ -3525,7 +3525,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 ) { @@ -3550,7 +3550,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 ) { @@ -3572,7 +3572,7 @@ class Title implements LinkTarget { } public static function clearCaches() { - $linkCache = LinkCache::singleton(); + $linkCache = MediaWikiServices::getInstance()->getLinkCache(); $linkCache->clear(); $titleCache = self::getTitleCache(); @@ -3676,7 +3676,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 ) { @@ -3744,7 +3744,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 ); @@ -4943,7 +4943,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 24a70595a1..5bbdb6cdec 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -527,7 +527,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 ) { @@ -1367,7 +1367,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 42d5db70b8..99ca07a01d 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 38bc95e802..a1b306434b 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -3635,7 +3635,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 e2f9834ca5..4140c23b14 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -1540,7 +1540,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(); } } } @@ -1657,7 +1657,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 );