From 88aa91f84aefe29175986e2985b0c86628fac900 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Wed, 28 Sep 2016 20:59:11 -0700 Subject: [PATCH] Clean up some ObjectCache factory callers * Use services container in more places. * Undeprecated getLocalServerInstance() since $fallback is not handled elsewhere. Change-Id: Id1fcd1c465d2d92653357523f4225f1c4d1ace2f --- includes/cache/MessageCache.php | 5 +++-- includes/db/MWLBFactory.php | 5 +++-- includes/filebackend/FileBackendGroup.php | 3 ++- includes/media/TransformationalImageHandler.php | 3 ++- includes/registration/ExtensionRegistry.php | 4 +++- includes/utils/MWCryptHKDF.php | 11 ++++++++--- includes/utils/UIDGenerator.php | 3 ++- 7 files changed, 23 insertions(+), 11 deletions(-) diff --git a/includes/cache/MessageCache.php b/includes/cache/MessageCache.php index e871855a32..f393acde06 100644 --- a/includes/cache/MessageCache.php +++ b/includes/cache/MessageCache.php @@ -20,6 +20,7 @@ * @file * @ingroup Cache */ +use MediaWiki\MediaWikiServices; /** * MediaWiki message cache structure version. @@ -154,9 +155,9 @@ class MessageCache { $this->mExpiry = $expiry; if ( $wgUseLocalMessageCache ) { - $this->localCache = ObjectCache::getLocalServerInstance( CACHE_NONE ); + $this->localCache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); } else { - $this->localCache = wfGetCache( CACHE_NONE ); + $this->localCache = new EmptyBagOStuff(); } $this->wanCache = ObjectCache::getMainWANInstance(); diff --git a/includes/db/MWLBFactory.php b/includes/db/MWLBFactory.php index 96c6e9f8d3..bfdce393b5 100644 --- a/includes/db/MWLBFactory.php +++ b/includes/db/MWLBFactory.php @@ -22,6 +22,7 @@ */ use MediaWiki\Logger\LoggerFactory; +use MediaWiki\MediaWikiServices; /** * MediaWiki-specific class for generating database load balancers @@ -110,7 +111,7 @@ abstract class MWLBFactory { } // Use APC/memcached style caching, but avoids loops with CACHE_DB (T141804) - $sCache = ObjectCache::getLocalServerInstance(); + $sCache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); if ( $sCache->getQoS( $sCache::ATTR_EMULATION ) > $sCache::QOS_EMULATION_SQL ) { $lbConf['srvCache'] = $sCache; } @@ -118,7 +119,7 @@ abstract class MWLBFactory { if ( $cCache->getQoS( $cCache::ATTR_EMULATION ) > $cCache::QOS_EMULATION_SQL ) { $lbConf['memCache'] = $cCache; } - $wCache = ObjectCache::getMainWANInstance(); + $wCache = MediaWikiServices::getInstance()->getMainWANObjectCache(); if ( $wCache->getQoS( $wCache::ATTR_EMULATION ) > $wCache::QOS_EMULATION_SQL ) { $lbConf['wanCache'] = $wCache; } diff --git a/includes/filebackend/FileBackendGroup.php b/includes/filebackend/FileBackendGroup.php index 87d9441c3b..e65a5945ff 100644 --- a/includes/filebackend/FileBackendGroup.php +++ b/includes/filebackend/FileBackendGroup.php @@ -22,6 +22,7 @@ * @author Aaron Schulz */ use \MediaWiki\Logger\LoggerFactory; +use MediaWiki\MediaWikiServices; /** * Class to handle file backend registration @@ -192,7 +193,7 @@ class FileBackendGroup { 'streamMimeFunc' => [ 'StreamFile', 'contentTypeFromPath' ], 'tmpDirectory' => wfTempDir(), 'statusWrapper' => [ 'Status', 'wrap' ], - 'wanCache' => ObjectCache::getMainWANInstance(), + 'wanCache' => MediaWikiServices::getInstance()->getMainWANObjectCache(), 'srvCache' => ObjectCache::getLocalServerInstance( 'hash' ), 'logger' => LoggerFactory::getInstance( 'FileOperation' ), 'profiler' => Profiler::instance() diff --git a/includes/media/TransformationalImageHandler.php b/includes/media/TransformationalImageHandler.php index 3ebda75c80..11c4d4214c 100644 --- a/includes/media/TransformationalImageHandler.php +++ b/includes/media/TransformationalImageHandler.php @@ -25,6 +25,7 @@ * @file * @ingroup Media */ +use MediaWiki\MediaWikiServices; /** * Handler for images that need to be transformed @@ -509,7 +510,7 @@ abstract class TransformationalImageHandler extends ImageHandler { * @return string|bool Representing the IM version; false on error */ protected function getMagickVersion() { - $cache = ObjectCache::getLocalServerInstance( CACHE_NONE ); + $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); return $cache->getWithSetCallback( 'imagemagick-version', $cache::TTL_HOUR, diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index 3bec457c1e..35044e1f86 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -1,5 +1,7 @@ cache = ObjectCache::getLocalServerInstance(); + $this->cache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); } catch ( MWException $e ) { $this->cache = new EmptyBagOStuff(); } diff --git a/includes/utils/MWCryptHKDF.php b/includes/utils/MWCryptHKDF.php index 1376fa7bb9..2756861e81 100644 --- a/includes/utils/MWCryptHKDF.php +++ b/includes/utils/MWCryptHKDF.php @@ -29,6 +29,7 @@ * @author Chris Steipp * @file */ +use MediaWiki\MediaWikiServices; class MWCryptHKDF { @@ -160,7 +161,7 @@ class MWCryptHKDF { * @throws MWException */ protected static function singleton() { - global $wgHKDFAlgorithm, $wgHKDFSecret, $wgSecretKey, $wgMainCacheType; + global $wgHKDFAlgorithm, $wgHKDFSecret, $wgSecretKey; $secret = $wgHKDFSecret ?: $wgSecretKey; if ( !$secret ) { @@ -174,8 +175,12 @@ class MWCryptHKDF { $context[] = getmypid(); $context[] = gethostname(); - // Setup salt cache. Use APC, or fallback to the main cache if it isn't setup - $cache = ObjectCache::getLocalServerInstance( $wgMainCacheType ); + // Setup salt cache + $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); + if ( $cache instanceof EmptyBagOStuff ) { + // Use APC, or fallback to the main cache if it isn't setup + $cache = ObjectCache::getLocalClusterInstance(); + } if ( is_null( self::$singleton ) ) { self::$singleton = new self( $secret, $wgHKDFAlgorithm, $cache, $context ); diff --git a/includes/utils/UIDGenerator.php b/includes/utils/UIDGenerator.php index abba5a1d1d..95b4463abd 100644 --- a/includes/utils/UIDGenerator.php +++ b/includes/utils/UIDGenerator.php @@ -21,6 +21,7 @@ * @author Aaron Schulz */ use Wikimedia\Assert\Assert; +use MediaWiki\MediaWikiServices; /** * Class for getting statistically unique IDs @@ -368,7 +369,7 @@ class UIDGenerator { // Counter values would not survive accross script instances in CLI mode. $cache = null; if ( ( $flags & self::QUICK_VOLATILE ) && PHP_SAPI !== 'cli' ) { - $cache = ObjectCache::getLocalServerInstance(); + $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache(); } if ( $cache ) { $counter = $cache->incrWithInit( $bucket, $cache::TTL_INDEFINITE, $count, $count ); -- 2.20.1