Fix for r79874: only set $mRevIdFetched from fetchContent(), it was overriden by...
[lhc/web/wiklou.git] / includes / installer / CliInstaller.php
index 2e1ecd1..af50f80 100644 (file)
@@ -1,9 +1,18 @@
 <?php
+/**
+ * Core installer command line interface.
+ *
+ * @file
+ * @ingroup Deployment
+ */
 
-class CliInstaller extends Installer {
-
-       /* The maintenance class in effect */
-       private $maint;
+/**
+ * Class for the core installer command line interface.
+ *
+ * @ingroup Deployment
+ * @since 1.17
+ */
+class CliInstaller extends CoreInstaller {
 
        private $optionMap = array(
                'dbtype' => 'wgDBtype',
@@ -22,11 +31,20 @@ class CliInstaller extends Installer {
                'dbschema' => 'wgDBmwschema',
                'dbts2schema' => 'wgDBts2schema',
                'dbpath' => 'wgSQLiteDataDir',
+               'scriptpath' => 'wgScriptPath',
+               'upgrade' => 'cliUpgrade', /* As long as it isn't $confItems
+                                                                       * in LocalSettingsGenerator, we
+                                                                       * should be fine. */
        );
 
-
-       /** Constructor */
-       function __construct( $siteName, $admin = null, $option = array()) {
+       /**
+        * Constructor.
+        *
+        * @param $siteName
+        * @param $admin
+        * @param $option Array
+        */
+       function __construct( $siteName, $admin = null, array $option = array() ) {
                parent::__construct();
 
                foreach ( $this->optionMap as $opt => $global ) {
@@ -45,11 +63,9 @@ class CliInstaller extends Installer {
                }
 
                $this->setVar( 'wgSitename', $siteName );
+
                if ( $admin ) {
                        $this->setVar( '_AdminName', $admin );
-               } else {
-                       $this->setVar( '_AdminName',
-                               wfMsgForContent( 'config-admin-default-username' ) );
                }
 
                if ( !isset( $option['installdbuser'] ) ) {
@@ -62,34 +78,74 @@ class CliInstaller extends Installer {
                if ( isset( $option['pass'] ) ) {
                        $this->setVar( '_AdminPassword', $option['pass'] );
                }
-
-               $this->output = new CliInstallerOutput( $this );
        }
 
        /**
         * Main entry point.
         */
-       function execute( ) {
-               foreach( $this->getInstallSteps() as $step ) {
-                       $this->showMessage("Installing $step... ");
-                       $func = 'install' . ucfirst( $step );
-                       $status = $this->{$func}();
-                       $ok = $status->isGood();
-                       if ( !$ok ) {
-                               $this->showStatusError( $status );
-                               exit;
-                       }
-                       $this->showMessage("done\n");
+       public function execute() {
+               global $cliUpgrade;
+
+               $vars = $this->getExistingLocalSettings();
+               if( $vars && ( !isset( $cliUpgrade ) || $cliUpgrade !== "yes" )  ) {
+                       $this->showStatusMessage(
+                               Status::newFatal( "config-localsettings-cli-upgrade" )
+                       );
                }
+
+               $this->performInstallation(
+                       array( $this, 'startStage' ),
+                       array( $this, 'endStage' )
+               );
        }
 
-       function showMessage( $msg /*, ... */ ) {
-               $this->output->addHTML($msg);
-               $this->output->output();
+       /**
+        * Write LocalSettings.php to a given path
+        *
+        * @param $path String Full path to write LocalSettings.php to
+        */
+       public function writeConfigurationFile( $path ) {
+               $ls = new LocalSettingsGenerator( $this );
+               $ls->writeFile( "$path/LocalSettings.php" );
        }
 
-       function showStatusError( $status ) {
-               $this->output->addHTML($status->getWikiText()."\n");
-               $this->output->flush();
+       public function startStage( $step ) {
+               $this->showMessage( wfMsg( "config-install-$step" ) .
+                       wfMsg( 'ellipsis' ) . wfMsg( 'word-separator' ) );
+       }
+
+       public function endStage( $step, $status ) {
+               $this->showStatusMessage( $status );
+               $this->showMessage( wfMsg( 'config-install-step-done' ) . "\n" );
+       }
+
+       public function showMessage( $msg /*, ... */ ) {
+               $params = func_get_args();
+               array_shift( $params );
+
+               /* parseinline has the nasty side-effect of putting encoded
+                * angle brackets, around the message, so the substr removes
+                * them. */
+               $text = substr( wfMsgExt( $msg, array( 'parseinline' ), $params ), 4, -4 );
+               $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
+               echo html_entity_decode( strip_tags( $text ), ENT_QUOTES ) . "\n";
+               flush();
+       }
+
+       public function showStatusMessage( Status $status ) {
+               $warnings = array_merge( $status->getWarningsArray(),
+                       $status->getErrorsArray() );
+
+               if ( count( $warnings ) !== 0 ) {
+                       foreach ( $status->getWikiTextArray( $warnings ) as $w ) {
+                               $this->showMessage( $w . wfMsg( 'ellipsis' ) .
+                                       wfMsg( 'word-separator' ) );
+                       }
+               }
+
+               if ( !$status->isOk() ) {
+                       echo "\n";
+                       exit;
+               }
        }
 }