MediaWiki  REL1_20
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                 $this->showMessage( "config-install-$step" );
00141         }
00142 
00143         public function endStage( $step, $status ) {
00144                 $this->showStatusMessage( $status );
00145                 $this->showMessage( 'config-install-step-done' );
00146         }
00147 
00148         public function showMessage( $msg /*, ... */ ) {
00149                 echo $this->getMessageText( func_get_args() ) . "\n";
00150                 flush();
00151         }
00152 
00153         public function showError( $msg /*, ... */ ) {
00154                 echo "***{$this->getMessageText( func_get_args() )}***\n";
00155                 flush();
00156         }
00157 
00163         protected function getMessageText( $params ) {
00164                 $msg = array_shift( $params );
00165 
00166                 $text = wfMessage( $msg, $params )->parse();
00167 
00168                 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
00169                 return html_entity_decode( strip_tags( $text ), ENT_QUOTES );
00170         }
00171 
00175         public function showHelpBox( $msg /*, ... */ ) {
00176         }
00177 
00178         public function showStatusMessage( Status $status ) {
00179                 $warnings = array_merge( $status->getWarningsArray(),
00180                         $status->getErrorsArray() );
00181 
00182                 if ( count( $warnings ) !== 0 ) {
00183                         foreach ( $warnings as $w ) {
00184                                 call_user_func_array( array( $this, 'showMessage' ), $w );
00185                         }
00186                 }
00187 
00188                 if ( !$status->isOk() ) {
00189                         echo "\n";
00190                         exit( 1 );
00191                 }
00192         }
00193 
00194         public function envCheckPath( ) {
00195                 if ( !$this->specifiedScriptPath ) {
00196                         $this->showMessage( 'config-no-cli-uri', $this->getVar("wgScriptPath") );
00197                 }
00198                 return parent::envCheckPath();
00199         }
00200 
00201         protected function envGetDefaultServer() {
00202                 return $this->getVar( 'wgServer' );
00203         }
00204 
00205         public function dirIsExecutable( $dir, $url ) {
00206                 $this->showMessage( 'config-no-cli-uploads-check', $dir );
00207                 return false;
00208         }
00209 }