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 'dbport' => 'wgDBport',
42 'dbschema' => 'wgDBmwschema',
43 'dbpath' => 'wgSQLiteDataDir',
44 'server' => 'wgServer',
45 'scriptpath' => 'wgScriptPath',
49 * @param string $siteName
50 * @param string $admin
51 * @param array $option
53 function __construct( $siteName, $admin = null, array $option = [] ) {
56 parent
::__construct();
58 if ( isset( $option['scriptpath'] ) ) {
59 $this->specifiedScriptPath
= true;
62 foreach ( $this->optionMap
as $opt => $global ) {
63 if ( isset( $option[$opt] ) ) {
64 $GLOBALS[$global] = $option[$opt];
65 $this->setVar( $global, $option[$opt] );
69 if ( isset( $option['lang'] ) ) {
70 global $wgLang, $wgLanguageCode;
71 $this->setVar( '_UserLang', $option['lang'] );
72 $wgContLang = Language
::factory( $option['lang'] );
73 $wgLang = Language
::factory( $option['lang'] );
74 $wgLanguageCode = $option['lang'];
75 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
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 // If APC is available, use that as the MainCacheType, instead of nothing.
130 // This is hacky and should be consolidated with WebInstallerOptions.
131 // This is here instead of in __construct(), because it should run run after
132 // doEnvironmentChecks(), which populates '_Caches'.
133 if ( count( $this->getVar( '_Caches' ) ) ) {
134 // We detected a CACHE_ACCEL implementation, use it.
135 $this->setVar( '_MainCacheType', 'accel' );
138 $vars = Installer
::getExistingLocalSettings();
140 $this->showStatusMessage(
141 Status
::newFatal( "config-localsettings-cli-upgrade" )
145 $this->performInstallation(
146 [ $this, 'startStage' ],
147 [ $this, 'endStage' ]
152 * Write LocalSettings.php to a given path
154 * @param string $path Full path to write LocalSettings.php to
156 public function writeConfigurationFile( $path ) {
157 $ls = InstallerOverrides
::getLocalSettingsGenerator( $this );
158 $ls->writeFile( "$path/LocalSettings.php" );
161 public function startStage( $step ) {
162 // Messages: config-install-database, config-install-tables, config-install-interwiki,
163 // config-install-stats, config-install-keys, config-install-sysop, config-install-mainpage,
164 // config-install-extensions
165 $this->showMessage( "config-install-$step" );
168 public function endStage( $step, $status ) {
169 $this->showStatusMessage( $status );
170 $this->showMessage( 'config-install-step-done' );
173 public function showMessage( $msg /*, ... */ ) {
174 echo $this->getMessageText( func_get_args() ) . "\n";
178 public function showError( $msg /*, ... */ ) {
179 echo "***{$this->getMessageText( func_get_args() )}***\n";
184 * @param array $params
188 protected function getMessageText( $params ) {
189 $msg = array_shift( $params );
191 $text = wfMessage( $msg, $params )->parse();
193 $text = preg_replace( '/<a href="(.*?)".*?>(.*?)<\/a>/', '$2 <$1>', $text );
195 return Sanitizer
::stripAllTags( $text );
201 public function showHelpBox( $msg /*, ... */ ) {
204 public function showStatusMessage( Status
$status ) {
205 $warnings = array_merge( $status->getWarningsArray(),
206 $status->getErrorsArray() );
208 if ( count( $warnings ) !== 0 ) {
209 foreach ( $warnings as $w ) {
210 call_user_func_array( [ $this, 'showMessage' ], $w );
214 if ( !$status->isOK() ) {
220 public function envCheckPath() {
221 if ( !$this->specifiedScriptPath
) {
222 $this->showMessage( 'config-no-cli-uri', $this->getVar( "wgScriptPath" ) );
225 return parent
::envCheckPath();
228 protected function envGetDefaultServer() {
229 return null; // Do not guess if installing from CLI
232 public function dirIsExecutable( $dir, $url ) {
233 $this->showMessage( 'config-no-cli-uploads-check', $dir );