Revert "Add the main stash, WAN, and server caches to MediaWikiServices"
authorHashar <hashar@free.fr>
Thu, 29 Sep 2016 08:43:58 +0000 (08:43 +0000)
committerAntoine Musso <hashar@free.fr>
Thu, 29 Sep 2016 08:46:48 +0000 (10:46 +0200)
 $ php maintenance/eval.php
 > $wgMessageCacheType = CACHE_ACCEL;

 > wfGetMessageCacheStorage();
 PHP Warning:  Illegal offset type in isset or empty in includes/objectcache/ObjectCache.php on line 93
 PHP Warning:  Illegal offset type in isset or empty in includes/objectcache/ObjectCache.php on line 125
 PHP Notice:  Array to string conversion in includes/objectcache/ObjectCache.php on line 133
 Caught exception InvalidArgumentException: Invalid object cache type "Array" requested. It is not present in $wgObjectCaches.
 #0 includes/objectcache/ObjectCache.php(94): ObjectCache::newFromId(Array)
 #1 includes/objectcache/ObjectCache.php(287): ObjectCache::getInstance(Array)
 #2 [internal function]: ObjectCache::getLocalServerInstance(Array)
 #3 includes/objectcache/ObjectCache.php(181): call_user_func('ObjectCache::ge...', Array)
 #4 includes/objectcache/ObjectCache.php(137): ObjectCache::newFromParams(Array)
 #5 includes/objectcache/ObjectCache.php(94): ObjectCache::newFromId(3)
 #6 includes/GlobalFunctions.php(3430): ObjectCache::getInstance(3)
 #7 maintenance/eval.php(78) : eval()'d code(1): wfGetMessageCacheStorage()
 #8 maintenance/eval.php(78): eval()
 #9 {main}

This reverts commit 6d99fa58247a1de7eaf9a79a061f0b4207154072.

Change-Id: I4d756eb6f66318a12d8cbbc1ba546397be8a29bf

includes/MediaWikiServices.php
includes/ServiceWiring.php
includes/objectcache/ObjectCache.php
tests/phpunit/MediaWikiTestCase.php
tests/phpunit/includes/MediaWikiServicesTest.php

index 199472a..b16044e 100644 (file)
@@ -589,30 +589,6 @@ class MediaWikiServices extends ServiceContainer {
                return $this->getService( 'TitleParser' );
        }
 
-       /**
-        * @since 1.28
-        * @return \BagOStuff
-        */
-       public function getMainObjectStash() {
-               return $this->getService( 'MainObjectStash' );
-       }
-
-       /**
-        * @since 1.28
-        * @return \WANObjectCache
-        */
-       public function getMainWANObjectCache() {
-               return $this->getService( 'MainWANObjectCache' );
-       }
-
-       /**
-        * @since 1.28
-        * @return \BagOStuff
-        */
-       public function getLocalServerObjectCache() {
-               return $this->getService( 'LocalServerObjectCache' );
-       }
-
        /**
         * @since 1.28
         * @return VirtualRESTServiceClient
index 0e4daa6..6044911 100644 (file)
@@ -218,59 +218,6 @@ return [
                return $services->getService( '_MediaWikiTitleCodec' );
        },
 
-       'MainObjectStash' => function( MediaWikiServices $services ) {
-               $mainConfig = $services->getMainConfig();
-
-               $id = $mainConfig->get( 'MainStash' );
-               if ( !isset( $mainConfig->get( 'ObjectCaches' )[$id] ) ) {
-                       throw new UnexpectedValueException(
-                               "Cache type \"$id\" is not present in \$wgObjectCaches." );
-               }
-
-               return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches' )[$id] );
-       },
-
-       'MainWANObjectCache' => function( MediaWikiServices $services ) {
-               $mainConfig = $services->getMainConfig();
-
-               $id = $mainConfig->get( 'MainWANCache' );
-               if ( !isset( $mainConfig->get( 'WANObjectCaches' )[$id] ) ) {
-                       throw new UnexpectedValueException(
-                               "WAN cache type \"$id\" is not present in \$wgWANObjectCaches." );
-               }
-
-               $params = $mainConfig->get( 'WANObjectCaches' )[$id];
-               $objectCacheId = $params['cacheId'];
-               if ( !isset( $mainConfig->get( 'ObjectCaches' )[$objectCacheId] ) ) {
-                       throw new UnexpectedValueException(
-                               "Cache type \"$objectCacheId\" is not present in \$wgObjectCaches." );
-               }
-               $params['store'] = $mainConfig->get( 'ObjectCaches' )[$objectCacheId];
-
-               return \ObjectCache::newWANCacheFromParams( $params );
-       },
-
-       'LocalServerObjectCache' => function( MediaWikiServices $services ) {
-               $mainConfig = $services->getMainConfig();
-
-               if ( function_exists( 'apc_fetch' ) ) {
-                       $id = 'apc';
-               } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) {
-                       $id = 'xcache';
-               } elseif ( function_exists( 'wincache_ucache_get' ) ) {
-                       $id = 'wincache';
-               } else {
-                       $id = CACHE_NONE;
-               }
-
-               if ( !isset( $mainConfig->get( 'ObjectCaches' )[$id] ) ) {
-                       throw new UnexpectedValueException(
-                               "Cache type \"$id\" is not present in \$wgObjectCaches." );
-               }
-
-               return \ObjectCache::newFromParams( $mainConfig->get( 'ObjectCaches' )[$id] );
-       },
-
        'VirtualRESTServiceClient' => function( MediaWikiServices $services ) {
                $config = $services->getMainConfig()->get( 'VirtualRestConfig' );
 
index 0f18479..d81f9e1 100644 (file)
@@ -274,18 +274,27 @@ class ObjectCache {
         *     // From $wgObjectCaches via newFromParams()
         *     ObjectCache::getLocalServerInstance( [ 'fallback' => $fallbackType ] );
         *
-        * @param int|string $fallback Fallback cache ID
+        * @param int|string|array $fallback Fallback cache or parameter map with 'fallback'
         * @return BagOStuff
         * @throws InvalidArgumentException
         * @since 1.27
-        * @deprecated Since 1.28; use MediaWikiServices::getLocalServerObjectCache
         */
        public static function getLocalServerInstance( $fallback = CACHE_NONE ) {
-               $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
+               if ( function_exists( 'apc_fetch' ) ) {
+                       $id = 'apc';
+               } elseif ( function_exists( 'xcache_get' ) && wfIniGetBool( 'xcache.var_size' ) ) {
+                       $id = 'xcache';
+               } elseif ( function_exists( 'wincache_ucache_get' ) ) {
+                       $id = 'wincache';
+               } else {
+                       if ( is_array( $fallback ) ) {
+                               $id = isset( $fallback['fallback'] ) ? $fallback['fallback'] : CACHE_NONE;
+                       } else {
+                               $id = $fallback;
+                       }
+               }
 
-               return ( $cache instanceof EmptyBagOStuff )
-                       ? self::getInstance( $fallback )
-                       : $cache;
+               return self::getInstance( $id );
        }
 
        /**
@@ -374,10 +383,11 @@ class ObjectCache {
         *
         * @since 1.26
         * @return WANObjectCache
-        * @deprecated Since 1.28 Use MediaWikiServices::getMainWANCache()
         */
        public static function getMainWANInstance() {
-               return MediaWikiServices::getInstance()->getMainWANObjectCache();
+               global $wgMainWANCache;
+
+               return self::getWANInstance( $wgMainWANCache );
        }
 
        /**
@@ -397,10 +407,11 @@ class ObjectCache {
         *
         * @return BagOStuff
         * @since 1.26
-        * @deprecated Since 1.28 Use MediaWikiServices::getMainObjectStash
         */
        public static function getMainStashInstance() {
-               return MediaWikiServices::getInstance()->getMainObjectStash();
+               global $wgMainStash;
+
+               return self::getInstance( $wgMainStash );
        }
 
        /**
index e53a958..45a7ce5 100644 (file)
@@ -336,10 +336,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase {
 
                JobQueueGroup::destroySingletons();
                ObjectCache::clear();
-               $services = MediaWikiServices::getInstance();
-               $services->resetServiceForTesting( 'MainObjectStash' );
-               $services->resetServiceForTesting( 'LocalServerObjectCache' );
-               $services->getMainWANObjectCache()->clearProcessCache();
                FileBackendGroup::destroySingleton();
 
                // TODO: move global state into MediaWikiServices
index 4fbef6c..a05e39d 100644 (file)
@@ -320,11 +320,8 @@ class MediaWikiServicesTest extends MediaWikiTestCase {
                        '_MediaWikiTitleCodec' => [ '_MediaWikiTitleCodec', MediaWikiTitleCodec::class ],
                        'TitleFormatter' => [ 'TitleFormatter', TitleFormatter::class ],
                        'TitleParser' => [ 'TitleParser', TitleParser::class ],
-                       'ProxyLookup' => [ 'ProxyLookup', ProxyLookup::class ],
-                       'MainObjectStash' => [ 'MainObjectStash', BagOStuff::class ],
-                       'MainWANObjectCache' => [ 'MainWANObjectCache', WANObjectCache::class ],
-                       'LocalServerObjectCache' => [ 'LocalServerObjectCache', BagOStuff::class ],
-                       'VirtualRESTServiceClient' => [ 'VirtualRESTServiceClient', VirtualRESTServiceClient::class ]
+                       'VirtualRESTServiceClient' => [ 'VirtualRESTServiceClient', VirtualRESTServiceClient::class ],
+                       'ProxyLookup' => [ 'ProxyLookup', ProxyLookup::class ]
                ];
        }