MediaWiki
REL1_19
|
00001 <?php 00015 class CliInstaller extends Installer { 00016 private $specifiedScriptPath = false; 00017 00018 private $optionMap = array( 00019 'dbtype' => 'wgDBtype', 00020 'dbserver' => 'wgDBserver', 00021 'dbname' => 'wgDBname', 00022 'dbuser' => 'wgDBuser', 00023 'dbpass' => 'wgDBpassword', 00024 'dbprefix' => 'wgDBprefix', 00025 'dbtableoptions' => 'wgDBTableOptions', 00026 'dbmysql5' => 'wgDBmysql5', 00027 'dbport' => 'wgDBport', 00028 'dbschema' => 'wgDBmwschema', 00029 'dbpath' => 'wgSQLiteDataDir', 00030 'server' => 'wgServer', 00031 'scriptpath' => 'wgScriptPath', 00032 ); 00033 00041 function __construct( $siteName, $admin = null, array $option = array() ) { 00042 global $wgContLang; 00043 00044 parent::__construct(); 00045 00046 if ( isset( $option['scriptpath'] ) ) { 00047 $this->specifiedScriptPath = true; 00048 } 00049 00050 foreach ( $this->optionMap as $opt => $global ) { 00051 if ( isset( $option[$opt] ) ) { 00052 $GLOBALS[$global] = $option[$opt]; 00053 $this->setVar( $global, $option[$opt] ); 00054 } 00055 } 00056 00057 if ( isset( $option['lang'] ) ) { 00058 global $wgLang, $wgLanguageCode; 00059 $this->setVar( '_UserLang', $option['lang'] ); 00060 $wgContLang = Language::factory( $option['lang'] ); 00061 $wgLang = Language::factory( $option['lang'] ); 00062 $wgLanguageCode = $option['lang']; 00063 } 00064 00065 $this->setVar( 'wgSitename', $siteName ); 00066 00067 $metaNS = $wgContLang->ucfirst( str_replace( ' ', '_', $siteName ) ); 00068 if ( $metaNS == 'MediaWiki' ) { 00069 $metaNS = 'Project'; 00070 } 00071 $this->setVar( 'wgMetaNamespace', $metaNS ); 00072 00073 if ( $admin ) { 00074 $this->setVar( '_AdminName', $admin ); 00075 } 00076 00077 if ( !isset( $option['installdbuser'] ) ) { 00078 $this->setVar( '_InstallUser', 00079 $this->getVar( 'wgDBuser' ) ); 00080 $this->setVar( '_InstallPassword', 00081 $this->getVar( 'wgDBpassword' ) ); 00082 } else { 00083 $this->setVar( '_InstallUser', 00084 $option['installdbuser'] ); 00085 $this->setVar( '_InstallPassword', 00086 isset( $option['installdbpass'] ) ? $option['installdbpass'] : "" ); 00087 00088 // Assume that if we're given the installer user, we'll create the account. 00089 $this->setVar( '_CreateDBAccount', true ); 00090 } 00091 00092 if ( isset( $option['pass'] ) ) { 00093 $this->setVar( '_AdminPassword', $option['pass'] ); 00094 } 00095 } 00096 00100 public function execute() { 00101 $vars = Installer::getExistingLocalSettings(); 00102 if( $vars ) { 00103 $this->showStatusMessage( 00104 Status::newFatal( "config-localsettings-cli-upgrade" ) 00105 ); 00106 } 00107 00108 $this->performInstallation( 00109 array( $this, 'startStage' ), 00110 array( $this, 'endStage' ) 00111 ); 00112 } 00113 00119 public function writeConfigurationFile( $path ) { 00120 $ls = new LocalSettingsGenerator( $this ); 00121 $ls->writeFile( "$path/LocalSettings.php" ); 00122 } 00123 00124 public function startStage( $step ) { 00125 $this->showMessage( "config-install-$step" ); 00126 } 00127 00128 public function endStage( $step, $status ) { 00129 $this->showStatusMessage( $status ); 00130 $this->showMessage( 'config-install-step-done' ); 00131 } 00132 00133 public function showMessage( $msg /*, ... */ ) { 00134 echo $this->getMessageText( func_get_args() ) . "\n"; 00135 flush(); 00136 } 00137 00138 public function showError( $msg /*, ... */ ) { 00139 echo "***{$this->getMessageText( func_get_args() )}***\n"; 00140 flush(); 00141 } 00142 00148 protected function getMessageText( $params ) { 00149 $msg = array_shift( $params ); 00150 00151 $text = wfMsgExt( $msg, array( 'parseinline' ), $params ); 00152 00153 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text ); 00154 return html_entity_decode( strip_tags( $text ), ENT_QUOTES ); 00155 } 00156 00160 public function showHelpBox( $msg /*, ... */ ) { 00161 } 00162 00163 public function showStatusMessage( Status $status ) { 00164 $warnings = array_merge( $status->getWarningsArray(), 00165 $status->getErrorsArray() ); 00166 00167 if ( count( $warnings ) !== 0 ) { 00168 foreach ( $warnings as $w ) { 00169 call_user_func_array( array( $this, 'showMessage' ), $w ); 00170 } 00171 } 00172 00173 if ( !$status->isOk() ) { 00174 echo "\n"; 00175 exit; 00176 } 00177 } 00178 00179 public function envCheckPath( ) { 00180 if ( !$this->specifiedScriptPath ) { 00181 $this->showMessage( 'config-no-cli-uri', $this->getVar("wgScriptPath") ); 00182 } 00183 return parent::envCheckPath(); 00184 } 00185 00186 protected function envGetDefaultServer() { 00187 return $this->getVar( 'wgServer' ); 00188 } 00189 00190 public function dirIsExecutable( $dir, $url ) { 00191 $this->showMessage( 'config-no-cli-uploads-check', $dir ); 00192 return false; 00193 } 00194 }