Clean up some ObjectCache factory callers
authorAaron Schulz <aschulz@wikimedia.org>
Thu, 29 Sep 2016 03:59:11 +0000 (20:59 -0700)
committerAaron Schulz <aschulz@wikimedia.org>
Mon, 3 Oct 2016 18:44:55 +0000 (11:44 -0700)
* Use services container in more places.
* Undeprecated getLocalServerInstance() since $fallback is not
  handled elsewhere.

Change-Id: Id1fcd1c465d2d92653357523f4225f1c4d1ace2f

includes/cache/MessageCache.php
includes/db/MWLBFactory.php
includes/filebackend/FileBackendGroup.php
includes/media/TransformationalImageHandler.php
includes/registration/ExtensionRegistry.php
includes/utils/MWCryptHKDF.php
includes/utils/UIDGenerator.php

index e871855..f393acd 100644 (file)
@@ -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();
index 96c6e9f..bfdce39 100644 (file)
@@ -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;
                }
index 87d9441..e65a594 100644 (file)
@@ -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()
index 3ebda75..11c4d42 100644 (file)
@@ -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,
index 3bec457..35044e1 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * ExtensionRegistry class
  *
@@ -86,7 +88,7 @@ class ExtensionRegistry {
                // we don't want to fail here if $wgObjectCaches is not configured
                // properly for APC setup
                try {
-                       $this->cache = ObjectCache::getLocalServerInstance();
+                       $this->cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
                } catch ( MWException $e ) {
                        $this->cache = new EmptyBagOStuff();
                }
index 1376fa7..2756861 100644 (file)
@@ -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 );
index abba5a1..95b4463 100644 (file)
@@ -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 );