MediaWiki
REL1_41
WebInstallerExistingWiki.php
Go to the documentation of this file.
1
<?php
2
3
use
MediaWiki\Status\Status
;
4
25
class
WebInstallerExistingWiki
extends
WebInstallerPage
{
26
30
public
function
execute
() {
31
// If there is no LocalSettings.php, continue to the installer welcome page
32
$vars =
Installer::getExistingLocalSettings
();
33
if
( !$vars ) {
34
return
'skip'
;
35
}
36
37
// Check if the upgrade key supplied to the user has appeared in LocalSettings.php
38
if
( $vars[
'wgUpgradeKey'
] !==
false
39
&& $this->
getVar
(
'_UpgradeKeySupplied'
)
40
&& $this->
getVar
(
'wgUpgradeKey'
) === $vars[
'wgUpgradeKey'
]
41
) {
42
// It's there, so the user is authorized
43
$status = $this->
handleExistingUpgrade
( $vars );
44
if
( $status->isOK() ) {
45
return
'skip'
;
46
}
else
{
47
$this->
startForm
();
48
$this->parent->showStatusBox( $status );
49
$this->
endForm
(
'continue'
);
50
51
return
'output'
;
52
}
53
}
54
55
// If there is no $wgUpgradeKey, tell the user to add one to LocalSettings.php
56
if
( $vars[
'wgUpgradeKey'
] ===
false
) {
57
if
( $this->
getVar
(
'wgUpgradeKey'
,
false
) ===
false
) {
58
$secretKey = $this->
getVar
(
'wgSecretKey'
);
// preserve $wgSecretKey
59
$this->parent->generateKeys();
60
$this->
setVar
(
'wgSecretKey'
, $secretKey );
61
$this->
setVar
(
'_UpgradeKeySupplied'
,
true
);
62
}
63
$this->
startForm
();
64
$this->
addHTML
( $this->parent->getInfoBox(
65
wfMessage
(
'config-upgrade-key-missing'
,
"<pre dir=\"ltr\">\$wgUpgradeKey = '"
.
66
$this->
getVar
(
'wgUpgradeKey'
) .
"';</pre>"
)->plain()
67
) );
68
$this->
endForm
(
'continue'
);
69
70
return
'output'
;
71
}
72
73
// If there is an upgrade key, but it wasn't supplied, prompt the user to enter it
74
75
$r = $this->parent->request;
76
if
( $r->wasPosted() ) {
77
$key = $r->getText(
'config_wgUpgradeKey'
);
78
if
( !$key || $key !== $vars[
'wgUpgradeKey'
] ) {
79
$this->parent->showError(
'config-localsettings-badkey'
);
80
$this->
showKeyForm
();
81
82
return
'output'
;
83
}
84
// Key was OK
85
$status = $this->
handleExistingUpgrade
( $vars );
86
if
( $status->isOK() ) {
87
return
'continue'
;
88
}
else
{
89
$this->parent->showStatusBox( $status );
90
$this->
showKeyForm
();
91
92
return
'output'
;
93
}
94
}
else
{
95
$this->
showKeyForm
();
96
97
return
'output'
;
98
}
99
}
100
104
protected
function
showKeyForm
() {
105
$this->
startForm
();
106
$this->
addHTML
(
107
$this->parent->getInfoBox(
wfMessage
(
'config-localsettings-upgrade'
)->plain() ) .
108
'<br />'
.
109
$this->parent->getTextBox( [
110
'var'
=>
'wgUpgradeKey'
,
111
'label'
=>
'config-localsettings-key'
,
112
'attribs'
=> [
'autocomplete'
=>
'off'
],
113
] )
114
);
115
$this->
endForm
(
'continue'
);
116
}
117
124
protected
function
importVariables
( $names, $vars ) {
125
$status = Status::newGood();
126
foreach
( $names as $name ) {
127
if
( !isset( $vars[$name] ) ) {
128
$status->fatal(
'config-localsettings-incomplete'
, $name );
129
}
130
$this->
setVar
( $name, $vars[$name] );
131
}
132
133
return
$status;
134
}
135
143
protected
function
handleExistingUpgrade
( $vars ) {
144
// Check $wgDBtype
145
if
( !isset( $vars[
'wgDBtype'
] ) ||
146
!in_array( $vars[
'wgDBtype'
],
Installer::getDBTypes
() )
147
) {
148
return
Status::newFatal(
'config-localsettings-connection-error'
,
''
);
149
}
150
151
// Set the relevant variables from LocalSettings.php
152
$requiredVars = [
'wgDBtype'
];
153
$status = $this->
importVariables
( $requiredVars, $vars );
154
$installer = $this->parent->getDBInstaller();
155
$status->merge( $this->
importVariables
( $installer->getGlobalNames(), $vars ) );
156
if
( !$status->isOK() ) {
157
return
$status;
158
}
159
160
$this->
setVar
(
'_InstallUser'
, $vars[
'wgDBadminuser'
] ?? $vars[
'wgDBuser'
] );
161
$this->
setVar
(
'_InstallPassword'
, $vars[
'wgDBadminpassword'
] ?? $vars[
'wgDBpassword'
] );
162
163
// Test the database connection
164
$status = $installer->getConnection();
165
if
( !$status->isOK() ) {
166
// Adjust the error message to explain things correctly
167
$status->replaceMessage(
'config-connection-error'
,
168
'config-localsettings-connection-error'
);
169
170
return
$status;
171
}
172
173
// All good
174
$this->
setVar
(
'_ExistingDBSettings'
,
true
);
175
176
// Copy $wgAuthenticationTokenVersion too, if it exists
177
$this->
setVar
(
'wgAuthenticationTokenVersion'
,
178
$vars[
'wgAuthenticationTokenVersion'
] ??
null
179
);
180
181
return
$status;
182
}
183
184
}
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition
GlobalFunctions.php:903
Installer\getExistingLocalSettings
static getExistingLocalSettings()
Determine if LocalSettings.php exists.
Definition
Installer.php:663
Installer\getDBTypes
static getDBTypes()
Get a list of known DB types.
Definition
Installer.php:551
MediaWiki\Status\Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition
Status.php:58
WebInstallerExistingWiki
Definition
WebInstallerExistingWiki.php:25
WebInstallerExistingWiki\importVariables
importVariables( $names, $vars)
Definition
WebInstallerExistingWiki.php:124
WebInstallerExistingWiki\handleExistingUpgrade
handleExistingUpgrade( $vars)
Initiate an upgrade of the existing database.
Definition
WebInstallerExistingWiki.php:143
WebInstallerExistingWiki\showKeyForm
showKeyForm()
Show the "enter key" form.
Definition
WebInstallerExistingWiki.php:104
WebInstallerExistingWiki\execute
execute()
Definition
WebInstallerExistingWiki.php:30
WebInstallerPage
Abstract class to define pages for the web installer.
Definition
WebInstallerPage.php:32
WebInstallerPage\startForm
startForm()
Definition
WebInstallerPage.php:71
WebInstallerPage\setVar
setVar( $name, $value)
Definition
WebInstallerPage.php:162
WebInstallerPage\endForm
endForm( $continue='continue', $back='back')
Definition
WebInstallerPage.php:88
WebInstallerPage\addHTML
addHTML( $html)
Definition
WebInstallerPage.php:67
WebInstallerPage\getVar
getVar( $var, $default=null)
Definition
WebInstallerPage.php:154
includes
installer
WebInstallerExistingWiki.php
Generated on Wed Nov 27 2024 07:23:34 for MediaWiki by
1.10.0