3 * Core installer command line interface.
10 * Class for the core installer command line interface.
15 class CliInstaller
extends Installer
{
16 private $specifiedScriptPath = false;
18 private $optionMap = array(
19 'dbtype' => 'wgDBtype',
20 'dbserver' => 'wgDBserver',
21 'dbname' => 'wgDBname',
22 'dbuser' => 'wgDBuser',
23 'dbpass' => 'wgDBpassword',
24 'dbprefix' => 'wgDBprefix',
25 'dbtableoptions' => 'wgDBTableOptions',
26 'dbmysql5' => 'wgDBmysql5',
27 'dbport' => 'wgDBport',
28 'dbschema' => 'wgDBmwschema',
29 'dbpath' => 'wgSQLiteDataDir',
30 'scriptpath' => 'wgScriptPath',
38 * @param $option Array
40 function __construct( $siteName, $admin = null, array $option = array() ) {
43 parent
::__construct();
45 if ( isset( $option['scriptpath'] ) ) {
46 $this->specifiedScriptPath
= true;
49 foreach ( $this->optionMap
as $opt => $global ) {
50 if ( isset( $option[$opt] ) ) {
51 $GLOBALS[$global] = $option[$opt];
52 $this->setVar( $global, $option[$opt] );
56 if ( isset( $option['lang'] ) ) {
57 global $wgLang, $wgLanguageCode;
58 $this->setVar( '_UserLang', $option['lang'] );
59 $wgContLang = Language
::factory( $option['lang'] );
60 $wgLang = Language
::factory( $option['lang'] );
61 $wgLanguageCode = $option['lang'];
64 $this->setVar( 'wgSitename', $siteName );
66 $metaNS = $wgContLang->ucfirst( str_replace( ' ', '_', $siteName ) );
67 if ( $metaNS == 'MediaWiki' ) {
70 $this->setVar( 'wgMetaNamespace', $metaNS );
73 $this->setVar( '_AdminName', $admin );
76 if ( !isset( $option['installdbuser'] ) ) {
77 $this->setVar( '_InstallUser',
78 $this->getVar( 'wgDBuser' ) );
79 $this->setVar( '_InstallPassword',
80 $this->getVar( 'wgDBpassword' ) );
82 $this->setVar( '_InstallUser',
83 $option['installdbuser'] );
84 $this->setVar( '_InstallPassword',
85 $option['installdbpass'] );
88 if ( isset( $option['pass'] ) ) {
89 $this->setVar( '_AdminPassword', $option['pass'] );
96 public function execute() {
97 $vars = Installer
::getExistingLocalSettings();
99 $this->showStatusMessage(
100 Status
::newFatal( "config-localsettings-cli-upgrade" )
104 $this->performInstallation(
105 array( $this, 'startStage' ),
106 array( $this, 'endStage' )
111 * Write LocalSettings.php to a given path
113 * @param $path String Full path to write LocalSettings.php to
115 public function writeConfigurationFile( $path ) {
116 $ls = new LocalSettingsGenerator( $this );
117 $ls->writeFile( "$path/LocalSettings.php" );
120 public function startStage( $step ) {
121 $this->showMessage( "config-install-$step" );
124 public function endStage( $step, $status ) {
125 $this->showStatusMessage( $status );
126 $this->showMessage( 'config-install-step-done' );
129 public function showMessage( $msg /*, ... */ ) {
130 echo $this->getMessageText( func_get_args() ) . "\n";
134 public function showError( $msg /*, ... */ ) {
135 echo "***{$this->getMessageText( func_get_args() )}***\n";
140 * @param $params array
144 protected function getMessageText( $params ) {
145 $msg = array_shift( $params );
147 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
149 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text );
150 return html_entity_decode( strip_tags( $text ), ENT_QUOTES
);
156 public function showHelpBox( $msg /*, ... */ ) {
159 public function showStatusMessage( Status
$status ) {
160 $warnings = array_merge( $status->getWarningsArray(),
161 $status->getErrorsArray() );
163 if ( count( $warnings ) !== 0 ) {
164 foreach ( $warnings as $w ) {
165 call_user_func_array( array( $this, 'showMessage' ), $w );
169 if ( !$status->isOk() ) {
175 public function envCheckPath( ) {
176 if ( !$this->specifiedScriptPath
) {
177 $this->showMessage( 'config-no-cli-uri', $this->getVar("wgScriptPath") );
179 return parent
::envCheckPath();
182 public function dirIsExecutable( $dir, $url ) {
183 $this->showMessage( 'config-no-cli-uploads-check', $dir );