Avoid using the deprecated ParserCache::singleton()
authorKunal Mehta <legoktm@member.fsf.org>
Sat, 9 Sep 2017 00:19:17 +0000 (17:19 -0700)
committerKunal Mehta <legoktm@member.fsf.org>
Sat, 9 Sep 2017 21:20:10 +0000 (14:20 -0700)
Change-Id: I0da6d9cbfad26c89bf5dab564071ef97acaf44f9

includes/api/ApiPurge.php
includes/jobqueue/jobs/RefreshLinksJob.php
includes/page/Article.php
includes/page/WikiPage.php
includes/poolcounter/PoolWorkArticleView.php
maintenance/compareParserCache.php

index 83227a2..35f93e0 100644 (file)
@@ -25,6 +25,7 @@
  * @file
  */
 use MediaWiki\Logger\LoggerFactory;
  * @file
  */
 use MediaWiki\Logger\LoggerFactory;
+use MediaWiki\MediaWikiServices;
 
 /**
  * API interface for page purging
 
 /**
  * API interface for page purging
@@ -98,7 +99,7 @@ class ApiPurge extends ApiBase {
                                                $r['linkupdate'] = true;
 
                                                if ( $enableParserCache ) {
                                                $r['linkupdate'] = true;
 
                                                if ( $enableParserCache ) {
-                                                       $pcache = ParserCache::singleton();
+                                                       $pcache = MediaWikiServices::getInstance()->getParserCache();
                                                        $pcache->save( $p_result, $page, $popts );
                                                }
                                        }
                                                        $pcache->save( $p_result, $page, $popts );
                                                }
                                        }
index 9f3550f..424fcec 100644 (file)
@@ -207,7 +207,7 @@ class RefreshLinksJob extends Job {
                        if ( $page->getTouched() >= $this->params['rootJobTimestamp'] || $opportunistic ) {
                                // Cache is suspected to be up-to-date. As long as the cache rev ID matches
                                // and it reflects the job's triggering change, then it is usable.
                        if ( $page->getTouched() >= $this->params['rootJobTimestamp'] || $opportunistic ) {
                                // Cache is suspected to be up-to-date. As long as the cache rev ID matches
                                // and it reflects the job's triggering change, then it is usable.
-                               $parserOutput = ParserCache::singleton()->getDirty( $page, $parserOptions );
+                               $parserOutput = $services->getParserCache()->getDirty( $page, $parserOptions );
                                if ( !$parserOutput
                                        || $parserOutput->getCacheRevisionId() != $revision->getId()
                                        || $parserOutput->getCacheTime() < $skewedTimestamp
                                if ( !$parserOutput
                                        || $parserOutput->getCacheRevisionId() != $revision->getId()
                                        || $parserOutput->getCacheTime() < $skewedTimestamp
@@ -234,7 +234,7 @@ class RefreshLinksJob extends Job {
                                && $parserOutput->isCacheable()
                        ) {
                                $ctime = wfTimestamp( TS_MW, (int)$start ); // cache time
                                && $parserOutput->isCacheable()
                        ) {
                                $ctime = wfTimestamp( TS_MW, (int)$start ); // cache time
-                               ParserCache::singleton()->save(
+                               $services->getParserCache()->save(
                                        $parserOutput, $page, $parserOptions, $ctime, $revision->getId()
                                );
                        }
                                        $parserOutput, $page, $parserOptions, $ctime, $revision->getId()
                                );
                        }
index f52cd8d..5b03a22 100644 (file)
@@ -466,7 +466,7 @@ class Article implements Page {
                # Allow frames by default
                $outputPage->allowClickjacking();
 
                # Allow frames by default
                $outputPage->allowClickjacking();
 
-               $parserCache = ParserCache::singleton();
+               $parserCache = MediaWikiServices::getInstance()->getParserCache();
 
                $parserOptions = $this->getParserOptions();
                # Render printable version, use printable version cache
 
                $parserOptions = $this->getParserOptions();
                # Render printable version, use printable version cache
index bf8a597..312edbd 100644 (file)
@@ -1070,7 +1070,8 @@ class WikiPage implements Page, IDBAccessObject {
                }
 
                if ( $useParserCache ) {
                }
 
                if ( $useParserCache ) {
-                       $parserOutput = ParserCache::singleton()->get( $this, $parserOptions );
+                       $parserOutput = MediaWikiServices::getInstance()->getParserCache()
+                               ->get( $this, $parserOptions );
                        if ( $parserOutput !== false ) {
                                return $parserOutput;
                        }
                        if ( $parserOutput !== false ) {
                                return $parserOutput;
                        }
@@ -2162,7 +2163,7 @@ class WikiPage implements Page, IDBAccessObject {
 
                // Save it to the parser cache.
                // Make sure the cache time matches page_touched to avoid double parsing.
 
                // Save it to the parser cache.
                // Make sure the cache time matches page_touched to avoid double parsing.
-               ParserCache::singleton()->save(
+               MediaWikiServices::getInstance()->getParserCache()->save(
                        $editInfo->output, $this, $editInfo->popts,
                        $revision->getTimestamp(), $editInfo->revid
                );
                        $editInfo->output, $this, $editInfo->popts,
                        $revision->getTimestamp(), $editInfo->revid
                );
index 1f1add7..17b62d7 100644 (file)
@@ -17,6 +17,7 @@
  *
  * @file
  */
  *
  * @file
  */
+use MediaWiki\MediaWikiServices;
 
 class PoolWorkArticleView extends PoolCounterWork {
        /** @var WikiPage */
 
 class PoolWorkArticleView extends PoolCounterWork {
        /** @var WikiPage */
@@ -28,6 +29,9 @@ class PoolWorkArticleView extends PoolCounterWork {
        /** @var int */
        private $revid;
 
        /** @var int */
        private $revid;
 
+       /** @var ParserCache */
+       private $parserCache;
+
        /** @var ParserOptions */
        private $parserOptions;
 
        /** @var ParserOptions */
        private $parserOptions;
 
@@ -66,7 +70,8 @@ class PoolWorkArticleView extends PoolCounterWork {
                $this->cacheable = $useParserCache;
                $this->parserOptions = $parserOptions;
                $this->content = $content;
                $this->cacheable = $useParserCache;
                $this->parserOptions = $parserOptions;
                $this->content = $content;
-               $this->cacheKey = ParserCache::singleton()->getKey( $page, $parserOptions );
+               $this->parserCache = MediaWikiServices::getInstance()->getParserCache();
+               $this->cacheKey = $this->parserCache->getKey( $page, $parserOptions );
                $keyPrefix = $this->cacheKey ?: wfMemcKey( 'articleview', 'missingcachekey' );
                parent::__construct( 'ArticleView', $keyPrefix . ':revid:' . $revid );
        }
                $keyPrefix = $this->cacheKey ?: wfMemcKey( 'articleview', 'missingcachekey' );
                parent::__construct( 'ArticleView', $keyPrefix . ':revid:' . $revid );
        }
@@ -153,7 +158,7 @@ class PoolWorkArticleView extends PoolCounterWork {
                }
 
                if ( $this->cacheable && $this->parserOutput->isCacheable() && $isCurrent ) {
                }
 
                if ( $this->cacheable && $this->parserOutput->isCacheable() && $isCurrent ) {
-                       ParserCache::singleton()->save(
+                       $this->parserCache->save(
                                $this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid );
                }
 
                                $this->parserOutput, $this->page, $this->parserOptions, $cacheTime, $this->revid );
                }
 
@@ -175,7 +180,7 @@ class PoolWorkArticleView extends PoolCounterWork {
         * @return bool
         */
        public function getCachedWork() {
         * @return bool
         */
        public function getCachedWork() {
-               $this->parserOutput = ParserCache::singleton()->get( $this->page, $this->parserOptions );
+               $this->parserOutput = $this->parserCache->get( $this->page, $this->parserOptions );
 
                if ( $this->parserOutput === false ) {
                        wfDebug( __METHOD__ . ": parser cache miss\n" );
 
                if ( $this->parserOutput === false ) {
                        wfDebug( __METHOD__ . ": parser cache miss\n" );
@@ -190,7 +195,7 @@ class PoolWorkArticleView extends PoolCounterWork {
         * @return bool
         */
        public function fallback() {
         * @return bool
         */
        public function fallback() {
-               $this->parserOutput = ParserCache::singleton()->getDirty( $this->page, $this->parserOptions );
+               $this->parserOutput = $this->parserCache->getDirty( $this->page, $this->parserOptions );
 
                if ( $this->parserOutput === false ) {
                        wfDebugLog( 'dirty', 'dirty missing' );
 
                if ( $this->parserOutput === false ) {
                        wfDebugLog( 'dirty', 'dirty missing' );
index 8bd060f..504c7d7 100644 (file)
@@ -21,6 +21,8 @@
 
 require_once __DIR__ . '/Maintenance.php';
 
 
 require_once __DIR__ . '/Maintenance.php';
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @ingroup Maintenance
  */
 /**
  * @ingroup Maintenance
  */
@@ -41,6 +43,7 @@ class CompareParserCache extends Maintenance {
                $scanned = 0;
                $withcache = 0;
                $withdiff = 0;
                $scanned = 0;
                $withcache = 0;
                $withdiff = 0;
+               $parserCache = MediaWikiServices::getInstance()->getParserCache();
                while ( $pages-- > 0 ) {
                        $row = $dbr->selectRow( 'page', '*',
                                [
                while ( $pages-- > 0 ) {
                        $row = $dbr->selectRow( 'page', '*',
                                [
@@ -66,7 +69,7 @@ class CompareParserCache extends Maintenance {
 
                        $parserOptions = $page->makeParserOptions( 'canonical' );
 
 
                        $parserOptions = $page->makeParserOptions( 'canonical' );
 
-                       $parserOutputOld = ParserCache::singleton()->get( $page, $parserOptions );
+                       $parserOutputOld = $parserCache->get( $page, $parserOptions );
 
                        if ( $parserOutputOld ) {
                                $t1 = microtime( true );
 
                        if ( $parserOutputOld ) {
                                $t1 = microtime( true );