3bc45b98394790c01e42b695ab979bbaab8e24fe
3 * Core installer command line interface.
10 * Class for the core installer command line interface.
15 class CliInstaller
extends CoreInstaller
{
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 'dbts2schema' => 'wgDBts2schema',
33 'dbpath' => 'wgSQLiteDataDir',
34 'scriptpath' => 'wgScriptPath',
35 'wikiroot' => 'wgScriptPath',
36 'upgrade' => 'cliUpgrade', /* As long as it isn't $confItems
37 * in LocalSettingsGenerator, we
46 * @param $option Array
48 function __construct( $siteName, $admin = null, array $option = array() ) {
49 parent
::__construct();
51 foreach ( $this->optionMap
as $opt => $global ) {
52 if ( isset( $option[$opt] ) ) {
53 $GLOBALS[$global] = $option[$opt];
54 $this->setVar( $global, $option[$opt] );
58 if ( isset( $option['lang'] ) ) {
59 global $wgLang, $wgContLang, $wgLanguageCode;
60 $this->setVar( '_UserLang', $option['lang'] );
61 $wgContLang = Language
::factory( $option['lang'] );
62 $wgLang = Language
::factory( $option['lang'] );
63 $wgLanguageCode = $option['lang'];
66 $this->setVar( 'wgSitename', $siteName );
69 $this->setVar( '_AdminName', $admin );
72 if ( !isset( $option['installdbuser'] ) ) {
73 $this->setVar( '_InstallUser',
74 $this->getVar( 'wgDBuser' ) );
75 $this->setVar( '_InstallPassword',
76 $this->getVar( 'wgDBpassword' ) );
79 if ( isset( $option['pass'] ) ) {
80 $this->setVar( '_AdminPassword', $option['pass'] );
87 public function execute() {
90 $vars = $this->getExistingLocalSettings();
91 if( $vars && ( !isset( $cliUpgrade ) ||
$cliUpgrade !== "yes" ) ) {
92 $this->showStatusMessage(
93 Status
::newFatal( "config-localsettings-cli-upgrade" )
97 $this->performInstallation(
98 array( $this, 'startStage' ),
99 array( $this, 'endStage' )
104 * Write LocalSettings.php to a given path
106 * @param $path String Full path to write LocalSettings.php to
108 public function writeConfigurationFile( $path ) {
109 $ls = new LocalSettingsGenerator( $this );
110 $ls->writeFile( "$path/LocalSettings.php" );
113 public function startStage( $step ) {
114 $this->showMessage( wfMsg( "config-install-$step" ) .
115 wfMsg( 'ellipsis' ) . wfMsg( 'word-separator' ) );
118 public function endStage( $step, $status ) {
119 $this->showStatusMessage( $status );
120 $this->showMessage( wfMsg( 'config-install-step-done' ) . "\n" );
123 public function showMessage( $msg /*, ... */ ) {
124 $params = func_get_args();
125 array_shift( $params );
127 /* parseinline has the nasty side-effect of putting encoded
128 * angle brackets, around the message, so the substr removes
130 $text = substr( wfMsgExt( $msg, array( 'parseinline' ), $params ), 4, -4 );
131 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text );
132 echo html_entity_decode( strip_tags( $text ), ENT_QUOTES
) . "\n";
136 public function showStatusMessage( Status
$status ) {
137 $warnings = array_merge( $status->getWarningsArray(),
138 $status->getErrorsArray() );
140 if ( count( $warnings ) !== 0 ) {
141 foreach ( $status->getWikiTextArray( $warnings ) as $w ) {
142 $this->showMessage( $w . wfMsg( 'ellipsis' ) .
143 wfMsg( 'word-separator' ) );
147 if ( !$status->isOk() ) {