3 * Core installer command line interface.
10 * Class for the core installer command line interface.
15 class CliInstaller
extends Installer
{
17 private $optionMap = array(
18 'dbtype' => 'wgDBtype',
19 'dbserver' => 'wgDBserver',
20 'dbname' => 'wgDBname',
21 'dbuser' => 'wgDBuser',
22 'dbpass' => 'wgDBpassword',
23 'dbprefix' => 'wgDBprefix',
24 'dbtableoptions' => 'wgDBTableOptions',
25 'dbmysql5' => 'wgDBmysql5',
26 'dbserver' => 'wgDBserver',
27 'dbport' => 'wgDBport',
28 'dbname' => 'wgDBname',
29 'dbuser' => 'wgDBuser',
30 'dbpass' => 'wgDBpassword',
31 'dbschema' => 'wgDBmwschema',
32 'dbpath' => 'wgSQLiteDataDir',
33 'scriptpath' => 'wgScriptPath',
41 * @param $option Array
43 function __construct( $siteName, $admin = null, array $option = array() ) {
46 parent
::__construct();
48 foreach ( $this->optionMap
as $opt => $global ) {
49 if ( isset( $option[$opt] ) ) {
50 $GLOBALS[$global] = $option[$opt];
51 $this->setVar( $global, $option[$opt] );
55 if ( isset( $option['lang'] ) ) {
56 global $wgLang, $wgLanguageCode;
57 $this->setVar( '_UserLang', $option['lang'] );
58 $wgContLang = Language
::factory( $option['lang'] );
59 $wgLang = Language
::factory( $option['lang'] );
60 $wgLanguageCode = $option['lang'];
63 $this->setVar( 'wgSitename', $siteName );
65 $metaNS = $wgContLang->ucfirst( str_replace( ' ', '_', $siteName ) );
66 if ( $metaNS == 'MediaWiki' ) {
69 $this->setVar( 'wgMetaNamespace', $metaNS );
72 $this->setVar( '_AdminName', $admin );
75 if ( !isset( $option['installdbuser'] ) ) {
76 $this->setVar( '_InstallUser',
77 $this->getVar( 'wgDBuser' ) );
78 $this->setVar( '_InstallPassword',
79 $this->getVar( 'wgDBpassword' ) );
81 $this->setVar( '_InstallUser',
82 $option['installdbuser'] );
83 $this->setVar( '_InstallPassword',
84 $option['installdbpass'] );
87 if ( isset( $option['pass'] ) ) {
88 $this->setVar( '_AdminPassword', $option['pass'] );
95 public function execute() {
96 $vars = Installer
::getExistingLocalSettings();
98 $this->showStatusMessage(
99 Status
::newFatal( "config-localsettings-cli-upgrade" )
103 $this->performInstallation(
104 array( $this, 'startStage' ),
105 array( $this, 'endStage' )
110 * Write LocalSettings.php to a given path
112 * @param $path String Full path to write LocalSettings.php to
114 public function writeConfigurationFile( $path ) {
115 $ls = new LocalSettingsGenerator( $this );
116 $ls->writeFile( "$path/LocalSettings.php" );
119 public function startStage( $step ) {
120 $this->showMessage( "config-install-$step" );
123 public function endStage( $step, $status ) {
124 $this->showStatusMessage( $status );
125 $this->showMessage( 'config-install-step-done' );
128 public function showMessage( $msg /*, ... */ ) {
129 echo $this->getMessageText( func_get_args() ) . "\n";
133 public function showError( $msg /*, ... */ ) {
134 echo "***{$this->getMessageText( func_get_args() )}***\n";
139 * @param $params array
143 protected function getMessageText( $params ) {
144 $msg = array_shift( $params );
146 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
148 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text );
149 return html_entity_decode( strip_tags( $text ), ENT_QUOTES
);
155 public function showHelpBox( $msg /*, ... */ ) {
158 public function showStatusMessage( Status
$status ) {
159 $warnings = array_merge( $status->getWarningsArray(),
160 $status->getErrorsArray() );
162 if ( count( $warnings ) !== 0 ) {
163 foreach ( $warnings as $w ) {
164 call_user_func_array( array( $this, 'showMessage' ), $w );
168 if ( !$status->isOk() ) {