Remove duplicate bits from the optionmap
[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 private $specifiedScriptPath = false;
17
18 private $optionMap = array(
19 'dbtype' => 'wgDBtype',
20 'dbserver' => 'wgDBserver',
21 'dbname' => 'wgDBname',
22 'dbuser' => 'wgDBuser',
23 'dbpass' => 'wgDBpassword',
24 'dbprefix' => 'wgDBprefix',
25 'dbtableoptions' => 'wgDBTableOptions',
26 'dbmysql5' => 'wgDBmysql5',
27 'dbport' => 'wgDBport',
28 'dbschema' => 'wgDBmwschema',
29 'dbpath' => 'wgSQLiteDataDir',
30 'scriptpath' => 'wgScriptPath',
31 );
32
33 /**
34 * Constructor.
35 *
36 * @param $siteName
37 * @param $admin
38 * @param $option Array
39 */
40 function __construct( $siteName, $admin = null, array $option = array() ) {
41 global $wgContLang;
42
43 parent::__construct();
44
45 if ( isset( $option['scriptpath'] ) ) {
46 $this->specifiedScriptPath = true;
47 }
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, $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 $metaNS = $wgContLang->ucfirst( str_replace( ' ', '_', $siteName ) );
67 if ( $metaNS == 'MediaWiki' ) {
68 $metaNS = 'Project';
69 }
70 $this->setVar( 'wgMetaNamespace', $metaNS );
71
72 if ( $admin ) {
73 $this->setVar( '_AdminName', $admin );
74 }
75
76 if ( !isset( $option['installdbuser'] ) ) {
77 $this->setVar( '_InstallUser',
78 $this->getVar( 'wgDBuser' ) );
79 $this->setVar( '_InstallPassword',
80 $this->getVar( 'wgDBpassword' ) );
81 } else {
82 $this->setVar( '_InstallUser',
83 $option['installdbuser'] );
84 $this->setVar( '_InstallPassword',
85 $option['installdbpass'] );
86 }
87
88 if ( isset( $option['pass'] ) ) {
89 $this->setVar( '_AdminPassword', $option['pass'] );
90 }
91 }
92
93 /**
94 * Main entry point.
95 */
96 public function execute() {
97 $vars = Installer::getExistingLocalSettings();
98 if( $vars ) {
99 $this->showStatusMessage(
100 Status::newFatal( "config-localsettings-cli-upgrade" )
101 );
102 }
103
104 $this->performInstallation(
105 array( $this, 'startStage' ),
106 array( $this, 'endStage' )
107 );
108 }
109
110 /**
111 * Write LocalSettings.php to a given path
112 *
113 * @param $path String Full path to write LocalSettings.php to
114 */
115 public function writeConfigurationFile( $path ) {
116 $ls = new LocalSettingsGenerator( $this );
117 $ls->writeFile( "$path/LocalSettings.php" );
118 }
119
120 public function startStage( $step ) {
121 $this->showMessage( "config-install-$step" );
122 }
123
124 public function endStage( $step, $status ) {
125 $this->showStatusMessage( $status );
126 $this->showMessage( 'config-install-step-done' );
127 }
128
129 public function showMessage( $msg /*, ... */ ) {
130 echo $this->getMessageText( func_get_args() ) . "\n";
131 flush();
132 }
133
134 public function showError( $msg /*, ... */ ) {
135 echo "***{$this->getMessageText( func_get_args() )}***\n";
136 flush();
137 }
138
139 /**
140 * @param $params array
141 *
142 * @return string
143 */
144 protected function getMessageText( $params ) {
145 $msg = array_shift( $params );
146
147 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
148
149 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
150 return html_entity_decode( strip_tags( $text ), ENT_QUOTES );
151 }
152
153 /**
154 * Dummy
155 */
156 public function showHelpBox( $msg /*, ... */ ) {
157 }
158
159 public function showStatusMessage( Status $status ) {
160 $warnings = array_merge( $status->getWarningsArray(),
161 $status->getErrorsArray() );
162
163 if ( count( $warnings ) !== 0 ) {
164 foreach ( $warnings as $w ) {
165 call_user_func_array( array( $this, 'showMessage' ), $w );
166 }
167 }
168
169 if ( !$status->isOk() ) {
170 echo "\n";
171 exit;
172 }
173 }
174
175 public function envCheckPath( ) {
176 if ( !$this->specifiedScriptPath ) {
177 $this->showMessage( 'config-no-cli-uri', $this->getVar("wgScriptPath") );
178 }
179 return parent::envCheckPath();
180 }
181
182 public function dirIsExecutable( $dir, $url ) {
183 $this->showMessage( 'config-no-cli-uploads-check', $dir );
184 return false;
185 }
186 }