MediaWiki
REL1_24
|
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 // Set up the default skins 00112 $skins = $this->findExtensions( 'skins' ); 00113 $this->setVar( '_Skins', $skins ); 00114 00115 if ( $skins ) { 00116 $skinNames = array_map( 'strtolower', $skins ); 00117 $this->setVar( 'wgDefaultSkin', $this->getDefaultSkin( $skinNames ) ); 00118 } 00119 } 00120 00124 public function execute() { 00125 $vars = Installer::getExistingLocalSettings(); 00126 if ( $vars ) { 00127 $this->showStatusMessage( 00128 Status::newFatal( "config-localsettings-cli-upgrade" ) 00129 ); 00130 } 00131 00132 $this->performInstallation( 00133 array( $this, 'startStage' ), 00134 array( $this, 'endStage' ) 00135 ); 00136 } 00137 00143 public function writeConfigurationFile( $path ) { 00144 $ls = InstallerOverrides::getLocalSettingsGenerator( $this ); 00145 $ls->writeFile( "$path/LocalSettings.php" ); 00146 } 00147 00148 public function startStage( $step ) { 00149 // Messages: config-install-database, config-install-tables, config-install-interwiki, 00150 // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage, 00151 // config-install-extensions 00152 $this->showMessage( "config-install-$step" ); 00153 } 00154 00155 public function endStage( $step, $status ) { 00156 $this->showStatusMessage( $status ); 00157 $this->showMessage( 'config-install-step-done' ); 00158 } 00159 00160 public function showMessage( $msg /*, ... */ ) { 00161 echo $this->getMessageText( func_get_args() ) . "\n"; 00162 flush(); 00163 } 00164 00165 public function showError( $msg /*, ... */ ) { 00166 echo "***{$this->getMessageText( func_get_args() )}***\n"; 00167 flush(); 00168 } 00169 00175 protected function getMessageText( $params ) { 00176 $msg = array_shift( $params ); 00177 00178 $text = wfMessage( $msg, $params )->parse(); 00179 00180 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text ); 00181 00182 return html_entity_decode( strip_tags( $text ), ENT_QUOTES ); 00183 } 00184 00188 public function showHelpBox( $msg /*, ... */ ) { 00189 } 00190 00191 public function showStatusMessage( Status $status ) { 00192 $warnings = array_merge( $status->getWarningsArray(), 00193 $status->getErrorsArray() ); 00194 00195 if ( count( $warnings ) !== 0 ) { 00196 foreach ( $warnings as $w ) { 00197 call_user_func_array( array( $this, 'showMessage' ), $w ); 00198 } 00199 } 00200 00201 if ( !$status->isOk() ) { 00202 echo "\n"; 00203 exit( 1 ); 00204 } 00205 } 00206 00207 public function envCheckPath() { 00208 if ( !$this->specifiedScriptPath ) { 00209 $this->showMessage( 'config-no-cli-uri', $this->getVar( "wgScriptPath" ) ); 00210 } 00211 00212 return parent::envCheckPath(); 00213 } 00214 00215 protected function envGetDefaultServer() { 00216 return null; // Do not guess if installing from CLI 00217 } 00218 00219 public function dirIsExecutable( $dir, $url ) { 00220 $this->showMessage( 'config-no-cli-uploads-check', $dir ); 00221 00222 return false; 00223 } 00224 }