29 private $specifiedScriptPath =
false;
31 private const OPTION_MAP = [
32 'dbtype' =>
'wgDBtype',
33 'dbserver' =>
'wgDBserver',
34 'dbname' =>
'wgDBname',
35 'dbuser' =>
'wgDBuser',
36 'dbpass' =>
'wgDBpassword',
37 'dbprefix' =>
'wgDBprefix',
38 'dbtableoptions' =>
'wgDBTableOptions',
39 'dbport' =>
'wgDBport',
41 'dbschema' =>
'wgDBmwschema',
42 'dbpath' =>
'wgSQLiteDataDir',
43 'server' =>
'wgServer',
44 'scriptpath' =>
'wgScriptPath',
53 public function __construct( $siteName, $admin =
null, array $options = [] ) {
56 parent::__construct();
58 if ( isset( $options[
'scriptpath'] ) ) {
59 $this->specifiedScriptPath =
true;
62 foreach ( self::OPTION_MAP as $opt => $global ) {
63 if ( isset( $options[$opt] ) ) {
64 $GLOBALS[$global] = $options[$opt];
65 $this->
setVar( $global, $options[$opt] );
69 if ( isset( $options[
'lang'] ) ) {
71 $this->
setVar(
'_UserLang', $options[
'lang'] );
73 $this->
setVar(
'wgLanguageCode', $wgLanguageCode );
75 ->getLanguage( $options[
'lang'] );
76 RequestContext::getMain()->setLanguage(
$wgLang );
79 $this->
setVar(
'wgSitename', $siteName );
82 $metaNS = $contLang->ucfirst( str_replace(
' ',
'_', $siteName ) );
83 if ( $metaNS ==
'MediaWiki' ) {
86 $this->
setVar(
'wgMetaNamespace', $metaNS );
88 if ( !isset( $options[
'installdbuser'] ) ) {
89 $this->
setVar(
'_InstallUser',
90 $this->
getVar(
'wgDBuser' ) );
91 $this->
setVar(
'_InstallPassword',
92 $this->
getVar(
'wgDBpassword' ) );
94 $this->
setVar(
'_InstallUser',
95 $options[
'installdbuser'] );
96 $this->
setVar(
'_InstallPassword',
97 $options[
'installdbpass'] ??
"" );
100 $this->
setVar(
'_CreateDBAccount',
true );
104 $this->
setVar(
'_AdminName', $admin );
105 if ( isset( $options[
'pass'] ) ) {
106 $adminUser = User::newFromName( $admin );
108 throw new InstallException( Status::newFatal(
'config-admin-name-invalid' ) );
114 $status = $upp->checkUserPasswordForGroups( $adminUser, $options[
'pass'],
115 [
'bureaucrat',
'sysop',
'interface-admin' ] );
116 if ( !$status->isGood() ) {
118 $status->getMessage(
'config-admin-error-password-invalid' ) ) );
120 $this->
setVar(
'_AdminPassword', $options[
'pass'] );
125 if ( isset( $options[
'extensions'] ) ) {
126 $status = $this->validateExtensions(
127 'extension',
'extensions', $options[
'extensions'] );
128 if ( !$status->isOK() ) {
131 $this->
setVar(
'_Extensions', $status->value );
132 } elseif ( isset( $options[
'with-extensions'] ) ) {
134 if ( !$status->isOK() ) {
137 $this->
setVar(
'_Extensions', array_keys( $status->value ) );
141 if ( isset( $options[
'skins'] ) ) {
142 $status = $this->validateExtensions(
'skin',
'skins', $options[
'skins'] );
143 if ( !$status->isOK() ) {
146 $skins = $status->value;
149 if ( !$status->isOK() ) {
152 $skins = array_keys( $status->value );
154 $this->
setVar(
'_Skins', $skins );
157 $skinNames = array_map(
'strtolower', $skins );
161 $this->
setVar(
'_WithDevelopmentSettings', isset( $options[
'with-developmentsettings'] ) );
169 private function validateExtensions(
string $type,
string $directory, $nameLists ):
Status {
172 foreach ( (array)$nameLists as $nameList ) {
173 foreach ( explode(
',', $nameList ) as $name ) {
174 $name = trim( $name );
175 if ( $name ===
'' ) {
179 if ( $extStatus->isOK() ) {
180 $extensions[] = $name;
182 $status->merge( $extStatus );
186 $extensions = array_unique( $extensions );
187 $status->value = $extensions;
200 if ( count( $this->getVar(
'_Caches' ) ) ) {
202 $this->setVar(
'_MainCacheType',
'accel' );
207 $status = Status::newFatal(
"config-localsettings-cli-upgrade" );
208 $this->showStatusMessage( $status );
212 $status = $this->performInstallation(
213 $this->startStage( ... ),
214 $this->endStage( ... )
216 if ( $status->isOK() ) {
217 return Status::newGood();
230 $ls->writeFile(
"$path/LocalSettings.php" );
238 echo $this->formatMessage( $task->getDescriptionMessage() ) .
'... ';
246 $this->showStatusMessage( $status );
247 if ( $status->isOK() ) {
248 $this->showMessage(
'config-install-step-done' );
250 $this->showError(
'config-install-step-failed' );
257 echo $this->getMessageText( $msg, $params ) .
"\n";
264 echo $this->getMessageText( $msg, $params ) .
"\n";
271 echo $this->getMessageText( $msg, $params ) .
"\n";
278 echo
"***{$this->getMessageText( $msg, $params )}***\n";
288 return $this->formatMessage(
wfMessage( $msg, $params ) );
296 $text = $message->parse();
297 $text = preg_replace(
'/<a href="(.*?)".*?>(.*?)<\/a>/',
'$2 <$1>', $text );
298 return Sanitizer::stripAllTags( $text );
303 foreach ( $status->
getMessages(
'warning' ) as $msg ) {
304 $this->showMessage( $msg );
306 foreach ( $status->
getMessages(
'error' ) as $msg ) {
307 $this->showMessage( $msg );
313 if ( !$this->specifiedScriptPath ) {
314 $this->showMessage(
'config-no-cli-uri', $this->getVar(
"wgScriptPath" ) );
317 return parent::envCheckPath();
323 return 'http://localhost';
328 $this->showMessage(
'config-no-cli-uploads-check', $dir );
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
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.