From fc1d4d79602415d1362de9286b0729bd86d03fc1 Mon Sep 17 00:00:00 2001 From: daniel Date: Fri, 13 May 2016 21:27:06 +0200 Subject: Fix installer issues introduces by MediaWikiServices This fixes three issues with the installer: 1) Make sure LocalizationCache can find the installer's i18n files. 2) Make sure we don't try to use an SqlBagOStuff for caching before we have a functioning database. 3) Don't try to output HTML when redirecting (this is unrelated to MediaWikiServices, but came up during testing) Bug: T135169 Change-Id: I7caa932024cd771d6fa226a3ac6001c3148ecc9c --- includes/cache/CacheDependency.php | 29 +++++++++++++++++++++++ includes/cache/localisation/LocalisationCache.php | 13 ++++++---- 2 files changed, 38 insertions(+), 4 deletions(-) (limited to 'includes/cache') diff --git a/includes/cache/CacheDependency.php b/includes/cache/CacheDependency.php index 2d29d8651306..a59ba97d0a00 100644 --- a/includes/cache/CacheDependency.php +++ b/includes/cache/CacheDependency.php @@ -20,6 +20,7 @@ * @file * @ingroup Cache */ +use MediaWiki\MediaWikiServices; /** * This class stores an arbitrary value along with its dependencies. @@ -244,6 +245,34 @@ class GlobalDependency extends CacheDependency { } } +/** + * @ingroup Cache + */ +class MainConfigDependency extends CacheDependency { + private $name; + private $value; + + function __construct( $name ) { + $this->name = $name; + $this->value = $this->getConfig()->get( $this->name ); + } + + private function getConfig() { + return MediaWikiServices::getInstance()->getMainConfig(); + } + + /** + * @return bool + */ + function isExpired() { + if ( !$this->getConfig()->has( $this->name ) ) { + return true; + } + + return $this->getConfig()->get( $this->name ) != $this->value; + } +} + /** * @ingroup Cache */ diff --git a/includes/cache/localisation/LocalisationCache.php b/includes/cache/localisation/LocalisationCache.php index dd7d81a33c04..0fb9ed856100 100644 --- a/includes/cache/localisation/LocalisationCache.php +++ b/includes/cache/localisation/LocalisationCache.php @@ -23,6 +23,7 @@ use Cdb\Reader as CdbReader; use Cdb\Writer as CdbWriter; use CLDRPluralRuleParser\Evaluator; +use MediaWiki\MediaWikiServices; /** * Class for caching the contents of localisation files, Messages*.php @@ -802,12 +803,15 @@ class LocalisationCache { * @return array */ public function getMessagesDirs() { - global $wgMessagesDirs, $IP; + global $IP; + + $config = MediaWikiServices::getInstance()->getMainConfig(); + $messagesDirs = $config->get( 'MessagesDirs' ); return [ 'core' => "$IP/languages/i18n", 'api' => "$IP/includes/api/i18n", 'oojs-ui' => "$IP/resources/lib/oojs-ui/i18n", - ] + $wgMessagesDirs; + ] + $messagesDirs; } /** @@ -958,8 +962,9 @@ class LocalisationCache { # Add cache dependencies for any referenced globals $deps['wgExtensionMessagesFiles'] = new GlobalDependency( 'wgExtensionMessagesFiles' ); - // $wgMessagesDirs is used in LocalisationCache::getMessagesDirs() - $deps['wgMessagesDirs'] = new GlobalDependency( 'wgMessagesDirs' ); + // The 'MessagesDirs' config setting is used in LocalisationCache::getMessagesDirs(). + // We use the key 'wgMessagesDirs' for historical reasons. + $deps['wgMessagesDirs'] = new MainConfigDependency( 'MessagesDirs' ); $deps['version'] = new ConstantDependency( 'LocalisationCache::VERSION' ); # Add dependencies to the cache entry -- cgit v1.2.3