Avoid deprecated LinkCache::singleton()
authorKunal Mehta <legoktm@member.fsf.org>
Mon, 11 Jun 2018 06:55:11 +0000 (23:55 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Mon, 11 Jun 2018 06:55:11 +0000 (23:55 -0700)
Change-Id: Ie0e5c4ef0fe6ec896378bb2433af0898655dd907

15 files changed:
includes/OutputPage.php
includes/Title.php
includes/api/ApiPageSet.php
includes/api/ApiParse.php
includes/page/WikiPage.php
includes/parser/CoreParserFunctions.php
includes/parser/LinkHolderArray.php
includes/parser/Parser.php
includes/parser/ParserOptions.php
maintenance/refreshLinks.php
tests/parser/ParserTestRunner.php
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/TitleMethodsTest.php
tests/phpunit/includes/TitleTest.php
tests/phpunit/includes/content/ContentHandlerTest.php

index 6700cdb..1dd6a41 100644 (file)
@@ -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;
        }
index 9711749..f326e5c 100644 (file)
@@ -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' );
                }
index 48303a5..515ebc5 100644 (file)
@@ -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 );
index 096122d..3a60471 100644 (file)
@@ -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 = [];
index e186279..8ed81a7 100644 (file)
@@ -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,
index 1ff8859..5d284ab 100644 (file)
@@ -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 ) {
index 1d722c2..939fe73 100644 (file)
@@ -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 = [];
 
index 15ed93c..586f926 100644 (file)
@@ -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 );
                        }
 
index 20bd599..5959281 100644 (file)
@@ -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 );
                } );
        }
 }
index 49f1cd1..9ca4e98 100644 (file)
@@ -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;
index 97175da..60a5881 100644 (file)
@@ -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();
index 6bcbd93..a619aac 100644 (file)
@@ -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();
                                }
                        }
 
index 4032b3a..e898c63 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @group ContentHandler
  * @group Database
@@ -353,7 +355,7 @@ class TitleMethodsTest extends MediaWikiLangTestCase {
         * @covers Title::clearCaches
         */
        public function testClearCaches() {
-               $linkCache = LinkCache::singleton();
+               $linkCache = MediaWikiServices::getInstance()->getLinkCache();
 
                $title1 = Title::newFromText( 'Foo' );
                $linkCache->addGoodLinkObj( 23, $title1 );
index c81a078..f9ffeae 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @group Database
  * @group Title
@@ -674,7 +676,7 @@ class TitleTest extends MediaWikiTestCase {
         */
        public function testExists() {
                $title = Title::makeTitle( NS_PROJECT, 'New page' );
-               $linkCache = LinkCache::singleton();
+               $linkCache = MediaWikiServices::getInstance()->getLinkCache();
 
                $article = new Article( $title );
                $page = $article->getPage();
index 309b7b1..9a1c90f 100644 (file)
@@ -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 );