Merge "Revert "Unwrap HTML loaded from parser cache""
[lhc/web/wiklou.git] / includes / installer / CliInstaller.php
index 845408a..f59b5da 100644 (file)
@@ -21,6 +21,8 @@
  * @ingroup Deployment
  */
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * Class for the core installer command line interface.
  *
@@ -47,31 +49,31 @@ class CliInstaller extends Installer {
 
        /**
         * @param string $siteName
-        * @param string $admin
-        * @param array $option
+        * @param string|null $admin
+        * @param array $options
         */
-       function __construct( $siteName, $admin = null, array $option = [] ) {
+       function __construct( $siteName, $admin = null, array $options = [] ) {
                global $wgContLang;
 
                parent::__construct();
 
-               if ( isset( $option['scriptpath'] ) ) {
+               if ( isset( $options['scriptpath'] ) ) {
                        $this->specifiedScriptPath = true;
                }
 
                foreach ( $this->optionMap as $opt => $global ) {
-                       if ( isset( $option[$opt] ) ) {
-                               $GLOBALS[$global] = $option[$opt];
-                               $this->setVar( $global, $option[$opt] );
+                       if ( isset( $options[$opt] ) ) {
+                               $GLOBALS[$global] = $options[$opt];
+                               $this->setVar( $global, $options[$opt] );
                        }
                }
 
-               if ( isset( $option['lang'] ) ) {
+               if ( isset( $options['lang'] ) ) {
                        global $wgLang, $wgLanguageCode;
-                       $this->setVar( '_UserLang', $option['lang'] );
-                       $wgContLang = Language::factory( $option['lang'] );
-                       $wgLang = Language::factory( $option['lang'] );
-                       $wgLanguageCode = $option['lang'];
+                       $this->setVar( '_UserLang', $options['lang'] );
+                       $wgLanguageCode = $options['lang'];
+                       $wgContLang = MediaWikiServices::getInstance()->getContentLanguage();
+                       $wgLang = Language::factory( $options['lang'] );
                        RequestContext::getMain()->setLanguage( $wgLang );
                }
 
@@ -87,32 +89,47 @@ class CliInstaller extends Installer {
                        $this->setVar( '_AdminName', $admin );
                }
 
-               if ( !isset( $option['installdbuser'] ) ) {
+               if ( !isset( $options['installdbuser'] ) ) {
                        $this->setVar( '_InstallUser',
                                $this->getVar( 'wgDBuser' ) );
                        $this->setVar( '_InstallPassword',
                                $this->getVar( 'wgDBpassword' ) );
                } else {
                        $this->setVar( '_InstallUser',
-                               $option['installdbuser'] );
+                               $options['installdbuser'] );
                        $this->setVar( '_InstallPassword',
-                               $option['installdbpass'] ?? "" );
+                               $options['installdbpass'] ?? "" );
 
                        // Assume that if we're given the installer user, we'll create the account.
                        $this->setVar( '_CreateDBAccount', true );
                }
 
-               if ( isset( $option['pass'] ) ) {
-                       $this->setVar( '_AdminPassword', $option['pass'] );
+               if ( isset( $options['pass'] ) ) {
+                       $this->setVar( '_AdminPassword', $options['pass'] );
                }
 
                // Detect and inject any extension found
-               if ( isset( $option['with-extensions'] ) ) {
+               if ( isset( $options['extensions'] ) ) {
+                       $status = $this->validateExtensions(
+                               'extension', 'extensions', $options['extensions'] );
+                       if ( !$status->isOK() ) {
+                               $this->showStatusMessage( $status );
+                       }
+                       $this->setVar( '_Extensions', $status->value );
+               } elseif ( isset( $options['with-extensions'] ) ) {
                        $this->setVar( '_Extensions', array_keys( $this->findExtensions() ) );
                }
 
                // Set up the default skins
-               $skins = array_keys( $this->findExtensions( 'skins' ) );
+               if ( isset( $options['skins'] ) ) {
+                       $status = $this->validateExtensions( 'skin', 'skins', $options['skins'] );
+                       if ( !$status->isOK() ) {
+                               $this->showStatusMessage( $status );
+                       }
+                       $skins = $status->value;
+               } else {
+                       $skins = array_keys( $this->findExtensions( 'skins' ) );
+               }
                $this->setVar( '_Skins', $skins );
 
                if ( $skins ) {
@@ -121,6 +138,28 @@ class CliInstaller extends Installer {
                }
        }
 
+       private function validateExtensions( $type, $directory, $nameLists ) {
+               $extensions = [];
+               $status = new Status;
+               foreach ( (array)$nameLists as $nameList ) {
+                       foreach ( explode( ',', $nameList ) as $name ) {
+                               $name = trim( $name );
+                               if ( $name === '' ) {
+                                       continue;
+                               }
+                               $extStatus = $this->getExtensionInfo( $type, $directory, $name );
+                               if ( $extStatus->isOK() ) {
+                                       $extensions[] = $name;
+                               } else {
+                                       $status->merge( $extStatus );
+                               }
+                       }
+               }
+               $extensions = array_unique( $extensions );
+               $status->value = $extensions;
+               return $status;
+       }
+
        /**
         * Main entry point.
         */