Fixed message borkage from r78593
[lhc/web/wiklou.git] / includes / installer / CliInstaller.php
1 <?php
2 /**
3 * Core installer command line interface.
4 *
5 * @file
6 * @ingroup Deployment
7 */
8
9 /**
10 * Class for the core installer command line interface.
11 *
12 * @ingroup Deployment
13 * @since 1.17
14 */
15 class CliInstaller extends Installer {
16
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',
34 'upgrade' => 'cliUpgrade', /* As long as it isn't $confItems
35 * in LocalSettingsGenerator, we
36 * should be fine. */
37 );
38
39 /**
40 * Constructor.
41 *
42 * @param $siteName
43 * @param $admin
44 * @param $option Array
45 */
46 function __construct( $siteName, $admin = null, array $option = array() ) {
47 parent::__construct();
48
49 foreach ( $this->optionMap as $opt => $global ) {
50 if ( isset( $option[$opt] ) ) {
51 $GLOBALS[$global] = $option[$opt];
52 $this->setVar( $global, $option[$opt] );
53 }
54 }
55
56 if ( isset( $option['lang'] ) ) {
57 global $wgLang, $wgContLang, $wgLanguageCode;
58 $this->setVar( '_UserLang', $option['lang'] );
59 $wgContLang = Language::factory( $option['lang'] );
60 $wgLang = Language::factory( $option['lang'] );
61 $wgLanguageCode = $option['lang'];
62 }
63
64 $this->setVar( 'wgSitename', $siteName );
65
66 if ( $admin ) {
67 $this->setVar( '_AdminName', $admin );
68 }
69
70 if ( !isset( $option['installdbuser'] ) ) {
71 $this->setVar( '_InstallUser',
72 $this->getVar( 'wgDBuser' ) );
73 $this->setVar( '_InstallPassword',
74 $this->getVar( 'wgDBpassword' ) );
75 }
76
77 if ( isset( $option['pass'] ) ) {
78 $this->setVar( '_AdminPassword', $option['pass'] );
79 }
80 }
81
82 /**
83 * Main entry point.
84 */
85 public function execute() {
86 global $cliUpgrade;
87
88 $vars = $this->getExistingLocalSettings();
89 if( $vars && ( !isset( $cliUpgrade ) || $cliUpgrade !== "yes" ) ) {
90 $this->showStatusMessage(
91 Status::newFatal( "config-localsettings-cli-upgrade" )
92 );
93 }
94
95 $this->performInstallation(
96 array( $this, 'startStage' ),
97 array( $this, 'endStage' )
98 );
99 }
100
101 /**
102 * Write LocalSettings.php to a given path
103 *
104 * @param $path String Full path to write LocalSettings.php to
105 */
106 public function writeConfigurationFile( $path ) {
107 $ls = new LocalSettingsGenerator( $this );
108 $ls->writeFile( "$path/LocalSettings.php" );
109 }
110
111 public function startStage( $step ) {
112 $this->showMessage( wfMsg( "config-install-$step" ) .
113 wfMsg( 'ellipsis' ) . wfMsg( 'word-separator' ) );
114 }
115
116 public function endStage( $step, $status ) {
117 $this->showStatusMessage( $status );
118 $this->showMessage( wfMsg( 'config-install-step-done' ) . "\n" );
119 }
120
121 public function showMessage( $msg /*, ... */ ) {
122 $params = func_get_args();
123 array_shift( $params );
124
125 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
126 /* parseinline has the nasty side-effect of putting encoded
127 * angle brackets, around the message.
128 */
129 $text = preg_replace( '/(^&lt;|&gt;$)/', '', $text );
130
131 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
132 echo html_entity_decode( strip_tags( $text ), ENT_QUOTES ) . "\n";
133 flush();
134 }
135
136 public function showStatusMessage( Status $status ) {
137 $warnings = array_merge( $status->getWarningsArray(),
138 $status->getErrorsArray() );
139
140 if ( count( $warnings ) !== 0 ) {
141 foreach ( $status->getWikiTextArray( $warnings ) as $w ) {
142 $this->showMessage( $w . wfMsg( 'ellipsis' ) .
143 wfMsg( 'word-separator' ) );
144 }
145 }
146
147 if ( !$status->isOk() ) {
148 echo "\n";
149 exit;
150 }
151 }
152 }