RELEASE-NOTES-1.19 for r103706, r103708
[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 'server' => 'wgServer',
31 'scriptpath' => 'wgScriptPath',
32 );
33
34 /**
35 * Constructor.
36 *
37 * @param $siteName
38 * @param $admin
39 * @param $option Array
40 */
41 function __construct( $siteName, $admin = null, array $option = array() ) {
42 global $wgContLang;
43
44 parent::__construct();
45
46 if ( isset( $option['scriptpath'] ) ) {
47 $this->specifiedScriptPath = true;
48 }
49
50 foreach ( $this->optionMap as $opt => $global ) {
51 if ( isset( $option[$opt] ) ) {
52 $GLOBALS[$global] = $option[$opt];
53 $this->setVar( $global, $option[$opt] );
54 }
55 }
56
57 if ( isset( $option['lang'] ) ) {
58 global $wgLang, $wgLanguageCode;
59 $this->setVar( '_UserLang', $option['lang'] );
60 $wgContLang = Language::factory( $option['lang'] );
61 $wgLang = Language::factory( $option['lang'] );
62 $wgLanguageCode = $option['lang'];
63 }
64
65 $this->setVar( 'wgSitename', $siteName );
66
67 $metaNS = $wgContLang->ucfirst( str_replace( ' ', '_', $siteName ) );
68 if ( $metaNS == 'MediaWiki' ) {
69 $metaNS = 'Project';
70 }
71 $this->setVar( 'wgMetaNamespace', $metaNS );
72
73 if ( $admin ) {
74 $this->setVar( '_AdminName', $admin );
75 }
76
77 if ( !isset( $option['installdbuser'] ) ) {
78 $this->setVar( '_InstallUser',
79 $this->getVar( 'wgDBuser' ) );
80 $this->setVar( '_InstallPassword',
81 $this->getVar( 'wgDBpassword' ) );
82 } else {
83 $this->setVar( '_InstallUser',
84 $option['installdbuser'] );
85 $this->setVar( '_InstallPassword',
86 isset( $option['installdbpass'] ) ? $option['installdbpass'] : "" );
87
88 // Assume that if we're given the installer user, we'll create the account.
89 $this->setVar( '_CreateDBAccount', true );
90 }
91
92 if ( isset( $option['pass'] ) ) {
93 $this->setVar( '_AdminPassword', $option['pass'] );
94 }
95 }
96
97 /**
98 * Main entry point.
99 */
100 public function execute() {
101 $vars = Installer::getExistingLocalSettings();
102 if( $vars ) {
103 $this->showStatusMessage(
104 Status::newFatal( "config-localsettings-cli-upgrade" )
105 );
106 }
107
108 $this->performInstallation(
109 array( $this, 'startStage' ),
110 array( $this, 'endStage' )
111 );
112 }
113
114 /**
115 * Write LocalSettings.php to a given path
116 *
117 * @param $path String Full path to write LocalSettings.php to
118 */
119 public function writeConfigurationFile( $path ) {
120 $ls = new LocalSettingsGenerator( $this );
121 $ls->writeFile( "$path/LocalSettings.php" );
122 }
123
124 public function startStage( $step ) {
125 $this->showMessage( "config-install-$step" );
126 }
127
128 public function endStage( $step, $status ) {
129 $this->showStatusMessage( $status );
130 $this->showMessage( 'config-install-step-done' );
131 }
132
133 public function showMessage( $msg /*, ... */ ) {
134 echo $this->getMessageText( func_get_args() ) . "\n";
135 flush();
136 }
137
138 public function showError( $msg /*, ... */ ) {
139 echo "***{$this->getMessageText( func_get_args() )}***\n";
140 flush();
141 }
142
143 /**
144 * @param $params array
145 *
146 * @return string
147 */
148 protected function getMessageText( $params ) {
149 $msg = array_shift( $params );
150
151 $text = wfMsgExt( $msg, array( 'parseinline' ), $params );
152
153 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
154 return html_entity_decode( strip_tags( $text ), ENT_QUOTES );
155 }
156
157 /**
158 * Dummy
159 */
160 public function showHelpBox( $msg /*, ... */ ) {
161 }
162
163 public function showStatusMessage( Status $status ) {
164 $warnings = array_merge( $status->getWarningsArray(),
165 $status->getErrorsArray() );
166
167 if ( count( $warnings ) !== 0 ) {
168 foreach ( $warnings as $w ) {
169 call_user_func_array( array( $this, 'showMessage' ), $w );
170 }
171 }
172
173 if ( !$status->isOk() ) {
174 echo "\n";
175 exit;
176 }
177 }
178
179 public function envCheckPath( ) {
180 if ( !$this->specifiedScriptPath ) {
181 $this->showMessage( 'config-no-cli-uri', $this->getVar("wgScriptPath") );
182 }
183 return parent::envCheckPath();
184 }
185
186 public function dirIsExecutable( $dir, $url ) {
187 $this->showMessage( 'config-no-cli-uploads-check', $dir );
188 return false;
189 }
190 }