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' ) );
82 if ( isset( $option['pass'] ) ) {
83 $this->setVar( '_AdminPassword', $option['pass'] );
90 public function execute() {
91 $vars = $this->getExistingLocalSettings();
93 $this->showStatusMessage(
94 Status
::newFatal( "config-localsettings-cli-upgrade" )
98 $this->performInstallation(
99 array( $this, 'startStage' ),
100 array( $this, 'endStage' )
105 * Write LocalSettings.php to a given path
107 * @param $path String Full path to write LocalSettings.php to
109 public function writeConfigurationFile( $path ) {
110 $ls = new LocalSettingsGenerator( $this );
111 $ls->writeFile( "$path/LocalSettings.php" );
114 public function startStage( $step ) {
115 $this->showMessage( "config-install-$step" );
118 public function endStage( $step, $status ) {
119 $this->showStatusMessage( $status );
120 $this->showMessage( 'config-install-step-done' );
123 public function showMessage( $msg /*, ... */ ) {
124 $params = func_get_args();
125 array_shift( $params );
127 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
129 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text );
130 echo html_entity_decode( strip_tags( $text ), ENT_QUOTES
) . "\n";
134 public function showStatusMessage( Status
$status ) {
135 $warnings = array_merge( $status->getWarningsArray(),
136 $status->getErrorsArray() );
138 if ( count( $warnings ) !== 0 ) {
139 foreach ( $warnings as $w ) {
140 call_user_func_array( array( $this, 'showMessage' ), $w );
144 if ( !$status->isOk() ) {