41 private $specifiedScriptPath =
false;
43 private const OPTION_MAP = [
44 'dbtype' =>
'wgDBtype',
45 'dbserver' =>
'wgDBserver',
46 'dbname' =>
'wgDBname',
47 'dbuser' =>
'wgDBuser',
48 'dbpass' =>
'wgDBpassword',
49 'dbprefix' =>
'wgDBprefix',
50 'dbtableoptions' =>
'wgDBTableOptions',
51 'dbport' =>
'wgDBport',
53 'dbschema' =>
'wgDBmwschema',
54 'dbpath' =>
'wgSQLiteDataDir',
55 'server' =>
'wgServer',
56 'scriptpath' =>
'wgScriptPath',
65 public function __construct( $siteName, $admin =
null, array $options = [] ) {
68 parent::__construct();
70 if ( isset( $options[
'scriptpath'] ) ) {
71 $this->specifiedScriptPath =
true;
74 foreach ( self::OPTION_MAP as $opt => $global ) {
75 if ( isset( $options[$opt] ) ) {
76 $GLOBALS[$global] = $options[$opt];
77 $this->
setVar( $global, $options[$opt] );
81 if ( isset( $options[
'lang'] ) ) {
83 $this->
setVar(
'_UserLang', $options[
'lang'] );
85 $this->
setVar(
'wgLanguageCode', $wgLanguageCode );
87 ->getLanguage( $options[
'lang'] );
88 RequestContext::getMain()->setLanguage(
$wgLang );
91 $this->
setVar(
'wgSitename', $siteName );
94 $metaNS = $contLang->ucfirst( str_replace(
' ',
'_', $siteName ) );
95 if ( $metaNS ==
'MediaWiki' ) {
98 $this->
setVar(
'wgMetaNamespace', $metaNS );
100 if ( !isset( $options[
'installdbuser'] ) ) {
101 $this->
setVar(
'_InstallUser',
102 $this->
getVar(
'wgDBuser' ) );
103 $this->
setVar(
'_InstallPassword',
104 $this->
getVar(
'wgDBpassword' ) );
106 $this->
setVar(
'_InstallUser',
107 $options[
'installdbuser'] );
108 $this->
setVar(
'_InstallPassword',
109 $options[
'installdbpass'] ??
"" );
112 $this->
setVar(
'_CreateDBAccount',
true );
116 $this->
setVar(
'_AdminName', $admin );
117 if ( isset( $options[
'pass'] ) ) {
118 $adminUser = User::newFromName( $admin );
120 throw new InstallException( Status::newFatal(
'config-admin-name-invalid' ) );
126 $status = $upp->checkUserPasswordForGroups( $adminUser, $options[
'pass'],
127 [
'bureaucrat',
'sysop',
'interface-admin' ] );
128 if ( !$status->isGood() ) {
130 $status->getMessage(
'config-admin-error-password-invalid' ) ) );
132 $this->
setVar(
'_AdminPassword', $options[
'pass'] );
137 if ( isset( $options[
'extensions'] ) ) {
138 $status = $this->validateExtensions(
139 'extension',
'extensions', $options[
'extensions'] );
140 if ( !$status->isOK() ) {
143 $this->
setVar(
'_Extensions', $status->value );
144 } elseif ( isset( $options[
'with-extensions'] ) ) {
146 if ( !$status->isOK() ) {
149 $this->
setVar(
'_Extensions', array_keys( $status->value ) );
153 if ( isset( $options[
'skins'] ) ) {
154 $status = $this->validateExtensions(
'skin',
'skins', $options[
'skins'] );
155 if ( !$status->isOK() ) {
158 $skins = $status->value;
161 if ( !$status->isOK() ) {
164 $skins = array_keys( $status->value );
166 $this->
setVar(
'_Skins', $skins );
169 $skinNames = array_map(
'strtolower', $skins );
173 $this->
setVar(
'_WithDevelopmentSettings', isset( $options[
'with-developmentsettings'] ) );
176 private function validateExtensions( $type, $directory, $nameLists ) {
179 foreach ( (array)$nameLists as $nameList ) {
180 foreach ( explode(
',', $nameList ) as $name ) {
181 $name = trim( $name );
182 if ( $name ===
'' ) {
186 if ( $extStatus->isOK() ) {
187 $extensions[] = $name;
189 $status->merge( $extStatus );
193 $extensions = array_unique( $extensions );
194 $status->value = $extensions;
207 if ( count( $this->
getVar(
'_Caches' ) ) ) {
209 $this->
setVar(
'_MainCacheType',
'accel' );
214 $status = Status::newFatal(
"config-localsettings-cli-upgrade" );
220 [ $this,
'startStage' ],
221 [ $this,
'endStage' ]
223 if ( $status->isOK() ) {
224 return Status::newGood();
237 $ls->writeFile(
"$path/LocalSettings.php" );
249 if ( $status->isOK() ) {
252 $this->
showError(
'config-install-step-failed' );
264 echo
"***{$this->getMessageText( $msg, $params )}***\n";
276 $text = preg_replace(
'/<a href="(.*?)".*?>(.*?)<\/a>/',
'$2 <$1>', $text );
278 return Sanitizer::stripAllTags( $text );
291 foreach ( $status->
getMessages(
'warning' ) as $msg ) {
294 foreach ( $status->
getMessages(
'error' ) as $msg ) {
300 if ( !$this->specifiedScriptPath ) {
304 return parent::envCheckPath();
309 return 'http://localhost';
313 $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') &&MW_ENTRY_POINT !=='cli' $wgLang
array $params
The job parameters.
Group all the pieces relevant to the context of a request into one instance.
getMessages(?string $type=null)
Returns a list of error messages, optionally only those of the given type.
$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.