Fixed spacing in db/debug/diff/externalstore/objectcache folder
[mediawiki.git] / includes / installer / CliInstaller.php
blobbb7e8776f3d3e611fda525409b58b990d7c1b42b
1 <?php
2 /**
3 * Core installer command line interface.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup Deployment
24 /**
25 * Class for the core installer command line interface.
27 * @ingroup Deployment
28 * @since 1.17
30 class CliInstaller extends Installer {
31 private $specifiedScriptPath = false;
33 private $optionMap = array(
34 'dbtype' => 'wgDBtype',
35 'dbserver' => 'wgDBserver',
36 'dbname' => 'wgDBname',
37 'dbuser' => 'wgDBuser',
38 'dbpass' => 'wgDBpassword',
39 'dbprefix' => 'wgDBprefix',
40 'dbtableoptions' => 'wgDBTableOptions',
41 'dbmysql5' => 'wgDBmysql5',
42 'dbport' => 'wgDBport',
43 'dbschema' => 'wgDBmwschema',
44 'dbpath' => 'wgSQLiteDataDir',
45 'server' => 'wgServer',
46 'scriptpath' => 'wgScriptPath',
49 /**
50 * Constructor.
52 * @param $siteName
53 * @param $admin
54 * @param $option Array
56 function __construct( $siteName, $admin = null, array $option = array() ) {
57 global $wgContLang;
59 parent::__construct();
61 if ( isset( $option['scriptpath'] ) ) {
62 $this->specifiedScriptPath = true;
65 foreach ( $this->optionMap as $opt => $global ) {
66 if ( isset( $option[$opt] ) ) {
67 $GLOBALS[$global] = $option[$opt];
68 $this->setVar( $global, $option[$opt] );
72 if ( isset( $option['lang'] ) ) {
73 global $wgLang, $wgLanguageCode;
74 $this->setVar( '_UserLang', $option['lang'] );
75 $wgContLang = Language::factory( $option['lang'] );
76 $wgLang = Language::factory( $option['lang'] );
77 $wgLanguageCode = $option['lang'];
80 $this->setVar( 'wgSitename', $siteName );
82 $metaNS = $wgContLang->ucfirst( str_replace( ' ', '_', $siteName ) );
83 if ( $metaNS == 'MediaWiki' ) {
84 $metaNS = 'Project';
86 $this->setVar( 'wgMetaNamespace', $metaNS );
88 if ( $admin ) {
89 $this->setVar( '_AdminName', $admin );
92 if ( !isset( $option['installdbuser'] ) ) {
93 $this->setVar( '_InstallUser',
94 $this->getVar( 'wgDBuser' ) );
95 $this->setVar( '_InstallPassword',
96 $this->getVar( 'wgDBpassword' ) );
97 } else {
98 $this->setVar( '_InstallUser',
99 $option['installdbuser'] );
100 $this->setVar( '_InstallPassword',
101 isset( $option['installdbpass'] ) ? $option['installdbpass'] : "" );
103 // Assume that if we're given the installer user, we'll create the account.
104 $this->setVar( '_CreateDBAccount', true );
107 if ( isset( $option['pass'] ) ) {
108 $this->setVar( '_AdminPassword', $option['pass'] );
113 * Main entry point.
115 public function execute() {
116 $vars = Installer::getExistingLocalSettings();
117 if( $vars ) {
118 $this->showStatusMessage(
119 Status::newFatal( "config-localsettings-cli-upgrade" )
123 $this->performInstallation(
124 array( $this, 'startStage' ),
125 array( $this, 'endStage' )
130 * Write LocalSettings.php to a given path
132 * @param string $path Full path to write LocalSettings.php to
134 public function writeConfigurationFile( $path ) {
135 $ls = InstallerOverrides::getLocalSettingsGenerator( $this );
136 $ls->writeFile( "$path/LocalSettings.php" );
139 public function startStage( $step ) {
140 $this->showMessage( "config-install-$step" );
143 public function endStage( $step, $status ) {
144 $this->showStatusMessage( $status );
145 $this->showMessage( 'config-install-step-done' );
148 public function showMessage( $msg /*, ... */ ) {
149 echo $this->getMessageText( func_get_args() ) . "\n";
150 flush();
153 public function showError( $msg /*, ... */ ) {
154 echo "***{$this->getMessageText( func_get_args() )}***\n";
155 flush();
159 * @param $params array
161 * @return string
163 protected function getMessageText( $params ) {
164 $msg = array_shift( $params );
166 $text = wfMessage( $msg, $params )->parse();
168 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 &lt;$1&gt;', $text );
169 return html_entity_decode( strip_tags( $text ), ENT_QUOTES );
173 * Dummy
175 public function showHelpBox( $msg /*, ... */ ) {
178 public function showStatusMessage( Status $status ) {
179 $warnings = array_merge( $status->getWarningsArray(),
180 $status->getErrorsArray() );
182 if ( count( $warnings ) !== 0 ) {
183 foreach ( $warnings as $w ) {
184 call_user_func_array( array( $this, 'showMessage' ), $w );
188 if ( !$status->isOk() ) {
189 echo "\n";
190 exit( 1 );
194 public function envCheckPath() {
195 if ( !$this->specifiedScriptPath ) {
196 $this->showMessage( 'config-no-cli-uri', $this->getVar( "wgScriptPath" ) );
198 return parent::envCheckPath();
201 protected function envGetDefaultServer() {
202 return $this->getVar( 'wgServer' );
205 public function dirIsExecutable( $dir, $url ) {
206 $this->showMessage( 'config-no-cli-uploads-check', $dir );
207 return false;