From a26eee40e08aef9cf44cfcab8124257f4d071b5a Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Thu, 28 Feb 2019 12:42:20 -0800 Subject: [PATCH] Avoid use of deprecated ObjectCache::getMainWANInstance method Change-Id: I429e68c8642a00afa812f5ae900c1fb4f8308528 --- includes/AjaxResponse.php | 9 ++++++--- includes/FeedUtils.php | 3 ++- includes/Title.php | 2 +- includes/changes/ChangesFeed.php | 7 ++++--- includes/deferred/WANCacheReapUpdate.php | 3 ++- includes/diff/DifferenceEngine.php | 2 +- includes/jobqueue/JobQueueDB.php | 2 +- includes/media/DjVuHandler.php | 3 ++- includes/page/WikiPage.php | 2 +- includes/resourceloader/ResourceLoaderModule.php | 2 +- includes/resourceloader/ResourceLoaderWikiModule.php | 5 +++-- includes/specialpage/ChangesListSpecialPage.php | 3 ++- 12 files changed, 26 insertions(+), 17 deletions(-) diff --git a/includes/AjaxResponse.php b/includes/AjaxResponse.php index dfcf4677af..8f4ed40489 100644 --- a/includes/AjaxResponse.php +++ b/includes/AjaxResponse.php @@ -282,7 +282,8 @@ class AjaxResponse { return false; } - $mcvalue = ObjectCache::getMainWANInstance()->get( $mckey ); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); + $mcvalue = $cache->get( $mckey ); if ( $mcvalue ) { # Check to see if the value has been invalidated if ( $touched <= $mcvalue['timestamp'] ) { @@ -304,11 +305,13 @@ class AjaxResponse { * @return bool */ function storeInMemcached( $mckey, $expiry = 86400 ) { - ObjectCache::getMainWANInstance()->set( $mckey, + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); + $cache->set( $mckey, [ 'timestamp' => wfTimestampNow(), 'value' => $this->mText - ], $expiry + ], + $expiry ); return true; diff --git a/includes/FeedUtils.php b/includes/FeedUtils.php index 899ac09ad2..0a88b2345f 100644 --- a/includes/FeedUtils.php +++ b/includes/FeedUtils.php @@ -20,6 +20,7 @@ * @file * @ingroup Feed */ +use MediaWiki\MediaWikiServices; /** * Helper functions for feeds @@ -41,7 +42,7 @@ class FeedUtils { $purge = $wgRequest->getVal( 'action' ) === 'purge'; // Allow users with 'purge' right to clear feed caches if ( $purge && $wgUser->isAllowed( 'purge' ) ) { - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $cache->delete( $timekey, 1 ); $cache->delete( $key, 1 ); } diff --git a/includes/Title.php b/includes/Title.php index 4075bd5122..2582fe25ba 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -3337,7 +3337,7 @@ class Title implements LinkTarget, IDBAccessObject { $dbr = wfGetDB( DB_MASTER ); $rows = $loadRestrictionsFromDb( $dbr ); } else { - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $rows = $cache->getWithSetCallback( // Page protections always leave a new null revision $cache->makeKey( 'page-restrictions', $id, $this->getLatestRevID() ), diff --git a/includes/changes/ChangesFeed.php b/includes/changes/ChangesFeed.php index 7ac8cd0ed0..fe9d24cd05 100644 --- a/includes/changes/ChangesFeed.php +++ b/includes/changes/ChangesFeed.php @@ -21,6 +21,7 @@ */ use Wikimedia\Rdbms\ResultWrapper; +use MediaWiki\MediaWikiServices; /** * Feed to Special:RecentChanges and Special:RecentChangesLiked @@ -82,7 +83,7 @@ class ChangesFeed { return null; } - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $optionsHash = md5( serialize( $opts->getAllValues() ) ) . $wgRenderHashAppend; $timekey = $cache->makeKey( $this->type, $this->format, $wgLang->getCode(), $optionsHash, 'timestamp' ); @@ -119,7 +120,7 @@ class ChangesFeed { * @param string $key Memcached key of the content */ public function saveToCache( $feed, $timekey, $key ) { - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $cache->set( $key, $feed, $cache::TTL_DAY ); $cache->set( $timekey, wfTimestamp( TS_MW ), $cache::TTL_DAY ); } @@ -135,7 +136,7 @@ class ChangesFeed { public function loadFromCache( $lastmod, $timekey, $key ) { global $wgFeedCacheTimeout, $wgOut; - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $feedLastmod = $cache->get( $timekey ); if ( ( $wgFeedCacheTimeout > 0 ) && $feedLastmod ) { diff --git a/includes/deferred/WANCacheReapUpdate.php b/includes/deferred/WANCacheReapUpdate.php index 604f2052c4..a218f76114 100644 --- a/includes/deferred/WANCacheReapUpdate.php +++ b/includes/deferred/WANCacheReapUpdate.php @@ -1,5 +1,6 @@ getMainWANObjectCache(), ObjectCache::getLocalClusterInstance(), [ $this, 'getTitleChangeEvents' ], [ $this, 'getEventAffectedKeys' ], diff --git a/includes/diff/DifferenceEngine.php b/includes/diff/DifferenceEngine.php index 8e2b96d080..e39334f3d7 100644 --- a/includes/diff/DifferenceEngine.php +++ b/includes/diff/DifferenceEngine.php @@ -1024,7 +1024,7 @@ class DifferenceEngine extends ContextSource { // Cacheable? $key = false; - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); if ( $this->mOldid && $this->mNewid ) { // Check if subclass is still using the old way // for backwards-compatibility diff --git a/includes/jobqueue/JobQueueDB.php b/includes/jobqueue/JobQueueDB.php index cda0636c86..65c27d8732 100644 --- a/includes/jobqueue/JobQueueDB.php +++ b/includes/jobqueue/JobQueueDB.php @@ -56,7 +56,7 @@ class JobQueueDB extends JobQueue { parent::__construct( $params ); $this->cluster = $params['cluster'] ?? false; - $this->cache = ObjectCache::getMainWANInstance(); + $this->cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); } protected function supportedOrders() { diff --git a/includes/media/DjVuHandler.php b/includes/media/DjVuHandler.php index ed62ba1f46..a0e7f2caee 100644 --- a/includes/media/DjVuHandler.php +++ b/includes/media/DjVuHandler.php @@ -20,6 +20,7 @@ * @file * @ingroup Media */ +use MediaWiki\MediaWikiServices; /** * Handler for DjVu images @@ -402,7 +403,7 @@ class DjVuHandler extends ImageHandler { } protected function getDimensionInfo( File $file ) { - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); return $cache->getWithSetCallback( $cache->makeKey( 'file-djvu', 'dimensions', $file->getSha1() ), $cache::TTL_INDEFINITE, diff --git a/includes/page/WikiPage.php b/includes/page/WikiPage.php index df9259b9e7..32b35f7d02 100644 --- a/includes/page/WikiPage.php +++ b/includes/page/WikiPage.php @@ -637,7 +637,7 @@ class WikiPage implements Page, IDBAccessObject { */ public function getContentModel() { if ( $this->exists() ) { - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); return $cache->getWithSetCallback( $cache->makeKey( 'page-content-model', $this->getLatest() ), diff --git a/includes/resourceloader/ResourceLoaderModule.php b/includes/resourceloader/ResourceLoaderModule.php index b39262527c..b646f20f8c 100644 --- a/includes/resourceloader/ResourceLoaderModule.php +++ b/includes/resourceloader/ResourceLoaderModule.php @@ -944,7 +944,7 @@ abstract class ResourceLoaderModule implements LoggerAwareInterface { if ( !$this->getConfig()->get( 'ResourceLoaderValidateJS' ) ) { return $contents; } - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); return $cache->getWithSetCallback( $cache->makeGlobalKey( 'resourceloader', diff --git a/includes/resourceloader/ResourceLoaderWikiModule.php b/includes/resourceloader/ResourceLoaderWikiModule.php index ecb1a09afa..a91537fb32 100644 --- a/includes/resourceloader/ResourceLoaderWikiModule.php +++ b/includes/resourceloader/ResourceLoaderWikiModule.php @@ -26,6 +26,7 @@ use MediaWiki\Linker\LinkTarget; use Wikimedia\Assert\Assert; use Wikimedia\Rdbms\Database; use Wikimedia\Rdbms\IDatabase; +use MediaWiki\MediaWikiServices; /** * Abstraction for ResourceLoader modules which pull from wiki pages @@ -482,7 +483,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { $func = [ static::class, 'fetchTitleInfo' ]; $fname = __METHOD__; - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $allInfo = $cache->getWithSetCallback( $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $db->getDomainID(), $hash ), $cache::TTL_HOUR, @@ -549,7 +550,7 @@ class ResourceLoaderWikiModule extends ResourceLoaderModule { } if ( $purge ) { - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); $key = $cache->makeGlobalKey( 'resourceloader', 'titleinfo', $domain ); $cache->touchCheckKey( $key ); } diff --git a/includes/specialpage/ChangesListSpecialPage.php b/includes/specialpage/ChangesListSpecialPage.php index c96cf8e765..a8271acf10 100644 --- a/includes/specialpage/ChangesListSpecialPage.php +++ b/includes/specialpage/ChangesListSpecialPage.php @@ -25,6 +25,7 @@ use Wikimedia\Rdbms\DBQueryTimeoutError; use Wikimedia\Rdbms\IResultWrapper; use Wikimedia\Rdbms\FakeResultWrapper; use Wikimedia\Rdbms\IDatabase; +use MediaWiki\MediaWikiServices; /** * Special page which uses a ChangesList to show query results. @@ -845,7 +846,7 @@ abstract class ChangesListSpecialPage extends SpecialPage { * @return array Tag data */ protected static function getChangeTagList( ResourceLoaderContext $context ) { - $cache = ObjectCache::getMainWANInstance(); + $cache = MediaWikiServices::getInstance()->getMainWANObjectCache(); return $cache->getWithSetCallback( $cache->makeKey( 'changeslistspecialpage-changetags', $context->getLanguage() ), $cache::TTL_MINUTE * 10, -- 2.20.1