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
25 * Class for the core installer command line interface.
30 class CliInstaller
extends Installer
{
31 private $specifiedScriptPath = false;
33 private $optionMap = [
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',
50 * @param string $siteName
51 * @param string $admin
52 * @param array $option
54 function __construct( $siteName, $admin = null, array $option = [] ) {
57 parent
::__construct();
59 if ( isset( $option['scriptpath'] ) ) {
60 $this->specifiedScriptPath
= true;
63 foreach ( $this->optionMap
as $opt => $global ) {
64 if ( isset( $option[$opt] ) ) {
65 $GLOBALS[$global] = $option[$opt];
66 $this->setVar( $global, $option[$opt] );
70 if ( isset( $option['lang'] ) ) {
71 global $wgLang, $wgLanguageCode;
72 $this->setVar( '_UserLang', $option['lang'] );
73 $wgContLang = Language
::factory( $option['lang'] );
74 $wgLang = Language
::factory( $option['lang'] );
75 $wgLanguageCode = $option['lang'];
76 RequestContext
::getMain()->setLanguage( $wgLang );
79 $this->setVar( 'wgSitename', $siteName );
81 $metaNS = $wgContLang->ucfirst( str_replace( ' ', '_', $siteName ) );
82 if ( $metaNS == 'MediaWiki' ) {
85 $this->setVar( 'wgMetaNamespace', $metaNS );
88 $this->setVar( '_AdminName', $admin );
91 if ( !isset( $option['installdbuser'] ) ) {
92 $this->setVar( '_InstallUser',
93 $this->getVar( 'wgDBuser' ) );
94 $this->setVar( '_InstallPassword',
95 $this->getVar( 'wgDBpassword' ) );
97 $this->setVar( '_InstallUser',
98 $option['installdbuser'] );
99 $this->setVar( '_InstallPassword',
100 isset( $option['installdbpass'] ) ?
$option['installdbpass'] : "" );
102 // Assume that if we're given the installer user, we'll create the account.
103 $this->setVar( '_CreateDBAccount', true );
106 if ( isset( $option['pass'] ) ) {
107 $this->setVar( '_AdminPassword', $option['pass'] );
110 // Detect and inject any extension found
111 if ( isset( $option['with-extensions'] ) ) {
112 $this->setVar( '_Extensions', array_keys( $this->findExtensions() ) );
115 // Set up the default skins
116 $skins = array_keys( $this->findExtensions( 'skins' ) );
117 $this->setVar( '_Skins', $skins );
120 $skinNames = array_map( 'strtolower', $skins );
121 $this->setVar( 'wgDefaultSkin', $this->getDefaultSkin( $skinNames ) );
128 public function execute() {
129 $vars = Installer
::getExistingLocalSettings();
131 $this->showStatusMessage(
132 Status
::newFatal( "config-localsettings-cli-upgrade" )
136 $this->performInstallation(
137 [ $this, 'startStage' ],
138 [ $this, 'endStage' ]
143 * Write LocalSettings.php to a given path
145 * @param string $path Full path to write LocalSettings.php to
147 public function writeConfigurationFile( $path ) {
148 $ls = InstallerOverrides
::getLocalSettingsGenerator( $this );
149 $ls->writeFile( "$path/LocalSettings.php" );
152 public function startStage( $step ) {
153 // Messages: config-install-database, config-install-tables, config-install-interwiki,
154 // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage,
155 // config-install-extensions
156 $this->showMessage( "config-install-$step" );
159 public function endStage( $step, $status ) {
160 $this->showStatusMessage( $status );
161 $this->showMessage( 'config-install-step-done' );
164 public function showMessage( $msg /*, ... */ ) {
165 echo $this->getMessageText( func_get_args() ) . "\n";
169 public function showError( $msg /*, ... */ ) {
170 echo "***{$this->getMessageText( func_get_args() )}***\n";
175 * @param array $params
179 protected function getMessageText( $params ) {
180 $msg = array_shift( $params );
182 $text = wfMessage( $msg, $params )->parse();
184 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text );
186 return Sanitizer
::stripAllTags( $text );
192 public function showHelpBox( $msg /*, ... */ ) {
195 public function showStatusMessage( Status
$status ) {
196 $warnings = array_merge( $status->getWarningsArray(),
197 $status->getErrorsArray() );
199 if ( count( $warnings ) !== 0 ) {
200 foreach ( $warnings as $w ) {
201 call_user_func_array( [ $this, 'showMessage' ], $w );
205 if ( !$status->isOK() ) {
211 public function envCheckPath() {
212 if ( !$this->specifiedScriptPath
) {
213 $this->showMessage( 'config-no-cli-uri', $this->getVar( "wgScriptPath" ) );
216 return parent
::envCheckPath();
219 protected function envGetDefaultServer() {
220 return null; // Do not guess if installing from CLI
223 public function dirIsExecutable( $dir, $url ) {
224 $this->showMessage( 'config-no-cli-uploads-check', $dir );