MediaWiki  REL1_22
CliInstaller.php
Go to the documentation of this file.
00001 <?php
00030 class CliInstaller extends Installer {
00031     private $specifiedScriptPath = false;
00032 
00033     private $optionMap = array(
00034         'dbtype' => 'wgDBtype',
00035         'dbserver' => 'wgDBserver',
00036         'dbname' => 'wgDBname',
00037         'dbuser' => 'wgDBuser',
00038         'dbpass' => 'wgDBpassword',
00039         'dbprefix' => 'wgDBprefix',
00040         'dbtableoptions' => 'wgDBTableOptions',
00041         'dbmysql5' => 'wgDBmysql5',
00042         'dbport' => 'wgDBport',
00043         'dbschema' => 'wgDBmwschema',
00044         'dbpath' => 'wgSQLiteDataDir',
00045         'server' => 'wgServer',
00046         'scriptpath' => 'wgScriptPath',
00047     );
00048 
00056     function __construct( $siteName, $admin = null, array $option = array() ) {
00057         global $wgContLang;
00058 
00059         parent::__construct();
00060 
00061         if ( isset( $option['scriptpath'] ) ) {
00062             $this->specifiedScriptPath = true;
00063         }
00064 
00065         foreach ( $this->optionMap as $opt => $global ) {
00066             if ( isset( $option[$opt] ) ) {
00067                 $GLOBALS[$global] = $option[$opt];
00068                 $this->setVar( $global, $option[$opt] );
00069             }
00070         }
00071 
00072         if ( isset( $option['lang'] ) ) {
00073             global $wgLang, $wgLanguageCode;
00074             $this->setVar( '_UserLang', $option['lang'] );
00075             $wgContLang = Language::factory( $option['lang'] );
00076             $wgLang = Language::factory( $option['lang'] );
00077             $wgLanguageCode = $option['lang'];
00078         }
00079 
00080         $this->setVar( 'wgSitename', $siteName );
00081 
00082         $metaNS = $wgContLang->ucfirst( str_replace( ' ', '_', $siteName ) );
00083         if ( $metaNS == 'MediaWiki' ) {
00084             $metaNS = 'Project';
00085         }
00086         $this->setVar( 'wgMetaNamespace', $metaNS );
00087 
00088         if ( $admin ) {
00089             $this->setVar( '_AdminName', $admin );
00090         }
00091 
00092         if ( !isset( $option['installdbuser'] ) ) {
00093             $this->setVar( '_InstallUser',
00094                 $this->getVar( 'wgDBuser' ) );
00095             $this->setVar( '_InstallPassword',
00096                 $this->getVar( 'wgDBpassword' ) );
00097         } else {
00098             $this->setVar( '_InstallUser',
00099                 $option['installdbuser'] );
00100             $this->setVar( '_InstallPassword',
00101                 isset( $option['installdbpass'] ) ? $option['installdbpass'] : "" );
00102 
00103             // Assume that if we're given the installer user, we'll create the account.
00104             $this->setVar( '_CreateDBAccount', true );
00105         }
00106 
00107         if ( isset( $option['pass'] ) ) {
00108             $this->setVar( '_AdminPassword', $option['pass'] );
00109         }
00110     }
00111 
00115     public function execute() {
00116         $vars = Installer::getExistingLocalSettings();
00117         if ( $vars ) {
00118             $this->showStatusMessage(
00119                 Status::newFatal( "config-localsettings-cli-upgrade" )
00120             );
00121         }
00122 
00123         $this->performInstallation(
00124             array( $this, 'startStage' ),
00125             array( $this, 'endStage' )
00126         );
00127     }
00128 
00134     public function writeConfigurationFile( $path ) {
00135         $ls = InstallerOverrides::getLocalSettingsGenerator( $this );
00136         $ls->writeFile( "$path/LocalSettings.php" );
00137     }
00138 
00139     public function startStage( $step ) {
00140         // Messages: config-install-database, config-install-tables, config-install-interwiki,
00141         // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage
00142         $this->showMessage( "config-install-$step" );
00143     }
00144 
00145     public function endStage( $step, $status ) {
00146         $this->showStatusMessage( $status );
00147         $this->showMessage( 'config-install-step-done' );
00148     }
00149 
00150     public function showMessage( $msg /*, ... */ ) {
00151         echo $this->getMessageText( func_get_args() ) . "\n";
00152         flush();
00153     }
00154 
00155     public function showError( $msg /*, ... */ ) {
00156         echo "***{$this->getMessageText( func_get_args() )}***\n";
00157         flush();
00158     }
00159 
00165     protected function getMessageText( $params ) {
00166         $msg = array_shift( $params );
00167 
00168         $text = wfMessage( $msg, $params )->parse();
00169 
00170         $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
00171 
00172         return html_entity_decode( strip_tags( $text ), ENT_QUOTES );
00173     }
00174 
00178     public function showHelpBox( $msg /*, ... */ ) {
00179     }
00180 
00181     public function showStatusMessage( Status $status ) {
00182         $warnings = array_merge( $status->getWarningsArray(),
00183             $status->getErrorsArray() );
00184 
00185         if ( count( $warnings ) !== 0 ) {
00186             foreach ( $warnings as $w ) {
00187                 call_user_func_array( array( $this, 'showMessage' ), $w );
00188             }
00189         }
00190 
00191         if ( !$status->isOk() ) {
00192             echo "\n";
00193             exit( 1 );
00194         }
00195     }
00196 
00197     public function envCheckPath() {
00198         if ( !$this->specifiedScriptPath ) {
00199             $this->showMessage( 'config-no-cli-uri', $this->getVar( "wgScriptPath" ) );
00200         }
00201 
00202         return parent::envCheckPath();
00203     }
00204 
00205     protected function envGetDefaultServer() {
00206         return null; // Do not guess if installing from CLI
00207     }
00208 
00209     public function dirIsExecutable( $dir, $url ) {
00210         $this->showMessage( 'config-no-cli-uploads-check', $dir );
00211 
00212         return false;
00213     }
00214 }