146 parent::__construct();
161 if ( isset(
$session[
'settings'] ) ) {
164 foreach ( $this->settings as $key => $val ) {
165 $GLOBALS[$key] = $val;
171 if ( ( $this->
getVar(
'_InstallDone' ) || $this->
getVar(
'_UpgradeDone' ) )
172 && $this->request->getVal(
'localsettings' )
178 $isCSS = $this->request->getVal(
'css' );
184 $this->happyPages =
$session[
'happyPages'] ?? [];
186 $this->skippedPages =
$session[
'skippedPages'] ?? [];
190 # Special case for Creative Commons partner chooser box.
191 if ( $this->request->getVal(
'SubmitCC' ) ) {
194 '@phan-var WebInstallerOptions $page';
195 $this->output->useShortHeader();
196 $this->output->allowFrames();
202 if ( $this->request->getVal(
'ShowCC' ) ) {
205 '@phan-var WebInstallerOptions $page';
206 $this->output->useShortHeader();
207 $this->output->allowFrames();
208 $this->output->addHTML( $page->getCCDoneBox() );
214 $pageName = $this->request->getVal(
'page',
'' );
216 if ( in_array( $pageName, $this->otherPages ) ) {
222 if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) {
223 $pageId = $lowestUnhappy;
225 $pageId = array_search( $pageName, $this->pageSequence );
228 # If necessary, move back to the lowest-numbered unhappy page
229 if ( $pageId > $lowestUnhappy ) {
230 $pageId = $lowestUnhappy;
231 if ( $lowestUnhappy == 0 ) {
232 # Knocked back to start, possible loss of session data.
233 $this->showSessionWarning =
true;
237 $pageName = $this->pageSequence[$pageId];
241 # If a back button was submitted, go back without submitting the form data.
242 if ( $this->request->wasPosted() && $this->request->getBool(
'submit-back' ) ) {
243 if ( $this->request->getVal(
'lastPage' ) ) {
244 $nextPage = $this->request->getVal(
'lastPage' );
245 } elseif ( $pageId !==
false ) {
247 # Skip the skipped pages
248 $nextPageId = $pageId;
252 $nextPage = $this->pageSequence[$nextPageId];
253 }
while ( isset( $this->skippedPages[$nextPage] ) );
255 $nextPage = $this->pageSequence[$lowestUnhappy];
258 $this->output->redirect( $this->
getUrl( [
'page' => $nextPage ] ) );
264 $this->currentPageName = $page->getName();
265 $this->startPageWrapper( $pageName );
267 if ( $page->isSlow() ) {
271 $result = $page->execute();
273 $this->endPageWrapper();
275 if ( $result ==
'skip' ) {
276 # Page skipped without explicit submission.
277 # Skip it when we click "back" so that we don't just go forward again.
278 $this->skippedPages[$pageName] =
true;
279 $result =
'continue';
281 unset( $this->skippedPages[$pageName] );
284 # If it was posted, the page can request a continue to the next page.
285 if ( $result ===
'continue' && !$this->output->headerDone() ) {
286 if ( $pageId !==
false ) {
287 $this->happyPages[$pageId] =
true;
292 if ( $this->request->getVal(
'lastPage' ) ) {
293 $nextPage = $this->request->getVal(
'lastPage' );
294 } elseif ( $pageId !==
false ) {
295 $nextPage = $this->pageSequence[$pageId + 1];
297 $nextPage = $this->pageSequence[$lowestUnhappy];
300 if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) {
301 $nextPage = $this->pageSequence[$lowestUnhappy];
304 $this->output->redirect( $this->
getUrl( [
'page' => $nextPage ] ) );
315 if ( count( $this->happyPages ) == 0 ) {
318 return max( array_keys( $this->happyPages ) ) + 1;
329 if (
wfIniGetBool(
'session.auto_start' ) || session_id() ) {
336 if ( $this->request->getProtocol() ===
'https' ) {
337 $options[
'cookie_secure'] =
'1';
340 $this->phpErrors = [];
341 set_error_handler( [ $this,
'errorHandler' ] );
343 session_name(
'mw_installer_session' );
344 session_start( $options );
345 }
catch ( Exception $e ) {
346 restore_error_handler();
349 restore_error_handler();
351 if ( $this->phpErrors ) {
368 $url = $this->request->getFullRequestURL();
369 if ( preg_match(
'!^(.*\?)!', $url, $m ) ) {
373 if ( preg_match(
'!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
379 return md5( serialize( [
380 'local path' => dirname( __DIR__ ),
393 if ( !( $msg instanceof
Message ) ) {
396 array_map(
'htmlspecialchars', $params )
399 $text = $msg->useDatabase(
false )->parse();
400 $box = Html::errorBox( $text,
'',
'config-error-box' );
401 $this->output->addHTML( $box );
411 $this->phpErrors[] = $errstr;
420 $this->output->output();
434 $this->happyPages = [];
435 $this->settings = [];
446 $url = $this->request->getRequestURL();
447 # Remove existing query
448 $url = preg_replace(
'/\?.*$/',
'', $url );
464 $pageClass =
'WebInstaller' . $pageName;
466 return new $pageClass( $this );
478 return $this->session[$name] ?? $default;
488 $this->session[$name] = $value;
497 return $this->tabIndex++;
506 if ( $this->
getSession(
'test' ) ===
null && !$this->request->wasPosted() ) {
508 $wgLang = MediaWikiServices::getInstance()->getLanguageFactory()
510 RequestContext::getMain()->setLanguage(
$wgLang );
511 $this->
setVar(
'wgLanguageCode', $wgLanguageCode );
512 $this->
setVar(
'_UserLang', $wgLanguageCode );
527 $mwLanguages = MediaWikiServices::getInstance()
528 ->getLanguageNameUtils()
529 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED );
530 $headerLanguages = array_keys(
$wgRequest->getAcceptLang() );
532 foreach ( $headerLanguages as
$lang ) {
533 if ( isset( $mwLanguages[
$lang] ) ) {
547 $s =
"<div class=\"config-page-wrapper\">\n";
548 $s .=
"<div class=\"config-page\">\n";
549 $s .=
"<div class=\"config-page-list\"><ul>\n";
552 foreach ( $this->pageSequence as $id => $pageName ) {
553 $happy = !empty( $this->happyPages[$id] );
554 $s .= $this->getPageListItem(
556 $happy || $lastHappy == $id - 1,
565 $s .=
"</ul><br/><ul>\n";
568 $s .=
"</ul></div>\n";
575 $s .= Html::element(
'h2', [],
578 $this->output->addHTMLNoFlush( $s );
591 $s =
"<li class=\"config-page-list-item\">";
598 $name =
wfMessage(
'config-page-' . strtolower( $pageName ) )->text();
601 $query = [
'page' => $pageName ];
603 if ( !in_array( $pageName, $this->pageSequence ) ) {
608 $link = Html::element(
'a',
610 'href' => $this->
getUrl( $query )
615 $link = htmlspecialchars( $name );
619 $s .=
"<span class=\"config-page-current\">$link</span>";
624 $s .= Html::element(
'span',
626 'class' =>
'config-page-disabled'
640 private function endPageWrapper() {
641 $this->output->addHTMLNoFlush(
642 "<div class=\"visualClear\"></div>\n" .
644 "<div class=\"visualClear\"></div>\n" .
656 public function getInfoBox( $text, $icon =
false, $class =
'' ) {
658 HtmlArmor::getHtml( $text ) :
659 $this->
parse( $text,
true );
661 'images/info-32.png' :
663 $alt =
wfMessage(
'config-information' )->text();
678 $args = array_map(
'htmlspecialchars', $args );
679 $text =
wfMessage( $msg, $args )->useDatabase(
false )->plain();
680 $html = $this->
parse( $text,
true );
681 $id =
'helpBox-' . $this->helpBoxId++;
683 return "<div class=\"config-help-field-container\">\n" .
684 "<input type=\"checkbox\" class=\"config-help-field-checkbox\" id=\"$id\" />" .
685 "<label class=\"config-help-field-hint\" for=\"$id\" title=\"" .
686 wfMessage(
'config-help-tooltip' )->escaped() .
"\">" .
687 wfMessage(
'config-help' )->escaped() .
"</label>\n" .
688 "<div class=\"config-help-field-data\">" . $html .
"</div>\n" .
698 $html = $this->
getHelpBox( $msg, ...$params );
699 $this->output->addHTML( $html );
710 $html =
'<div class="config-message">' .
711 $this->
parse(
wfMessage( $msg, $params )->useDatabase(
false )->plain() ) .
713 $this->output->addHTML( $html );
721 foreach ( $errors as $error ) {
737 public function label( $msg, $forId, $contents, $helpData =
"" ) {
738 if ( strval( $msg ) ==
'' ) {
739 $labelText =
"\u{00A0}";
741 $labelText =
wfMessage( $msg )->escaped();
744 $attributes = [
'class' =>
'config-label' ];
747 $attributes[
'for'] = $forId;
750 return "<div class=\"config-block\">\n" .
751 " <div class=\"config-block-label\">\n" .
758 " <div class=\"config-block-elements\">\n" .
780 if ( !isset( $params[
'controlName'] ) ) {
781 $params[
'controlName'] =
'config_' . $params[
'var'];
784 if ( !isset( $params[
'value'] ) ) {
785 $params[
'value'] = $this->
getVar( $params[
'var'] );
788 if ( !isset( $params[
'attribs'] ) ) {
789 $params[
'attribs'] = [];
791 if ( !isset( $params[
'help'] ) ) {
792 $params[
'help'] =
"";
797 $params[
'controlName'],
799 $params[
'controlName'],
802 $params[
'attribs'] + [
803 'id' => $params[
'controlName'],
804 'class' =>
'config-input-text',
827 if ( !isset( $params[
'controlName'] ) ) {
828 $params[
'controlName'] =
'config_' . $params[
'var'];
831 if ( !isset( $params[
'value'] ) ) {
832 $params[
'value'] = $this->
getVar( $params[
'var'] );
835 if ( !isset( $params[
'attribs'] ) ) {
836 $params[
'attribs'] = [];
838 if ( !isset( $params[
'help'] ) ) {
839 $params[
'help'] =
"";
844 $params[
'controlName'],
846 $params[
'controlName'],
850 $params[
'attribs'] + [
851 'id' => $params[
'controlName'],
852 'class' =>
'config-input-text',
877 if ( !isset( $params[
'value'] ) ) {
878 $params[
'value'] = $this->
getVar( $params[
'var'] );
881 if ( !isset( $params[
'attribs'] ) ) {
882 $params[
'attribs'] = [];
886 $params[
'attribs'][
'type'] =
'password';
908 if ( !isset( $params[
'controlName'] ) ) {
909 $params[
'controlName'] =
'config_' . $params[
'var'];
912 if ( !isset( $params[
'value'] ) ) {
913 $params[
'value'] = $this->
getVar( $params[
'var'] );
916 if ( !isset( $params[
'attribs'] ) ) {
917 $params[
'attribs'] = [];
919 if ( !isset( $params[
'help'] ) ) {
920 $params[
'help'] =
"";
922 if ( !isset( $params[
'labelAttribs'] ) ) {
923 $params[
'labelAttribs'] = [];
925 $labelText = $params[
'rawtext'] ?? $this->
parse(
wfMessage( $params[
'label'] )->plain() );
927 return "<div class=\"config-input-check\">\n" .
931 $params[
'labelAttribs'],
933 $params[
'controlName'],
935 $params[
'attribs'] + [
936 'id' => $params[
'controlName'],
968 $label = $params[
'label'] ??
'';
970 if ( !isset( $params[
'controlName'] ) ) {
971 $params[
'controlName'] =
'config_' . $params[
'var'];
974 if ( !isset( $params[
'help'] ) ) {
975 $params[
'help'] =
"";
979 foreach ( $items as $item ) {
980 $s .=
"<li>$item</li>\n";
984 return $this->
label( $label, $params[
'controlName'], $s, $params[
'help'] );
997 if ( !isset( $params[
'controlName'] ) ) {
998 $params[
'controlName'] =
'config_' . $params[
'var'];
1001 if ( !isset( $params[
'value'] ) ) {
1002 $params[
'value'] = $this->
getVar( $params[
'var'] );
1007 foreach ( $params[
'values'] as $value ) {
1010 if ( isset( $params[
'commonAttribs'] ) ) {
1011 $itemAttribs = $params[
'commonAttribs'];
1014 if ( isset( $params[
'itemAttribs'][$value] ) ) {
1015 $itemAttribs = $params[
'itemAttribs'][$value] + $itemAttribs;
1018 $checked = $value == $params[
'value'];
1019 $id = $params[
'controlName'] .
'_' . $value;
1020 $itemAttribs[
'id'] = $id;
1024 Xml::radio( $params[
'controlName'], $value, $checked, $itemAttribs ) .
1026 Xml::tags(
'label', [
'for' => $id ], $this->
parse(
1027 isset( $params[
'itemLabels'] ) ?
1028 wfMessage( $params[
'itemLabels'][$value] )->plain() :
1029 wfMessage( $params[
'itemLabelPrefix'] . strtolower( $value ) )->plain()
1042 if ( !$status->isGood() ) {
1043 $html = $status->getHTML();
1045 if ( $status->isOK() ) {
1046 $box = Html::warningBox( $html,
'config-warning-box' );
1048 $box = Html::errorBox( $html,
'',
'config-error-box' );
1051 $this->output->addHTML( $box );
1068 foreach ( $varNames as $name ) {
1069 $value = $this->request->getVal( $prefix . $name );
1071 if ( $value !==
null && stripos( $name,
'password' ) ===
false ) {
1072 $value = trim( $value );
1074 $newValues[$name] = $value;
1076 if ( $value ===
null ) {
1078 $this->
setVar( $name,
false );
1079 } elseif ( stripos( $name,
'password' ) !==
false ) {
1082 $this->
setVar( $name, $value );
1097 $query = [
'page' => $page ];
1099 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
1103 return $this->
getUrl( $query );
1115 return Html::rawElement(
'li', [],
1116 Html::element(
'a', [
'href' => $url ], $linkText )
1127 $anchor = Html::rawElement(
'a',
1128 [
'href' => $this->
getUrl( [
'localsettings' => 1 ] ) ],
1132 return Html::rawElement(
'div', [
'class' =>
'config-download-link' ], $anchor );
1157 if ( !empty( $_SERVER[
'PHP_SELF'] ) ) {
1158 $path = $_SERVER[
'PHP_SELF'];
1159 } elseif ( !empty( $_SERVER[
'SCRIPT_NAME'] ) ) {
1160 $path = $_SERVER[
'SCRIPT_NAME'];
1162 if (
$path ===
false ) {
1167 return parent::envCheckPath();
1171 parent::envPrepPath();
1176 if ( !empty( $_SERVER[
'PHP_SELF'] ) ) {
1177 $path = $_SERVER[
'PHP_SELF'];
1178 } elseif ( !empty( $_SERVER[
'SCRIPT_NAME'] ) ) {
1179 $path = $_SERVER[
'SCRIPT_NAME'];
1181 if (
$path !==
false ) {
1182 $scriptPath = preg_replace(
'{^(.*)/(mw-)?config.*$}',
'$1',
$path );
1184 $this->
setVar(
'wgScriptPath',
"$scriptPath" );
1186 $this->
setVar(
'wgScript',
"$scriptPath/index.php" );
1187 $this->
setVar(
'wgLoadScript',
"$scriptPath/load.php" );
1188 $this->
setVar(
'wgStylePath',
"$scriptPath/skins" );
1189 $this->
setVar(
'wgLocalStylePath',
"$scriptPath/skins" );
1190 $this->
setVar(
'wgExtensionAssetsPath',
"$scriptPath/extensions" );
1191 $this->
setVar(
'wgUploadPath',
"$scriptPath/images" );
1192 $this->
setVar(
'wgResourceBasePath',
"$scriptPath" );
1200 $assumeProxiesUseDefaultProtocolPorts =
1201 $this->
getVar(
'wgAssumeProxiesUseDefaultProtocolPorts' );
1203 return WebRequest::detectServer( $assumeProxiesUseDefaultProtocolPorts );
1209 private function outputLS() {
1210 $this->request->response()->header(
'Content-type: application/x-httpd-php' );
1211 $this->request->response()->header(
1212 'Content-Disposition: attachment; filename="LocalSettings.php"'
1216 $rightsProfile = $this->rightsProfiles[$this->
getVar(
'_RightsProfile' )];
1217 foreach ( $rightsProfile as $group => $rightsArr ) {
1218 $ls->setGroupRights( $group, $rightsArr );
1220 echo $ls->getText();
1227 $this->request->response()->header(
'Content-type: text/css' );
1228 echo $this->output->getCSS();
1248 protected static function infoBox( $rawHtml, $icon, $alt, $class =
'' ) {
1249 $s = Html::openElement(
'div', [
'class' =>
'mw-installer-box-left' ] ) .
1250 Html::element(
'img',
1256 Html::closeElement(
'div' ) .
1257 Html::openElement(
'div', [
'class' =>
'mw-installer-box-right' ] ) .
1259 Html::closeElement(
'div' ) .
1260 Html::element(
'div', [
'style' =>
'clear: left;' ],
' ' );
1262 return Html::warningBox( $s, $class )
1263 . Html::element(
'div', [
'style' =>
'clear: left;' ],
' ' );
const MW_VERSION
The running version of MediaWiki.
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode $wgLang
Marks HTML that shouldn't be escaped.
static getLocalSettingsGenerator(Installer $installer)
Instantiates and returns an instance of LocalSettingsGenerator or its descendant classes.
parse( $text, $lineStart=false)
Convert wikitext $text to HTML.
setVar( $name, $value)
Set a MW configuration variable, or internal installer configuration variable.
getFakePassword( $realPassword)
Get a fake password for sending back to the user in HTML.
disableTimeLimit()
Disable the time limit for execution.
setPassword( $name, $value)
Set a variable which stores a password, except if the new value is a fake password in which case leav...
getVar( $name, $default=null)
Get an MW configuration variable, or internal installer configuration variable.
The Message class deals with fetching and processing of interface message into a variety of formats.
Generic operation result class Has warning/error list, boolean status and arbitrary value.
getErrorsArray()
Get the list of errors (but not warnings)
getWarningsArray()
Get the list of warnings (but not errors)
Output class modelled on OutputPage.
Class for the core installer web interface.
makeDownloadLinkHtml()
Helper for "Download LocalSettings" link.
setupLanguage()
Initializes language-related variables.
WebInstallerOutput $output
finish()
Clean up from execute()
getTextBox( $params)
Get a labelled text box to configure a variable.
getAcceptLanguage()
Retrieves MediaWiki language from Accept-Language HTTP header.
nextTabIndex()
Get the next tabindex attribute value.
showStatusBox( $status)
Output an error or warning box using a Status object.
setVarsFromRequest( $varNames, $prefix='config_')
Convenience function to set variables based on form data.
getPageByName( $pageName)
Get a WebInstallerPage by name.
errorHandler( $errno, $errstr)
Temporary error handler for session start debugging.
bool[] $happyPages
Array of pages which have declared that they have been submitted, have validated their input,...
getSession( $name, $default=null)
Get a session variable.
outputCss()
Output stylesheet for web installer pages.
getLowestUnhappy()
Find the next page in sequence that hasn't been completed.
showHelpBox( $msg,... $params)
Output a help box.
label( $msg, $forId, $contents, $helpData="")
Label a control by wrapping a config-input div around it and putting a label before it.
execute(array $session)
Main entry point.
getLocalSettingsLocation()
If the software package wants the LocalSettings.php file to be placed in a specific location,...
getDocUrl( $page)
Helper for WebInstallerOutput.
bool[] $skippedPages
List of "skipped" pages.
getRadioElements( $params)
Get a set of labelled radio buttons.
showMessage( $msg,... $params)
Show a short informational message.
showError( $msg,... $params)
Show an error message in a box.
setSession( $name, $value)
Set a session variable.
reset()
We're restarting the installation, reset the session, happyPages, etc.
string $currentPageName
Name of the page we're on.
getHelpBox( $msg,... $args)
Get small text indented help for a preceding form field.
getRadioSet( $params)
Get a set of labelled radio buttons.
getPasswordBox( $params)
Get a labelled password box to configure a variable.
getInfoBox( $text, $icon=false, $class='')
Get HTML for an information message box with an icon.
WebRequest $request
WebRequest object.
__construct(WebRequest $request)
getTextArea( $params)
Get a labelled textarea to configure a variable.
getFingerprint()
Get a hash of data identifying this MW installation.
string[] $otherPages
Out of sequence pages, selectable by the user at any time.
string[] $pageSequence
The main sequence of page names.
string[] $phpErrors
Captured PHP error text.
static infoBox( $rawHtml, $icon, $alt, $class='')
Get HTML for an information message box with an icon.
bool $showSessionWarning
Flag indicating that session data may have been lost.
showStatusMessage(Status $status)
getCheckBox( $params)
Get a labelled checkbox to configure a boolean variable.
makeLinkItem( $url, $linkText)
Helper for sidebar links.
startSession()
Start the PHP session.
int $tabIndex
Numeric index of the page we're on.
array[] $session
Cached session array.
getUrl( $query=[])
Get a URL for submission back to the same script.
envPrepPath()
Environment prep for setting $IP and $wgScriptPath.
int $helpBoxId
Numeric index of the help box.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
$wgLanguageCode
Config variable stub for the LanguageCode setting, for use by phpdoc and IDEs.
if(!isset( $args[0])) $lang