Fix installer issues introduces by MediaWikiServices
authordaniel <daniel.kinzler@wikimedia.de>
Fri, 13 May 2016 19:27:06 +0000 (21:27 +0200)
committerBryanDavis <bdavis@wikimedia.org>
Tue, 17 May 2016 15:24:31 +0000 (15:24 +0000)
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

autoload.php
includes/MediaWikiServices.php
includes/cache/CacheDependency.php
includes/cache/localisation/LocalisationCache.php
includes/installer/Installer.php
includes/installer/WebInstallerOutput.php
includes/objectcache/ObjectCache.php

index f79bace..cf0e417 100644 (file)
@@ -772,6 +772,7 @@ $wgAutoloadLocalClasses = [
        'MagicWord' => __DIR__ . '/includes/MagicWord.php',
        'MagicWordArray' => __DIR__ . '/includes/MagicWordArray.php',
        'MailAddress' => __DIR__ . '/includes/mail/MailAddress.php',
        'MagicWord' => __DIR__ . '/includes/MagicWord.php',
        'MagicWordArray' => __DIR__ . '/includes/MagicWordArray.php',
        'MailAddress' => __DIR__ . '/includes/mail/MailAddress.php',
+       'MainConfigDependency' => __DIR__ . '/includes/cache/CacheDependency.php',
        'Maintenance' => __DIR__ . '/maintenance/Maintenance.php',
        'MaintenanceFormatInstallDoc' => __DIR__ . '/maintenance/formatInstallDoc.php',
        'MakeTestEdits' => __DIR__ . '/maintenance/makeTestEdits.php',
        'Maintenance' => __DIR__ . '/maintenance/Maintenance.php',
        'MaintenanceFormatInstallDoc' => __DIR__ . '/maintenance/formatInstallDoc.php',
        'MakeTestEdits' => __DIR__ . '/maintenance/makeTestEdits.php',
index 891f426..71e58af 100644 (file)
@@ -13,6 +13,7 @@ use Liuggio\StatsdClient\Factory\StatsdDataFactory;
 use LoadBalancer;
 use MediaWiki\Services\ServiceContainer;
 use MWException;
 use LoadBalancer;
 use MediaWiki\Services\ServiceContainer;
 use MWException;
+use ObjectCache;
 use ResourceLoader;
 use SearchEngine;
 use SearchEngineConfig;
 use ResourceLoader;
 use SearchEngine;
 use SearchEngineConfig;
@@ -222,6 +223,8 @@ class MediaWikiServices extends ServiceContainer {
                foreach ( $destroy as $name ) {
                        $services->disableService( $name );
                }
                foreach ( $destroy as $name ) {
                        $services->disableService( $name );
                }
+
+               ObjectCache::clear();
        }
 
        /**
        }
 
        /**
index 2d29d86..a59ba97 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup Cache
  */
  * @file
  * @ingroup Cache
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * This class stores an arbitrary value along with its dependencies.
 
 /**
  * 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
  */
 /**
  * @ingroup Cache
  */
index dd7d81a..0fb9ed8 100644 (file)
@@ -23,6 +23,7 @@
 use Cdb\Reader as CdbReader;
 use Cdb\Writer as CdbWriter;
 use CLDRPluralRuleParser\Evaluator;
 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
 
 /**
  * Class for caching the contents of localisation files, Messages*.php
@@ -802,12 +803,15 @@ class LocalisationCache {
         * @return array
         */
        public function getMessagesDirs() {
         * @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",
                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' );
 
                # 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
                $deps['version'] = new ConstantDependency( 'LocalisationCache::VERSION' );
 
                # Add dependencies to the cache entry
index a9f219f..85b1013 100644 (file)
@@ -20,6 +20,7 @@
  * @file
  * @ingroup Deployment
  */
  * @file
  * @ingroup Deployment
  */
+use MediaWiki\MediaWikiServices;
 
 /**
  * This documentation group collects source code files with deployment functionality.
 
 /**
  * This documentation group collects source code files with deployment functionality.
@@ -383,14 +384,24 @@ abstract class Installer {
 
                $configOverrides->set( 'MessagesDirs', $messageDirs );
 
 
                $configOverrides->set( 'MessagesDirs', $messageDirs );
 
-               return new MultiConfig( [ $configOverrides, $baseConfig ] );
+               $installerConfig = new MultiConfig( [ $configOverrides, $baseConfig ] );
+
+               // make sure we use the installer config as the main config
+               $configRegistry = $baseConfig->get( 'ConfigRegistry' );
+               $configRegistry['main'] = function() use ( $installerConfig ) {
+                       return $installerConfig;
+               };
+
+               $configOverrides->set( 'ConfigRegistry', $configRegistry );
+
+               return $installerConfig;
        }
 
        /**
         * Constructor, always call this from child classes.
         */
        public function __construct() {
        }
 
        /**
         * Constructor, always call this from child classes.
         */
        public function __construct() {
-               global $wgMemc, $wgUser;
+               global $wgMemc, $wgUser, $wgObjectCaches;
 
                $defaultConfig = new GlobalVarConfig(); // all the stuff from DefaultSettings.php
                $installerConfig = self::getInstallerConfig( $defaultConfig );
 
                $defaultConfig = new GlobalVarConfig(); // all the stuff from DefaultSettings.php
                $installerConfig = self::getInstallerConfig( $defaultConfig );
@@ -411,6 +422,7 @@ abstract class Installer {
 
                // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and
                // SqlBagOStuff will then throw since we just disabled wfGetDB)
 
                // Disable object cache (otherwise CACHE_ANYTHING will try CACHE_DB and
                // SqlBagOStuff will then throw since we just disabled wfGetDB)
+               $wgObjectCaches = MediaWikiServices::getInstance()->getMainConfig()->get( 'ObjectCaches' );
                $wgMemc = ObjectCache::getInstance( CACHE_NONE );
 
                // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
                $wgMemc = ObjectCache::getInstance( CACHE_NONE );
 
                // Having a user with id = 0 safeguards us from DB access via User::loadOptions().
index b4c8aa8..f8dc8ee 100644 (file)
@@ -115,7 +115,10 @@ class WebInstallerOutput {
 
        public function output() {
                $this->flush();
 
        public function output() {
                $this->flush();
-               $this->outputFooter();
+
+               if ( !$this->redirectTarget ) {
+                       $this->outputFooter();
+               }
        }
 
        /**
        }
 
        /**
index 24846e6..e1bb2db 100644 (file)
@@ -23,6 +23,7 @@
 
 use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
 
 use MediaWiki\Logger\LoggerFactory;
 use MediaWiki\MediaWikiServices;
+use MediaWiki\Services\ServiceDisabledException;
 
 /**
  * Functions to get cache objects
 
 /**
  * Functions to get cache objects
@@ -226,7 +227,18 @@ class ObjectCache {
                                return self::getInstance( $candidate );
                        }
                }
                                return self::getInstance( $candidate );
                        }
                }
-               return self::getInstance( CACHE_DB );
+
+               try {
+                       // Make sure we actually have a DB backend before falling back to CACHE_DB
+                       MediaWikiServices::getInstance()->getDBLoadBalancer();
+                       $candidate = CACHE_DB;
+               } catch ( ServiceDisabledException $e ) {
+                       // The LoadBalancer is disabled, probably because
+                       // MediaWikiServices::disableStorageBackend was called.
+                       $candidate = CACHE_NONE;
+               }
+
+               return self::getInstance( $candidate );
        }
 
        /**
        }
 
        /**