From 69aecc2eeae01dc94e40785fbfb9dd11e5b1c6b4 Mon Sep 17 00:00:00 2001 From: Max Semenik Date: Mon, 30 Apr 2018 17:35:08 -0700 Subject: [PATCH] Don't initialize MediaWikiServices before extensions have been loaded Bug: T153256 Bug: T190425 Change-Id: I749f66d13a8c8a8ae4a83661b83c56f0db74a187 --- includes/ServiceWiring.php | 20 ++------------------ includes/objectcache/ObjectCache.php | 17 +++++++++++++++++ includes/registration/ExtensionRegistry.php | 7 ++++--- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/includes/ServiceWiring.php b/includes/ServiceWiring.php index f97d60df02..ee92cbfecf 100644 --- a/includes/ServiceWiring.php +++ b/includes/ServiceWiring.php @@ -404,24 +404,8 @@ return [ }, 'LocalServerObjectCache' => function ( MediaWikiServices $services ) { - $mainConfig = $services->getMainConfig(); - - if ( function_exists( 'apc_fetch' ) ) { - $id = 'apc'; - } elseif ( function_exists( 'apcu_fetch' ) ) { - $id = 'apcu'; - } 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] ); + $cacheId = \ObjectCache::detectLocalServerCache(); + return \ObjectCache::newFromId( $cacheId ); }, 'VirtualRESTServiceClient' => function ( MediaWikiServices $services ) { diff --git a/includes/objectcache/ObjectCache.php b/includes/objectcache/ObjectCache.php index a6f55e6026..c384032220 100644 --- a/includes/objectcache/ObjectCache.php +++ b/includes/objectcache/ObjectCache.php @@ -413,4 +413,21 @@ class ObjectCache { self::$instances = []; self::$wanInstances = []; } + + /** + * Detects which local server cache library is present and returns a configuration for it + * @since 1.32 + * + * @return int|string Index to cache in $wgObjectCaches + */ + public static function detectLocalServerCache() { + if ( function_exists( 'apc_fetch' ) ) { + return 'apc'; + } elseif ( function_exists( 'apcu_fetch' ) ) { + return 'apcu'; + } elseif ( function_exists( 'wincache_ucache_get' ) ) { + return 'wincache'; + } + return CACHE_NONE; + } } diff --git a/includes/registration/ExtensionRegistry.php b/includes/registration/ExtensionRegistry.php index b000dc11b1..b34a123635 100644 --- a/includes/registration/ExtensionRegistry.php +++ b/includes/registration/ExtensionRegistry.php @@ -1,7 +1,5 @@ getLocalServerObjectCache(); + // Don't use MediaWikiServices here to prevent instantiating it before extensions have + // been loaded + $cacheId = ObjectCache::detectLocalServerCache(); + $cache = ObjectCache::newFromId( $cacheId ); } catch ( MWException $e ) { $cache = new EmptyBagOStuff(); } -- 2.20.1