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 isset( $option['installdbpass'] ) ?
$option['installdbpass'] : "" );
87 // Assume that if we're given the installer user, we'll create the account.
88 $this->setVar( '_CreateDBAccount', true );
91 if ( isset( $option['pass'] ) ) {
92 $this->setVar( '_AdminPassword', $option['pass'] );
99 public function execute() {
100 $vars = Installer
::getExistingLocalSettings();
102 $this->showStatusMessage(
103 Status
::newFatal( "config-localsettings-cli-upgrade" )
107 $this->performInstallation(
108 array( $this, 'startStage' ),
109 array( $this, 'endStage' )
114 * Write LocalSettings.php to a given path
116 * @param $path String Full path to write LocalSettings.php to
118 public function writeConfigurationFile( $path ) {
119 $ls = new LocalSettingsGenerator( $this );
120 $ls->writeFile( "$path/LocalSettings.php" );
123 public function startStage( $step ) {
124 $this->showMessage( "config-install-$step" );
127 public function endStage( $step, $status ) {
128 $this->showStatusMessage( $status );
129 $this->showMessage( 'config-install-step-done' );
132 public function showMessage( $msg /*, ... */ ) {
133 echo $this->getMessageText( func_get_args() ) . "\n";
137 public function showError( $msg /*, ... */ ) {
138 echo "***{$this->getMessageText( func_get_args() )}***\n";
143 * @param $params array
147 protected function getMessageText( $params ) {
148 $msg = array_shift( $params );
150 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
152 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text );
153 return html_entity_decode( strip_tags( $text ), ENT_QUOTES
);
159 public function showHelpBox( $msg /*, ... */ ) {
162 public function showStatusMessage( Status
$status ) {
163 $warnings = array_merge( $status->getWarningsArray(),
164 $status->getErrorsArray() );
166 if ( count( $warnings ) !== 0 ) {
167 foreach ( $warnings as $w ) {
168 call_user_func_array( array( $this, 'showMessage' ), $w );
172 if ( !$status->isOk() ) {
178 public function envCheckPath( ) {
179 if ( !$this->specifiedScriptPath
) {
180 $this->showMessage( 'config-no-cli-uri', $this->getVar("wgScriptPath") );
182 return parent
::envCheckPath();
185 public function dirIsExecutable( $dir, $url ) {
186 $this->showMessage( 'config-no-cli-uploads-check', $dir );