c6b78d9fe253a9c3ed4a83a8695e19963b7fe4dd
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( wfMsg( "config-install-$step" ) .
116 wfMsg( 'ellipsis' ) . wfMsg( 'word-separator' ) );
119 public function endStage( $step, $status ) {
120 $this->showStatusMessage( $status );
121 $this->showMessage( wfMsg( 'config-install-step-done' ) . "\n" );
124 public function showMessage( $msg /*, ... */ ) {
125 $params = func_get_args();
126 array_shift( $params );
128 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
129 /* parseinline has the nasty side-effect of putting encoded
130 * angle brackets, around the message.
132 $text = preg_replace( '/(^<|>$)/', '', $text );
134 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text );
135 echo html_entity_decode( strip_tags( $text ), ENT_QUOTES
) . "\n";
139 public function showStatusMessage( Status
$status ) {
140 $warnings = array_merge( $status->getWarningsArray(),
141 $status->getErrorsArray() );
143 if ( count( $warnings ) !== 0 ) {
144 foreach ( $status->getWikiTextArray( $warnings ) as $w ) {
145 $this->showMessage( $w . wfMsg( 'ellipsis' ) .
146 wfMsg( 'word-separator' ) );
150 if ( !$status->isOk() ) {