avoid E_STRICT warnings when no --installdbpass is given
[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 isset( $option['installdbpass'] ) ? $option['installdbpass'] : "" );
86
87 // Assume that if we're given the installer user, we'll create the account.
88 $this->setVar( '_CreateDBAccount', true );
89 }
90
91 if ( isset( $option['pass'] ) ) {
92 $this->setVar( '_AdminPassword', $option['pass'] );
93 }
94 }
95
96 /**
97 * Main entry point.
98 */
99 public function execute() {
100 $vars = Installer::getExistingLocalSettings();
101 if( $vars ) {
102 $this->showStatusMessage(
103 Status::newFatal( "config-localsettings-cli-upgrade" )
104 );
105 }
106
107 $this->performInstallation(
108 array( $this, 'startStage' ),
109 array( $this, 'endStage' )
110 );
111 }
112
113 /**
114 * Write LocalSettings.php to a given path
115 *
116 * @param $path String Full path to write LocalSettings.php to
117 */
118 public function writeConfigurationFile( $path ) {
119 $ls = new LocalSettingsGenerator( $this );
120 $ls->writeFile( "$path/LocalSettings.php" );
121 }
122
123 public function startStage( $step ) {
124 $this->showMessage( "config-install-$step" );
125 }
126
127 public function endStage( $step, $status ) {
128 $this->showStatusMessage( $status );
129 $this->showMessage( 'config-install-step-done' );
130 }
131
132 public function showMessage( $msg /*, ... */ ) {
133 echo $this->getMessageText( func_get_args() ) . "\n";
134 flush();
135 }
136
137 public function showError( $msg /*, ... */ ) {
138 echo "***{$this->getMessageText( func_get_args() )}***\n";
139 flush();
140 }
141
142 /**
143 * @param $params array
144 *
145 * @return string
146 */
147 protected function getMessageText( $params ) {
148 $msg = array_shift( $params );
149
150 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
151
152 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
153 return html_entity_decode( strip_tags( $text ), ENT_QUOTES );
154 }
155
156 /**
157 * Dummy
158 */
159 public function showHelpBox( $msg /*, ... */ ) {
160 }
161
162 public function showStatusMessage( Status $status ) {
163 $warnings = array_merge( $status->getWarningsArray(),
164 $status->getErrorsArray() );
165
166 if ( count( $warnings ) !== 0 ) {
167 foreach ( $warnings as $w ) {
168 call_user_func_array( array( $this, 'showMessage' ), $w );
169 }
170 }
171
172 if ( !$status->isOk() ) {
173 echo "\n";
174 exit;
175 }
176 }
177
178 public function envCheckPath( ) {
179 if ( !$this->specifiedScriptPath ) {
180 $this->showMessage( 'config-no-cli-uri', $this->getVar("wgScriptPath") );
181 }
182 return parent::envCheckPath();
183 }
184
185 public function dirIsExecutable( $dir, $url ) {
186 $this->showMessage( 'config-no-cli-uploads-check', $dir );
187 return false;
188 }
189 }