3 * Core installer web interface.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
25 * Class for the core installer web interface.
30 class WebInstaller
extends Installer
{
33 * @var WebInstallerOutput
45 * Cached session array.
52 * Captured PHP error text. Temporary.
59 * The main sequence of page names. These will be displayed in turn.
61 * To add a new installer page:
62 * * Add it to this WebInstaller::$pageSequence property
63 * * Add a "config-page-<name>" message
64 * * Add a "WebInstaller<name>" class
68 public $pageSequence = [
82 * Out of sequence pages, selectable by the user at any time.
86 protected $otherPages = [
91 'UpgradeDoc', // Can't use Upgrade due to Upgrade step
95 * Array of pages which have declared that they have been submitted, have validated
96 * their input, and need no further processing.
100 protected $happyPages;
103 * List of "skipped" pages. These are pages that will automatically continue
104 * to the next page on any GET request. To avoid breaking the "back" button,
105 * they need to be skipped during a back operation.
109 protected $skippedPages;
112 * Flag indicating that session data may have been lost.
116 public $showSessionWarning = false;
119 * Numeric index of the page we're on
123 protected $tabIndex = 1;
126 * Name of the page we're on
130 protected $currentPageName;
133 * @param WebRequest $request
135 public function __construct( WebRequest
$request ) {
136 parent
::__construct();
137 $this->output
= new WebInstallerOutput( $this );
138 $this->request
= $request;
142 $wgParser->setHook( 'downloadlink', [ $this, 'downloadLinkHook' ] );
143 $wgParser->setHook( 'doclink', [ $this, 'docLink' ] );
149 * @param array[] $session Initial session array
151 * @return array[] New session array
153 public function execute( array $session ) {
154 $this->session
= $session;
156 if ( isset( $session['settings'] ) ) {
157 $this->settings
= $session['settings'] +
$this->settings
;
158 // T187586 MediaWikiServices works with globals
159 foreach ( $this->settings
as $key => $val ) {
160 $GLOBALS[$key] = $val;
164 $this->setupLanguage();
166 if ( ( $this->getVar( '_InstallDone' ) ||
$this->getVar( '_UpgradeDone' ) )
167 && $this->request
->getVal( 'localsettings' )
170 return $this->session
;
173 $isCSS = $this->request
->getVal( 'css' );
176 return $this->session
;
179 if ( isset( $session['happyPages'] ) ) {
180 $this->happyPages
= $session['happyPages'];
182 $this->happyPages
= [];
185 if ( isset( $session['skippedPages'] ) ) {
186 $this->skippedPages
= $session['skippedPages'];
188 $this->skippedPages
= [];
191 $lowestUnhappy = $this->getLowestUnhappy();
193 # Special case for Creative Commons partner chooser box.
194 if ( $this->request
->getVal( 'SubmitCC' ) ) {
195 $page = $this->getPageByName( 'Options' );
196 $this->output
->useShortHeader();
197 $this->output
->allowFrames();
200 return $this->finish();
203 if ( $this->request
->getVal( 'ShowCC' ) ) {
204 $page = $this->getPageByName( 'Options' );
205 $this->output
->useShortHeader();
206 $this->output
->allowFrames();
207 $this->output
->addHTML( $page->getCCDoneBox() );
209 return $this->finish();
213 $pageName = $this->request
->getVal( 'page' );
215 if ( in_array( $pageName, $this->otherPages
) ) {
218 $page = $this->getPageByName( $pageName );
221 if ( !$pageName ||
!in_array( $pageName, $this->pageSequence
) ) {
222 $pageId = $lowestUnhappy;
224 $pageId = array_search( $pageName, $this->pageSequence
);
227 # If necessary, move back to the lowest-numbered unhappy page
228 if ( $pageId > $lowestUnhappy ) {
229 $pageId = $lowestUnhappy;
230 if ( $lowestUnhappy == 0 ) {
231 # Knocked back to start, possible loss of session data.
232 $this->showSessionWarning
= true;
236 $pageName = $this->pageSequence
[$pageId];
237 $page = $this->getPageByName( $pageName );
240 # If a back button was submitted, go back without submitting the form data.
241 if ( $this->request
->wasPosted() && $this->request
->getBool( 'submit-back' ) ) {
242 if ( $this->request
->getVal( 'lastPage' ) ) {
243 $nextPage = $this->request
->getVal( 'lastPage' );
244 } elseif ( $pageId !== false ) {
246 # Skip the skipped pages
247 $nextPageId = $pageId;
251 $nextPage = $this->pageSequence
[$nextPageId];
252 } while ( isset( $this->skippedPages
[$nextPage] ) );
254 $nextPage = $this->pageSequence
[$lowestUnhappy];
257 $this->output
->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
259 return $this->finish();
263 $this->currentPageName
= $page->getName();
264 $this->startPageWrapper( $pageName );
266 if ( $page->isSlow() ) {
267 $this->disableTimeLimit();
270 $result = $page->execute();
272 $this->endPageWrapper();
274 if ( $result == 'skip' ) {
275 # Page skipped without explicit submission.
276 # Skip it when we click "back" so that we don't just go forward again.
277 $this->skippedPages
[$pageName] = true;
278 $result = 'continue';
280 unset( $this->skippedPages
[$pageName] );
283 # If it was posted, the page can request a continue to the next page.
284 if ( $result === 'continue' && !$this->output
->headerDone() ) {
285 if ( $pageId !== false ) {
286 $this->happyPages
[$pageId] = true;
289 $lowestUnhappy = $this->getLowestUnhappy();
291 if ( $this->request
->getVal( 'lastPage' ) ) {
292 $nextPage = $this->request
->getVal( 'lastPage' );
293 } elseif ( $pageId !== false ) {
294 $nextPage = $this->pageSequence
[$pageId +
1];
296 $nextPage = $this->pageSequence
[$lowestUnhappy];
299 if ( array_search( $nextPage, $this->pageSequence
) > $lowestUnhappy ) {
300 $nextPage = $this->pageSequence
[$lowestUnhappy];
303 $this->output
->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
306 return $this->finish();
310 * Find the next page in sequence that hasn't been completed
313 public function getLowestUnhappy() {
314 if ( count( $this->happyPages
) == 0 ) {
317 return max( array_keys( $this->happyPages
) ) +
1;
322 * Start the PHP session. This may be called before execute() to start the PHP session.
327 public function startSession() {
328 if ( wfIniGetBool( 'session.auto_start' ) ||
session_id() ) {
333 $this->phpErrors
= [];
334 set_error_handler( [ $this, 'errorHandler' ] );
336 session_name( 'mw_installer_session' );
338 } catch ( Exception
$e ) {
339 restore_error_handler();
342 restore_error_handler();
344 if ( $this->phpErrors
) {
352 * Get a hash of data identifying this MW installation.
354 * This is used by mw-config/index.php to prevent multiple installations of MW
355 * on the same cookie domain from interfering with each other.
359 public function getFingerprint() {
360 // Get the base URL of the installation
361 $url = $this->request
->getFullRequestURL();
362 if ( preg_match( '!^(.*\?)!', $url, $m ) ) {
366 if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
367 // This... seems to try to get the base path from
368 // the /mw-config/index.php. Kinda scary though?
372 return md5( serialize( [
373 'local path' => dirname( __DIR__
),
375 'version' => $GLOBALS['wgVersion']
380 * Show an error message in a box. Parameters are like wfMessage(), or
381 * alternatively, pass a Message object in.
382 * @param string|Message $msg
384 public function showError( $msg /*...*/ ) {
385 if ( !( $msg instanceof Message
) ) {
386 $args = func_get_args();
387 array_shift( $args );
388 $args = array_map( 'htmlspecialchars', $args );
389 $msg = wfMessage( $msg, $args );
391 $text = $msg->useDatabase( false )->plain();
392 $this->output
->addHTML( $this->getErrorBox( $text ) );
396 * Temporary error handler for session start debugging.
398 * @param int $errno Unused
399 * @param string $errstr
401 public function errorHandler( $errno, $errstr ) {
402 $this->phpErrors
[] = $errstr;
406 * Clean up from execute()
410 public function finish() {
411 $this->output
->output();
413 $this->session
['happyPages'] = $this->happyPages
;
414 $this->session
['skippedPages'] = $this->skippedPages
;
415 $this->session
['settings'] = $this->settings
;
417 return $this->session
;
421 * We're restarting the installation, reset the session, happyPages, etc
423 public function reset() {
425 $this->happyPages
= [];
426 $this->settings
= [];
430 * Get a URL for submission back to the same script.
432 * @param string[] $query
436 public function getUrl( $query = [] ) {
437 $url = $this->request
->getRequestURL();
438 # Remove existing query
439 $url = preg_replace( '/\?.*$/', '', $url );
442 $url .= '?' . wfArrayToCgi( $query );
449 * Get a WebInstallerPage by name.
451 * @param string $pageName
452 * @return WebInstallerPage
454 public function getPageByName( $pageName ) {
455 $pageClass = 'WebInstaller' . $pageName;
457 return new $pageClass( $this );
461 * Get a session variable.
463 * @param string $name
464 * @param array|null $default
468 public function getSession( $name, $default = null ) {
469 if ( !isset( $this->session
[$name] ) ) {
472 return $this->session
[$name];
477 * Set a session variable.
479 * @param string $name Key for the variable
480 * @param mixed $value
482 public function setSession( $name, $value ) {
483 $this->session
[$name] = $value;
487 * Get the next tabindex attribute value.
491 public function nextTabIndex() {
492 return $this->tabIndex++
;
496 * Initializes language-related variables.
498 public function setupLanguage() {
499 global $wgLang, $wgContLang, $wgLanguageCode;
501 if ( $this->getSession( 'test' ) === null && !$this->request
->wasPosted() ) {
502 $wgLanguageCode = $this->getAcceptLanguage();
503 $wgLang = $wgContLang = Language
::factory( $wgLanguageCode );
504 RequestContext
::getMain()->setLanguage( $wgLang );
505 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
506 $this->setVar( '_UserLang', $wgLanguageCode );
508 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
509 $wgContLang = Language
::factory( $wgLanguageCode );
514 * Retrieves MediaWiki language from Accept-Language HTTP header.
518 public function getAcceptLanguage() {
519 global $wgLanguageCode, $wgRequest;
521 $mwLanguages = Language
::fetchLanguageNames( null, 'mwfile' );
522 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
524 foreach ( $headerLanguages as $lang ) {
525 if ( isset( $mwLanguages[$lang] ) ) {
530 return $wgLanguageCode;
534 * Called by execute() before page output starts, to show a page list.
536 * @param string $currentPageName
538 private function startPageWrapper( $currentPageName ) {
539 $s = "<div class=\"config-page-wrapper\">\n";
540 $s .= "<div class=\"config-page\">\n";
541 $s .= "<div class=\"config-page-list\"><ul>\n";
544 foreach ( $this->pageSequence
as $id => $pageName ) {
545 $happy = !empty( $this->happyPages
[$id] );
546 $s .= $this->getPageListItem(
548 $happy ||
$lastHappy == $id - 1,
557 $s .= "</ul><br/><ul>\n";
558 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
560 $s .= "</ul></div>\n";
563 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
564 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
565 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
566 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
567 $s .= Html
::element( 'h2', [],
568 wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
570 $this->output
->addHTMLNoFlush( $s );
574 * Get a list item for the page list.
576 * @param string $pageName
577 * @param bool $enabled
578 * @param string $currentPageName
582 private function getPageListItem( $pageName, $enabled, $currentPageName ) {
583 $s = "<li class=\"config-page-list-item\">";
586 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
587 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
588 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
589 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
590 $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
593 $query = [ 'page' => $pageName ];
595 if ( !in_array( $pageName, $this->pageSequence
) ) {
596 if ( in_array( $currentPageName, $this->pageSequence
) ) {
597 $query['lastPage'] = $currentPageName;
600 $link = Html
::element( 'a',
602 'href' => $this->getUrl( $query )
607 $link = htmlspecialchars( $name );
610 if ( $pageName == $currentPageName ) {
611 $s .= "<span class=\"config-page-current\">$link</span>";
616 $s .= Html
::element( 'span',
618 'class' => 'config-page-disabled'
630 * Output some stuff after a page is finished.
632 private function endPageWrapper() {
633 $this->output
->addHTMLNoFlush(
634 "<div class=\"visualClear\"></div>\n" .
636 "<div class=\"visualClear\"></div>\n" .
641 * Get HTML for an error box with an icon.
643 * @param string $text Wikitext, get this with wfMessage()->plain()
647 public function getErrorBox( $text ) {
648 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
652 * Get HTML for a warning box with an icon.
654 * @param string $text Wikitext, get this with wfMessage()->plain()
658 public function getWarningBox( $text ) {
659 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
663 * Get HTML for an info box with an icon.
665 * @param string $text Wikitext, get this with wfMessage()->plain()
666 * @param string|bool $icon Icon name, file in mw-config/images. Default: false
667 * @param string|bool $class Additional class name to add to the wrapper div. Default: false.
671 public function getInfoBox( $text, $icon = false, $class = false ) {
672 $text = $this->parse( $text, true );
673 $icon = ( $icon == false ) ?
674 'images/info-32.png' :
676 $alt = wfMessage( 'config-information' )->text();
678 return Html
::infoBox( $text, $icon, $alt, $class );
682 * Get small text indented help for a preceding form field.
683 * Parameters like wfMessage().
688 public function getHelpBox( $msg /*, ... */ ) {
689 $args = func_get_args();
690 array_shift( $args );
691 $args = array_map( 'htmlspecialchars', $args );
692 $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
693 $html = $this->parse( $text, true );
695 return "<div class=\"config-help-field-container\">\n" .
696 "<span class=\"config-help-field-hint\" title=\"" .
697 wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
698 wfMessage( 'config-help' )->escaped() . "</span>\n" .
699 "<div class=\"config-help-field-data\">" . $html . "</div>\n" .
705 * @param string $msg Key for wfMessage()
707 public function showHelpBox( $msg /*, ... */ ) {
708 $args = func_get_args();
709 $html = $this->getHelpBox( ...$args );
710 $this->output
->addHTML( $html );
714 * Show a short informational message.
715 * Output looks like a list.
719 public function showMessage( $msg /*, ... */ ) {
720 $args = func_get_args();
721 array_shift( $args );
722 $html = '<div class="config-message">' .
723 $this->parse( wfMessage( $msg, $args )->useDatabase( false )->plain() ) .
725 $this->output
->addHTML( $html );
729 * @param Status $status
731 public function showStatusMessage( Status
$status ) {
732 $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
733 foreach ( $errors as $error ) {
734 $this->showMessage( ...$error );
739 * Label a control by wrapping a config-input div around it and putting a
743 * @param string $forId
744 * @param string $contents
745 * @param string $helpData
748 public function label( $msg, $forId, $contents, $helpData = "" ) {
749 if ( strval( $msg ) == '' ) {
750 $labelText = "\u{00A0}";
752 $labelText = wfMessage( $msg )->escaped();
755 $attributes = [ 'class' => 'config-label' ];
758 $attributes['for'] = $forId;
761 return "<div class=\"config-block\">\n" .
762 " <div class=\"config-block-label\">\n" .
769 " <div class=\"config-block-elements\">\n" .
776 * Get a labelled text box to configure a variable.
778 * @param mixed[] $params
780 * var: The variable to be configured (required)
781 * label: The message name for the label (required)
782 * attribs: Additional attributes for the input element (optional)
783 * controlName: The name for the input element (optional)
784 * value: The current value of the variable (optional)
785 * help: The html for the help text (optional)
789 public function getTextBox( $params ) {
790 if ( !isset( $params['controlName'] ) ) {
791 $params['controlName'] = 'config_' . $params['var'];
794 if ( !isset( $params['value'] ) ) {
795 $params['value'] = $this->getVar( $params['var'] );
798 if ( !isset( $params['attribs'] ) ) {
799 $params['attribs'] = [];
801 if ( !isset( $params['help'] ) ) {
802 $params['help'] = "";
807 $params['controlName'],
809 $params['controlName'],
810 30, // intended to be overridden by CSS
812 $params['attribs'] +
[
813 'id' => $params['controlName'],
814 'class' => 'config-input-text',
815 'tabindex' => $this->nextTabIndex()
823 * Get a labelled textarea to configure a variable
825 * @param mixed[] $params
827 * var: The variable to be configured (required)
828 * label: The message name for the label (required)
829 * attribs: Additional attributes for the input element (optional)
830 * controlName: The name for the input element (optional)
831 * value: The current value of the variable (optional)
832 * help: The html for the help text (optional)
836 public function getTextArea( $params ) {
837 if ( !isset( $params['controlName'] ) ) {
838 $params['controlName'] = 'config_' . $params['var'];
841 if ( !isset( $params['value'] ) ) {
842 $params['value'] = $this->getVar( $params['var'] );
845 if ( !isset( $params['attribs'] ) ) {
846 $params['attribs'] = [];
848 if ( !isset( $params['help'] ) ) {
849 $params['help'] = "";
854 $params['controlName'],
856 $params['controlName'],
860 $params['attribs'] +
[
861 'id' => $params['controlName'],
862 'class' => 'config-input-text',
863 'tabindex' => $this->nextTabIndex()
871 * Get a labelled password box to configure a variable.
873 * Implements password hiding
874 * @param mixed[] $params
876 * var: The variable to be configured (required)
877 * label: The message name for the label (required)
878 * attribs: Additional attributes for the input element (optional)
879 * controlName: The name for the input element (optional)
880 * value: The current value of the variable (optional)
881 * help: The html for the help text (optional)
885 public function getPasswordBox( $params ) {
886 if ( !isset( $params['value'] ) ) {
887 $params['value'] = $this->getVar( $params['var'] );
890 if ( !isset( $params['attribs'] ) ) {
891 $params['attribs'] = [];
894 $params['value'] = $this->getFakePassword( $params['value'] );
895 $params['attribs']['type'] = 'password';
897 return $this->getTextBox( $params );
901 * Get a labelled checkbox to configure a boolean variable.
903 * @param mixed[] $params
905 * var: The variable to be configured (required)
906 * label: The message name for the label (required)
907 * labelAttribs:Additional attributes for the label element (optional)
908 * attribs: Additional attributes for the input element (optional)
909 * controlName: The name for the input element (optional)
910 * value: The current value of the variable (optional)
911 * help: The html for the help text (optional)
915 public function getCheckBox( $params ) {
916 if ( !isset( $params['controlName'] ) ) {
917 $params['controlName'] = 'config_' . $params['var'];
920 if ( !isset( $params['value'] ) ) {
921 $params['value'] = $this->getVar( $params['var'] );
924 if ( !isset( $params['attribs'] ) ) {
925 $params['attribs'] = [];
927 if ( !isset( $params['help'] ) ) {
928 $params['help'] = "";
930 if ( !isset( $params['labelAttribs'] ) ) {
931 $params['labelAttribs'] = [];
933 if ( isset( $params['rawtext'] ) ) {
934 $labelText = $params['rawtext'];
936 $labelText = $this->parse( wfMessage( $params['label'] )->text() );
939 return "<div class=\"config-input-check\">\n" .
943 $params['labelAttribs'],
945 $params['controlName'],
947 $params['attribs'] +
[
948 'id' => $params['controlName'],
949 'tabindex' => $this->nextTabIndex(),
958 * Get a set of labelled radio buttons.
960 * @param mixed[] $params
962 * var: The variable to be configured (required)
963 * label: The message name for the label (required)
964 * itemLabelPrefix: The message name prefix for the item labels (required)
965 * itemLabels: List of message names to use for the item labels instead
966 * of itemLabelPrefix, keyed by values
967 * values: List of allowed values (required)
968 * itemAttribs: Array of attribute arrays, outer key is the value name (optional)
969 * commonAttribs: Attribute array applied to all items
970 * controlName: The name for the input element (optional)
971 * value: The current value of the variable (optional)
972 * help: The html for the help text (optional)
976 public function getRadioSet( $params ) {
977 $items = $this->getRadioElements( $params );
979 if ( !isset( $params['label'] ) ) {
982 $label = $params['label'];
985 if ( !isset( $params['controlName'] ) ) {
986 $params['controlName'] = 'config_' . $params['var'];
989 if ( !isset( $params['help'] ) ) {
990 $params['help'] = "";
994 foreach ( $items as $value => $item ) {
995 $s .= "<li>$item</li>\n";
999 return $this->label( $label, $params['controlName'], $s, $params['help'] );
1003 * Get a set of labelled radio buttons. You probably want to use getRadioSet(), not this.
1007 * @param mixed[] $params
1010 public function getRadioElements( $params ) {
1011 if ( !isset( $params['controlName'] ) ) {
1012 $params['controlName'] = 'config_' . $params['var'];
1015 if ( !isset( $params['value'] ) ) {
1016 $params['value'] = $this->getVar( $params['var'] );
1021 foreach ( $params['values'] as $value ) {
1024 if ( isset( $params['commonAttribs'] ) ) {
1025 $itemAttribs = $params['commonAttribs'];
1028 if ( isset( $params['itemAttribs'][$value] ) ) {
1029 $itemAttribs = $params['itemAttribs'][$value] +
$itemAttribs;
1032 $checked = $value == $params['value'];
1033 $id = $params['controlName'] . '_' . $value;
1034 $itemAttribs['id'] = $id;
1035 $itemAttribs['tabindex'] = $this->nextTabIndex();
1038 Xml
::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
1040 Xml
::tags( 'label', [ 'for' => $id ], $this->parse(
1041 isset( $params['itemLabels'] ) ?
1042 wfMessage( $params['itemLabels'][$value] )->plain() :
1043 wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
1051 * Output an error or warning box using a Status object.
1053 * @param Status $status
1055 public function showStatusBox( $status ) {
1056 if ( !$status->isGood() ) {
1057 $text = $status->getWikiText();
1059 if ( $status->isOK() ) {
1060 $box = $this->getWarningBox( $text );
1062 $box = $this->getErrorBox( $text );
1065 $this->output
->addHTML( $box );
1070 * Convenience function to set variables based on form data.
1071 * Assumes that variables containing "password" in the name are (potentially
1074 * @param string[] $varNames
1075 * @param string $prefix The prefix added to variables to obtain form names
1079 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
1082 foreach ( $varNames as $name ) {
1083 $value = $this->request
->getVal( $prefix . $name );
1084 // T32524, do not trim passwords
1085 if ( stripos( $name, 'password' ) === false ) {
1086 $value = trim( $value );
1088 $newValues[$name] = $value;
1090 if ( $value === null ) {
1092 $this->setVar( $name, false );
1094 if ( stripos( $name, 'password' ) !== false ) {
1095 $this->setPassword( $name, $value );
1097 $this->setVar( $name, $value );
1106 * Helper for Installer::docLink()
1108 * @param string $page
1112 protected function getDocUrl( $page ) {
1113 $query = [ 'page' => $page ];
1115 if ( in_array( $this->currentPageName
, $this->pageSequence
) ) {
1116 $query['lastPage'] = $this->currentPageName
;
1119 return $this->getUrl( $query );
1123 * Extension tag hook for a documentation link.
1125 * @param string $linkText
1126 * @param string[] $attribs
1127 * @param Parser $parser Unused
1131 public function docLink( $linkText, $attribs, $parser ) {
1132 $url = $this->getDocUrl( $attribs['href'] );
1134 return Html
::element( 'a', [ 'href' => $url ], $linkText );
1138 * Helper for "Download LocalSettings" link on WebInstall_Complete
1140 * @param string $text Unused
1141 * @param string[] $attribs Unused
1142 * @param Parser $parser Unused
1144 * @return string Html for download link
1146 public function downloadLinkHook( $text, $attribs, $parser ) {
1147 $anchor = Html
::rawElement( 'a',
1148 [ 'href' => $this->getUrl( [ 'localsettings' => 1 ] ) ],
1149 wfMessage( 'config-download-localsettings' )->parse()
1152 return Html
::rawElement( 'div', [ 'class' => 'config-download-link' ], $anchor );
1156 * If the software package wants the LocalSettings.php file
1157 * to be placed in a specific location, override this function
1158 * (see mw-config/overrides/README) to return the path of
1159 * where the file should be saved, or false for a generic
1160 * "in the base of your install"
1163 * @return string|bool
1165 public function getLocalSettingsLocation() {
1172 public function envCheckPath() {
1173 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1174 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1175 // to get the path to the current script... hopefully it's reliable. SIGH
1177 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1178 $path = $_SERVER['PHP_SELF'];
1179 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1180 $path = $_SERVER['SCRIPT_NAME'];
1182 if ( $path === false ) {
1183 $this->showError( 'config-no-uri' );
1187 return parent
::envCheckPath();
1190 public function envPrepPath() {
1191 parent
::envPrepPath();
1192 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1193 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1194 // to get the path to the current script... hopefully it's reliable. SIGH
1196 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1197 $path = $_SERVER['PHP_SELF'];
1198 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1199 $path = $_SERVER['SCRIPT_NAME'];
1201 if ( $path !== false ) {
1202 $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
1204 $this->setVar( 'wgScriptPath', "$scriptPath" );
1205 // Update variables set from Setup.php that are derived from wgScriptPath
1206 $this->setVar( 'wgScript', "$scriptPath/index.php" );
1207 $this->setVar( 'wgLoadScript', "$scriptPath/load.php" );
1208 $this->setVar( 'wgStylePath', "$scriptPath/skins" );
1209 $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
1210 $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
1211 $this->setVar( 'wgUploadPath', "$scriptPath/images" );
1212 $this->setVar( 'wgResourceBasePath', "$scriptPath" );
1219 protected function envGetDefaultServer() {
1220 return WebRequest
::detectServer();
1224 * Actually output LocalSettings.php for download
1226 * @suppress SecurityCheck-XSS
1228 private function outputLS() {
1229 $this->request
->response()->header( 'Content-type: application/x-httpd-php' );
1230 $this->request
->response()->header(
1231 'Content-Disposition: attachment; filename="LocalSettings.php"'
1234 $ls = InstallerOverrides
::getLocalSettingsGenerator( $this );
1235 $rightsProfile = $this->rightsProfiles
[$this->getVar( '_RightsProfile' )];
1236 foreach ( $rightsProfile as $group => $rightsArr ) {
1237 $ls->setGroupRights( $group, $rightsArr );
1239 echo $ls->getText();
1243 * Output stylesheet for web installer pages
1245 public function outputCss() {
1246 $this->request
->response()->header( 'Content-type: text/css' );
1247 echo $this->output
->getCSS();
1253 public function getPhpErrors() {
1254 return $this->phpErrors
;