43 private $specifiedScriptPath =
false;
45 private const OPTION_MAP = [
46 'dbtype' =>
'wgDBtype',
47 'dbserver' =>
'wgDBserver',
48 'dbname' =>
'wgDBname',
49 'dbuser' =>
'wgDBuser',
50 'dbpass' =>
'wgDBpassword',
51 'dbprefix' =>
'wgDBprefix',
52 'dbtableoptions' =>
'wgDBTableOptions',
53 'dbport' =>
'wgDBport',
55 'dbschema' =>
'wgDBmwschema',
56 'dbpath' =>
'wgSQLiteDataDir',
57 'server' =>
'wgServer',
58 'scriptpath' =>
'wgScriptPath',
67 public function __construct( $siteName, $admin =
null, array $options = [] ) {
70 parent::__construct();
72 if ( isset( $options[
'scriptpath'] ) ) {
73 $this->specifiedScriptPath =
true;
76 foreach ( self::OPTION_MAP as $opt => $global ) {
77 if ( isset( $options[$opt] ) ) {
78 $GLOBALS[$global] = $options[$opt];
79 $this->
setVar( $global, $options[$opt] );
83 if ( isset( $options[
'lang'] ) ) {
85 $this->
setVar(
'_UserLang', $options[
'lang'] );
87 $this->
setVar(
'wgLanguageCode', $wgLanguageCode );
89 ->getLanguage( $options[
'lang'] );
90 RequestContext::getMain()->setLanguage(
$wgLang );
93 $this->
setVar(
'wgSitename', $siteName );
96 $metaNS = $contLang->ucfirst( str_replace(
' ',
'_', $siteName ) );
97 if ( $metaNS ==
'MediaWiki' ) {
100 $this->
setVar(
'wgMetaNamespace', $metaNS );
102 if ( !isset( $options[
'installdbuser'] ) ) {
103 $this->
setVar(
'_InstallUser',
104 $this->
getVar(
'wgDBuser' ) );
105 $this->
setVar(
'_InstallPassword',
106 $this->
getVar(
'wgDBpassword' ) );
108 $this->
setVar(
'_InstallUser',
109 $options[
'installdbuser'] );
110 $this->
setVar(
'_InstallPassword',
111 $options[
'installdbpass'] ??
"" );
114 $this->
setVar(
'_CreateDBAccount',
true );
118 $this->
setVar(
'_AdminName', $admin );
119 if ( isset( $options[
'pass'] ) ) {
120 $adminUser = User::newFromName( $admin );
122 throw new InstallException( Status::newFatal(
'config-admin-name-invalid' ) );
128 $status = $upp->checkUserPasswordForGroups( $adminUser, $options[
'pass'],
129 [
'bureaucrat',
'sysop',
'interface-admin' ] );
130 if ( !$status->isGood() ) {
132 $status->getMessage(
'config-admin-error-password-invalid' ) ) );
134 $this->
setVar(
'_AdminPassword', $options[
'pass'] );
139 if ( isset( $options[
'extensions'] ) ) {
140 $status = $this->validateExtensions(
141 'extension',
'extensions', $options[
'extensions'] );
142 if ( !$status->isOK() ) {
145 $this->
setVar(
'_Extensions', $status->value );
146 } elseif ( isset( $options[
'with-extensions'] ) ) {
148 if ( !$status->isOK() ) {
151 $this->
setVar(
'_Extensions', array_keys( $status->value ) );
155 if ( isset( $options[
'skins'] ) ) {
156 $status = $this->validateExtensions(
'skin',
'skins', $options[
'skins'] );
157 if ( !$status->isOK() ) {
160 $skins = $status->value;
163 if ( !$status->isOK() ) {
166 $skins = array_keys( $status->value );
168 $this->
setVar(
'_Skins', $skins );
171 $skinNames = array_map(
'strtolower', $skins );
175 $this->
setVar(
'_WithDevelopmentSettings', isset( $options[
'with-developmentsettings'] ) );
178 private function validateExtensions( $type, $directory, $nameLists ) {
181 foreach ( (array)$nameLists as $nameList ) {
182 foreach ( explode(
',', $nameList ) as $name ) {
183 $name = trim( $name );
184 if ( $name ===
'' ) {
188 if ( $extStatus->isOK() ) {
189 $extensions[] = $name;
191 $status->merge( $extStatus );
195 $extensions = array_unique( $extensions );
196 $status->value = $extensions;
209 if ( count( $this->
getVar(
'_Caches' ) ) ) {
211 $this->
setVar(
'_MainCacheType',
'accel' );
216 $status = Status::newFatal(
"config-localsettings-cli-upgrade" );
222 [ $this,
'startStage' ],
223 [ $this,
'endStage' ]
225 if ( $status->isOK() ) {
226 return Status::newGood();
239 $ls->writeFile(
"$path/LocalSettings.php" );
247 echo $this->
formatMessage( $task->getDescriptionMessage() ) .
'... ';
256 if ( $status->isOK() ) {
259 $this->
showError(
'config-install-step-failed' );
271 echo
"***{$this->getMessageText( $msg, $params )}***\n";
289 $text = $message->parse();
290 $text = preg_replace(
'/<a href="(.*?)".*?>(.*?)<\/a>/',
'$2 <$1>', $text );
291 return Sanitizer::stripAllTags( $text );
296 foreach ( $status->
getMessages(
'warning' ) as $msg ) {
299 foreach ( $status->
getMessages(
'error' ) as $msg ) {
305 if ( !$this->specifiedScriptPath ) {
309 return parent::envCheckPath();
314 return 'http://localhost';
318 $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.