34 private $specifiedScriptPath =
false;
36 private $optionMap = [
37 'dbtype' =>
'wgDBtype',
38 'dbserver' =>
'wgDBserver',
39 'dbname' =>
'wgDBname',
40 'dbuser' =>
'wgDBuser',
41 'dbpass' =>
'wgDBpassword',
42 'dbprefix' =>
'wgDBprefix',
43 'dbtableoptions' =>
'wgDBTableOptions',
44 'dbport' =>
'wgDBport',
45 'dbschema' =>
'wgDBmwschema',
46 'dbpath' =>
'wgSQLiteDataDir',
47 'server' =>
'wgServer',
48 'scriptpath' =>
'wgScriptPath',
57 public function __construct( $siteName, $admin =
null, array $options = [] ) {
60 parent::__construct();
62 if ( isset( $options[
'scriptpath'] ) ) {
63 $this->specifiedScriptPath =
true;
66 foreach ( $this->optionMap as $opt => $global ) {
67 if ( isset( $options[$opt] ) ) {
68 $GLOBALS[$global] = $options[$opt];
69 $this->
setVar( $global, $options[$opt] );
73 if ( isset( $options[
'lang'] ) ) {
75 $this->
setVar(
'_UserLang', $options[
'lang'] );
77 $this->
setVar(
'wgLanguageCode', $wgLanguageCode );
78 $wgLang = MediaWikiServices::getInstance()->getLanguageFactory()
79 ->getLanguage( $options[
'lang'] );
80 RequestContext::getMain()->setLanguage(
$wgLang );
83 $this->
setVar(
'wgSitename', $siteName );
85 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
86 $metaNS = $contLang->ucfirst( str_replace(
' ',
'_', $siteName ) );
87 if ( $metaNS ==
'MediaWiki' ) {
90 $this->
setVar(
'wgMetaNamespace', $metaNS );
92 if ( !isset( $options[
'installdbuser'] ) ) {
93 $this->
setVar(
'_InstallUser',
94 $this->
getVar(
'wgDBuser' ) );
95 $this->
setVar(
'_InstallPassword',
96 $this->
getVar(
'wgDBpassword' ) );
98 $this->
setVar(
'_InstallUser',
99 $options[
'installdbuser'] );
100 $this->
setVar(
'_InstallPassword',
101 $options[
'installdbpass'] ??
"" );
104 $this->
setVar(
'_CreateDBAccount',
true );
108 $this->
setVar(
'_AdminName', $admin );
109 if ( isset( $options[
'pass'] ) ) {
112 throw new InstallException( Status::newFatal(
'config-admin-name-invalid' ) );
118 $status = $upp->checkUserPasswordForGroups( $adminUser, $options[
'pass'],
119 [
'bureaucrat',
'sysop',
'interface-admin' ] );
120 if ( !$status->isGood() ) {
122 $status->getMessage(
'config-admin-error-password-invalid' ) ) );
124 $this->
setVar(
'_AdminPassword', $options[
'pass'] );
129 if ( isset( $options[
'extensions'] ) ) {
130 $status = $this->validateExtensions(
131 'extension',
'extensions', $options[
'extensions'] );
132 if ( !$status->isOK() ) {
135 $this->
setVar(
'_Extensions', $status->value );
136 } elseif ( isset( $options[
'with-extensions'] ) ) {
138 if ( !$status->isOK() ) {
141 $this->
setVar(
'_Extensions', array_keys( $status->value ) );
145 if ( isset( $options[
'skins'] ) ) {
146 $status = $this->validateExtensions(
'skin',
'skins', $options[
'skins'] );
147 if ( !$status->isOK() ) {
150 $skins = $status->value;
153 if ( !$status->isOK() ) {
156 $skins = array_keys( $status->value );
158 $this->
setVar(
'_Skins', $skins );
161 $skinNames = array_map(
'strtolower', $skins );
166 private function validateExtensions(
$type, $directory, $nameLists ) {
169 foreach ( (array)$nameLists as $nameList ) {
170 foreach ( explode(
',', $nameList ) as $name ) {
171 $name = trim( $name );
172 if ( $name ===
'' ) {
176 if ( $extStatus->isOK() ) {
177 $extensions[] = $name;
179 $status->merge( $extStatus );
183 $extensions = array_unique( $extensions );
184 $status->value = $extensions;
197 if ( count( $this->
getVar(
'_Caches' ) ) ) {
199 $this->
setVar(
'_MainCacheType',
'accel' );
204 $status = Status::newFatal(
"config-localsettings-cli-upgrade" );
210 [ $this,
'startStage' ],
211 [ $this,
'endStage' ]
215 $lastStepStatus = end( $result );
216 if ( $lastStepStatus->isOK() ) {
217 return Status::newGood();
219 return $lastStepStatus;
230 $ls->writeFile(
"$path/LocalSettings.php" );
242 if ( $status->isOK() ) {
245 $this->
showError(
'config-install-step-failed' );
257 echo
"***{$this->getMessageText( $msg, $params )}***\n";
268 $text =
wfMessage( $msg, $params )->parse();
270 $text = preg_replace(
'/<a href="(.*?)".*?>(.*?)<\/a>/',
'$2 <$1>', $text );
272 return Sanitizer::stripAllTags( $text );
287 if ( count( $warnings ) !== 0 ) {
288 foreach ( $warnings as $w ) {
295 if ( !$this->specifiedScriptPath ) {
299 return parent::envCheckPath();
304 return 'http://localhost';
308 $this->
showMessage(
'config-no-cli-uploads-check', $dir );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode $wgLang
Class for the core installer command line interface.
showMessage( $msg,... $params)
UI interface for displaying a short message The parameters are like parameters to wfMessage().
showHelpBox( $msg,... $params)
Dummy.
execute()
Main entry point.
__construct( $siteName, $admin=null, array $options=[])
getMessageText( $msg, $params)
showStatusMessage(Status $status)
Show a message to the installing user by using a Status object.
writeConfigurationFile( $path)
Write LocalSettings.php to a given path.
dirIsExecutable( $dir, $url)
Checks if scripts located in the given directory can be executed via the given URL.
showError( $msg,... $params)
Same as showMessage(), but for displaying errors.
envGetDefaultServer()
Helper function to be called from envPrepServer()
envCheckPath()
Environment check to inform user which paths we've assumed.
endStage( $step, $status)
static getLocalSettingsGenerator(Installer $installer)
Instantiates and returns an instance of LocalSettingsGenerator or its descendant classes.
getExtensionInfo( $type, $parentRelPath, $name)
getDefaultSkin(array $skinNames)
Returns a default value to be used for $wgDefaultSkin: normally the DefaultSkin from config-schema....
setVar( $name, $value)
Set a MW configuration variable, or internal installer configuration variable.
static getExistingLocalSettings()
Determine if LocalSettings.php exists.
performInstallation( $startCB, $endCB)
Actually perform the installation.
getVar( $name, $default=null)
Get an MW configuration variable, or internal installer configuration variable.
findExtensions( $directory='extensions')
Find extensions or skins in a subdirectory of $IP.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getErrorsArray()
Get the list of errors (but not warnings)
getWarningsArray()
Get the list of warnings (but not errors)
Check if a user's password complies with any password policies that apply to that user,...
static newFromName( $name, $validate='valid')
$wgLanguageCode
Config variable stub for the LanguageCode setting, for use by phpdoc and IDEs.
$wgPasswordPolicy
Config variable stub for the PasswordPolicy setting, for use by phpdoc and IDEs.