37 private $specifiedScriptPath =
false;
39 private $optionMap = [
40 'dbtype' =>
'wgDBtype',
41 'dbserver' =>
'wgDBserver',
42 'dbname' =>
'wgDBname',
43 'dbuser' =>
'wgDBuser',
44 'dbpass' =>
'wgDBpassword',
45 'dbprefix' =>
'wgDBprefix',
46 'dbtableoptions' =>
'wgDBTableOptions',
47 'dbport' =>
'wgDBport',
49 'dbschema' =>
'wgDBmwschema',
50 'dbpath' =>
'wgSQLiteDataDir',
51 'server' =>
'wgServer',
52 'scriptpath' =>
'wgScriptPath',
61 public function __construct( $siteName, $admin =
null, array $options = [] ) {
64 parent::__construct();
66 if ( isset( $options[
'scriptpath'] ) ) {
67 $this->specifiedScriptPath =
true;
70 foreach ( $this->optionMap as $opt => $global ) {
71 if ( isset( $options[$opt] ) ) {
72 $GLOBALS[$global] = $options[$opt];
73 $this->
setVar( $global, $options[$opt] );
77 if ( isset( $options[
'lang'] ) ) {
79 $this->
setVar(
'_UserLang', $options[
'lang'] );
81 $this->
setVar(
'wgLanguageCode', $wgLanguageCode );
82 $wgLang = MediaWikiServices::getInstance()->getLanguageFactory()
83 ->getLanguage( $options[
'lang'] );
84 RequestContext::getMain()->setLanguage(
$wgLang );
87 $this->
setVar(
'wgSitename', $siteName );
89 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
90 $metaNS = $contLang->ucfirst( str_replace(
' ',
'_', $siteName ) );
91 if ( $metaNS ==
'MediaWiki' ) {
94 $this->
setVar(
'wgMetaNamespace', $metaNS );
96 if ( !isset( $options[
'installdbuser'] ) ) {
97 $this->
setVar(
'_InstallUser',
98 $this->
getVar(
'wgDBuser' ) );
99 $this->
setVar(
'_InstallPassword',
100 $this->
getVar(
'wgDBpassword' ) );
102 $this->
setVar(
'_InstallUser',
103 $options[
'installdbuser'] );
104 $this->
setVar(
'_InstallPassword',
105 $options[
'installdbpass'] ??
"" );
108 $this->
setVar(
'_CreateDBAccount',
true );
112 $this->
setVar(
'_AdminName', $admin );
113 if ( isset( $options[
'pass'] ) ) {
114 $adminUser = User::newFromName( $admin );
116 throw new InstallException( Status::newFatal(
'config-admin-name-invalid' ) );
122 $status = $upp->checkUserPasswordForGroups( $adminUser, $options[
'pass'],
123 [
'bureaucrat',
'sysop',
'interface-admin' ] );
124 if ( !$status->isGood() ) {
126 $status->getMessage(
'config-admin-error-password-invalid' ) ) );
128 $this->
setVar(
'_AdminPassword', $options[
'pass'] );
133 if ( isset( $options[
'extensions'] ) ) {
134 $status = $this->validateExtensions(
135 'extension',
'extensions', $options[
'extensions'] );
136 if ( !$status->isOK() ) {
139 $this->
setVar(
'_Extensions', $status->value );
140 } elseif ( isset( $options[
'with-extensions'] ) ) {
142 if ( !$status->isOK() ) {
145 $this->
setVar(
'_Extensions', array_keys( $status->value ) );
149 if ( isset( $options[
'skins'] ) ) {
150 $status = $this->validateExtensions(
'skin',
'skins', $options[
'skins'] );
151 if ( !$status->isOK() ) {
154 $skins = $status->value;
157 if ( !$status->isOK() ) {
160 $skins = array_keys( $status->value );
162 $this->
setVar(
'_Skins', $skins );
165 $skinNames = array_map(
'strtolower', $skins );
170 private function validateExtensions( $type, $directory, $nameLists ) {
173 foreach ( (array)$nameLists as $nameList ) {
174 foreach ( explode(
',', $nameList ) as $name ) {
175 $name = trim( $name );
176 if ( $name ===
'' ) {
180 if ( $extStatus->isOK() ) {
181 $extensions[] = $name;
183 $status->merge( $extStatus );
187 $extensions = array_unique( $extensions );
188 $status->value = $extensions;
201 if ( count( $this->
getVar(
'_Caches' ) ) ) {
203 $this->
setVar(
'_MainCacheType',
'accel' );
208 $status = Status::newFatal(
"config-localsettings-cli-upgrade" );
214 [ $this,
'startStage' ],
215 [ $this,
'endStage' ]
219 $lastStepStatus = end( $result );
220 if ( $lastStepStatus->isOK() ) {
221 return Status::newGood();
223 return $lastStepStatus;
234 $ls->writeFile(
"$path/LocalSettings.php" );
246 if ( $status->isOK() ) {
249 $this->
showError(
'config-install-step-failed' );
261 echo
"***{$this->getMessageText( $msg, $params )}***\n";
272 $text =
wfMessage( $msg, $params )->parse();
274 $text = preg_replace(
'/<a href="(.*?)".*?>(.*?)<\/a>/',
'$2 <$1>', $text );
276 return Sanitizer::stripAllTags( $text );
291 if ( count( $warnings ) !== 0 ) {
292 foreach ( $warnings as $w ) {
299 if ( !$this->specifiedScriptPath ) {
303 return parent::envCheckPath();
308 return 'http://localhost';
312 $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.
Check if a user's password complies with any password policies that apply to that user,...
$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.