Installer: Do not use Vector skin if not installed
authorsaper <saper@saper.info>
Tue, 26 Aug 2014 19:38:41 +0000 (21:38 +0200)
committerBartosz Dziewoński <matma.rex@gmail.com>
Sat, 30 Aug 2014 22:34:53 +0000 (00:34 +0200)
MediaWiki installer works fine in a bareskin
mode without Vector features, so do not
throw errors in the PHP error log just because
we don't have "skins" project extracted.

The message in the PHP error log:

Warning:  include_once(w/skins/Vector/Vector.php): failed to open stream: No such file or directory in w/includes/installer/WebInstallerOutput.php on line 135
Stack trace:
  1. {main}() w/mw-config/index.php:0
  2. wfInstallerMain() w/mw-config/index.php:38
  3. WebInstaller->execute() w/mw-config/index.php:79
  4. WebInstaller->outputCss() w/includes/installer/WebInstaller.php:185
  5. WebInstallerOutput->getCSS() w/includes/installer/WebInstaller.php:1200

Change-Id: I7b8bd77f5868af2ccf464e48db771f2e8e0472ff

includes/installer/WebInstallerOutput.php

index ccaf523..3094d55 100644 (file)
@@ -124,53 +124,55 @@ class WebInstallerOutput {
         * @return string
         */
        public function getCSS() {
-               // Horrible, horrible hack: the installer is currently hardcoded to use the Vector skin, so load
-               // it here. Include instead of require, as this will work without it, it will just look bad.
-               // We need the 'global' statement for $wgResourceModules because the Vector skin adds the
-               // definitions for its RL modules there that we use implicitly below.
-               // @codingStandardsIgnoreStart
-               global $wgResourceModules; // This is NOT UNUSED!
-               // @codingStandardsIgnoreEnd
                global $wgStyleDirectory;
-               include_once "$wgStyleDirectory/Vector/Vector.php";
 
                $moduleNames = array(
                        // See SkinTemplate::setupSkinUserCss
                        'mediawiki.legacy.shared',
                        // See Vector::setupSkinUserCss
                        'mediawiki.skinning.interface',
-                       'skins.vector.styles',
-
-                       'mediawiki.legacy.config',
                );
 
-               $css = '';
+               if ( file_exists( "$wgStyleDirectory/Vector/Vector.php" ) ) {
+                       // Force loading Vector skin if available as a fallback skin
+                       // for whatever ResourceLoader wants to have as the default.
+
+                       // Include instead of require, as this will work without it, it will just look bad.
+                       // We need the 'global' statement for $wgResourceModules because the Vector skin adds the
+                       // definitions for its RL modules there that we use implicitly below.
+
+                       // @codingStandardsIgnoreStart
+                       global $wgResourceModules; // This is NOT UNUSED!
+                       // @codingStandardsIgnoreEnd
+
+                       include_once "$wgStyleDirectory/Vector/Vector.php";
+
+                       $moduleNames[] = 'skins.vector.styles';
+               }
+
+               $moduleNames[] = 'mediawiki.legacy.config';
 
                $resourceLoader = new ResourceLoader();
                $rlContext = new ResourceLoaderContext( $resourceLoader, new FauxRequest( array(
                                'debug' => 'true',
                                'lang' => $this->getLanguageCode(),
                                'only' => 'styles',
-                               'skin' => 'vector',
                ) ) );
+
+               $styles = array();
                foreach ( $moduleNames as $moduleName ) {
                        /** @var ResourceLoaderFileModule $module */
                        $module = $resourceLoader->getModule( $moduleName );
-                       // One of the modules will be missing if Vector is unavailable
-                       if ( !$module ) {
-                               continue;
-                       }
 
                        // Based on: ResourceLoaderFileModule::getStyles (without the DB query)
-                       $styles = ResourceLoader::makeCombinedStyles( $module->readStyleFiles(
-                               $module->getStyleFiles( $rlContext ),
-                               $module->getFlip( $rlContext )
-                       ) );
-
-                       $css .= implode( "\n", $styles );
+                       $styles = array_merge( $styles, ResourceLoader::makeCombinedStyles(
+                               $module->readStyleFiles(
+                                       $module->getStyleFiles( $rlContext ),
+                                       $module->getFlip( $rlContext )
+                       ) ) );
                }
 
-               return $css;
+               return implode( "\n", $styles );
        }
 
        /**