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
24 use MediaWiki\MediaWikiServices
;
27 * Class for the core installer web interface.
32 class WebInstaller
extends Installer
{
35 * @var WebInstallerOutput
47 * Cached session array.
54 * Captured PHP error text. Temporary.
61 * The main sequence of page names. These will be displayed in turn.
63 * To add a new installer page:
64 * * Add it to this WebInstaller::$pageSequence property
65 * * Add a "config-page-<name>" message
66 * * Add a "WebInstaller<name>" class
70 public $pageSequence = [
84 * Out of sequence pages, selectable by the user at any time.
88 protected $otherPages = [
93 'UpgradeDoc', // Can't use Upgrade due to Upgrade step
97 * Array of pages which have declared that they have been submitted, have validated
98 * their input, and need no further processing.
102 protected $happyPages;
105 * List of "skipped" pages. These are pages that will automatically continue
106 * to the next page on any GET request. To avoid breaking the "back" button,
107 * they need to be skipped during a back operation.
111 protected $skippedPages;
114 * Flag indicating that session data may have been lost.
118 public $showSessionWarning = false;
121 * Numeric index of the page we're on
125 protected $tabIndex = 1;
128 * Numeric index of the help box
132 protected $helpBoxId = 1;
135 * Name of the page we're on
139 protected $currentPageName;
142 * @param WebRequest $request
144 public function __construct( WebRequest
$request ) {
145 parent
::__construct();
146 $this->output
= new WebInstallerOutput( $this );
147 $this->request
= $request;
153 * @param array[] $session Initial session array
155 * @return array[] New session array
157 public function execute( array $session ) {
158 $this->session
= $session;
160 if ( isset( $session['settings'] ) ) {
161 $this->settings
= $session['settings'] +
$this->settings
;
162 // T187586 MediaWikiServices works with globals
163 foreach ( $this->settings
as $key => $val ) {
164 $GLOBALS[$key] = $val;
168 $this->setupLanguage();
170 if ( ( $this->getVar( '_InstallDone' ) ||
$this->getVar( '_UpgradeDone' ) )
171 && $this->request
->getVal( 'localsettings' )
174 return $this->session
;
177 $isCSS = $this->request
->getVal( 'css' );
180 return $this->session
;
183 $this->happyPages
= $session['happyPages'] ??
[];
185 $this->skippedPages
= $session['skippedPages'] ??
[];
187 $lowestUnhappy = $this->getLowestUnhappy();
189 # Special case for Creative Commons partner chooser box.
190 if ( $this->request
->getVal( 'SubmitCC' ) ) {
191 $page = $this->getPageByName( 'Options' );
192 $this->output
->useShortHeader();
193 $this->output
->allowFrames();
196 return $this->finish();
199 if ( $this->request
->getVal( 'ShowCC' ) ) {
200 $page = $this->getPageByName( 'Options' );
201 $this->output
->useShortHeader();
202 $this->output
->allowFrames();
203 $this->output
->addHTML( $page->getCCDoneBox() );
205 return $this->finish();
209 $pageName = $this->request
->getVal( 'page' );
211 if ( in_array( $pageName, $this->otherPages
) ) {
214 $page = $this->getPageByName( $pageName );
217 if ( !$pageName ||
!in_array( $pageName, $this->pageSequence
) ) {
218 $pageId = $lowestUnhappy;
220 $pageId = array_search( $pageName, $this->pageSequence
);
223 # If necessary, move back to the lowest-numbered unhappy page
224 if ( $pageId > $lowestUnhappy ) {
225 $pageId = $lowestUnhappy;
226 if ( $lowestUnhappy == 0 ) {
227 # Knocked back to start, possible loss of session data.
228 $this->showSessionWarning
= true;
232 $pageName = $this->pageSequence
[$pageId];
233 $page = $this->getPageByName( $pageName );
236 # If a back button was submitted, go back without submitting the form data.
237 if ( $this->request
->wasPosted() && $this->request
->getBool( 'submit-back' ) ) {
238 if ( $this->request
->getVal( 'lastPage' ) ) {
239 $nextPage = $this->request
->getVal( 'lastPage' );
240 } elseif ( $pageId !== false ) {
242 # Skip the skipped pages
243 $nextPageId = $pageId;
247 $nextPage = $this->pageSequence
[$nextPageId];
248 } while ( isset( $this->skippedPages
[$nextPage] ) );
250 $nextPage = $this->pageSequence
[$lowestUnhappy];
253 $this->output
->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
255 return $this->finish();
259 $this->currentPageName
= $page->getName();
260 $this->startPageWrapper( $pageName );
262 if ( $page->isSlow() ) {
263 $this->disableTimeLimit();
266 $result = $page->execute();
268 $this->endPageWrapper();
270 if ( $result == 'skip' ) {
271 # Page skipped without explicit submission.
272 # Skip it when we click "back" so that we don't just go forward again.
273 $this->skippedPages
[$pageName] = true;
274 $result = 'continue';
276 unset( $this->skippedPages
[$pageName] );
279 # If it was posted, the page can request a continue to the next page.
280 if ( $result === 'continue' && !$this->output
->headerDone() ) {
281 if ( $pageId !== false ) {
282 $this->happyPages
[$pageId] = true;
285 $lowestUnhappy = $this->getLowestUnhappy();
287 if ( $this->request
->getVal( 'lastPage' ) ) {
288 $nextPage = $this->request
->getVal( 'lastPage' );
289 } elseif ( $pageId !== false ) {
290 $nextPage = $this->pageSequence
[$pageId +
1];
292 $nextPage = $this->pageSequence
[$lowestUnhappy];
295 if ( array_search( $nextPage, $this->pageSequence
) > $lowestUnhappy ) {
296 $nextPage = $this->pageSequence
[$lowestUnhappy];
299 $this->output
->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
302 return $this->finish();
306 * Find the next page in sequence that hasn't been completed
309 public function getLowestUnhappy() {
310 if ( count( $this->happyPages
) == 0 ) {
313 return max( array_keys( $this->happyPages
) ) +
1;
318 * Start the PHP session. This may be called before execute() to start the PHP session.
323 public function startSession() {
324 if ( wfIniGetBool( 'session.auto_start' ) ||
session_id() ) {
329 $this->phpErrors
= [];
330 set_error_handler( [ $this, 'errorHandler' ] );
332 session_name( 'mw_installer_session' );
334 } catch ( Exception
$e ) {
335 restore_error_handler();
338 restore_error_handler();
340 if ( $this->phpErrors
) {
348 * Get a hash of data identifying this MW installation.
350 * This is used by mw-config/index.php to prevent multiple installations of MW
351 * on the same cookie domain from interfering with each other.
355 public function getFingerprint() {
356 // Get the base URL of the installation
357 $url = $this->request
->getFullRequestURL();
358 if ( preg_match( '!^(.*\?)!', $url, $m ) ) {
362 if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
363 // This... seems to try to get the base path from
364 // the /mw-config/index.php. Kinda scary though?
368 return md5( serialize( [
369 'local path' => dirname( __DIR__
),
371 'version' => $GLOBALS['wgVersion']
376 * Show an error message in a box. Parameters are like wfMessage(), or
377 * alternatively, pass a Message object in.
378 * @param string|Message $msg
379 * @param mixed ...$params
381 public function showError( $msg, ...$params ) {
382 if ( !( $msg instanceof Message
) ) {
385 array_map( 'htmlspecialchars', $params )
388 $text = $msg->useDatabase( false )->plain();
389 $this->output
->addHTML( $this->getErrorBox( $text ) );
393 * Temporary error handler for session start debugging.
395 * @param int $errno Unused
396 * @param string $errstr
398 public function errorHandler( $errno, $errstr ) {
399 $this->phpErrors
[] = $errstr;
403 * Clean up from execute()
407 public function finish() {
408 $this->output
->output();
410 $this->session
['happyPages'] = $this->happyPages
;
411 $this->session
['skippedPages'] = $this->skippedPages
;
412 $this->session
['settings'] = $this->settings
;
414 return $this->session
;
418 * We're restarting the installation, reset the session, happyPages, etc
420 public function reset() {
422 $this->happyPages
= [];
423 $this->settings
= [];
427 * Get a URL for submission back to the same script.
429 * @param string[] $query
433 public function getUrl( $query = [] ) {
434 $url = $this->request
->getRequestURL();
435 # Remove existing query
436 $url = preg_replace( '/\?.*$/', '', $url );
439 $url .= '?' . wfArrayToCgi( $query );
446 * Get a WebInstallerPage by name.
448 * @param string $pageName
449 * @return WebInstallerPage
451 public function getPageByName( $pageName ) {
452 $pageClass = 'WebInstaller' . $pageName;
454 return new $pageClass( $this );
458 * Get a session variable.
460 * @param string $name
461 * @param array|null $default
465 public function getSession( $name, $default = null ) {
466 return $this->session
[$name] ??
$default;
470 * Set a session variable.
472 * @param string $name Key for the variable
473 * @param mixed $value
475 public function setSession( $name, $value ) {
476 $this->session
[$name] = $value;
480 * Get the next tabindex attribute value.
484 public function nextTabIndex() {
485 return $this->tabIndex++
;
489 * Initializes language-related variables.
491 public function setupLanguage() {
492 global $wgLang, $wgContLang, $wgLanguageCode;
494 if ( $this->getSession( 'test' ) === null && !$this->request
->wasPosted() ) {
495 $wgLanguageCode = $this->getAcceptLanguage();
496 $wgLang = Language
::factory( $wgLanguageCode );
497 RequestContext
::getMain()->setLanguage( $wgLang );
498 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
499 $this->setVar( '_UserLang', $wgLanguageCode );
501 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
503 $wgContLang = MediaWikiServices
::getInstance()->getContentLanguage();
507 * Retrieves MediaWiki language from Accept-Language HTTP header.
511 public function getAcceptLanguage() {
512 global $wgLanguageCode, $wgRequest;
514 $mwLanguages = Language
::fetchLanguageNames( null, 'mwfile' );
515 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
517 foreach ( $headerLanguages as $lang ) {
518 if ( isset( $mwLanguages[$lang] ) ) {
523 return $wgLanguageCode;
527 * Called by execute() before page output starts, to show a page list.
529 * @param string $currentPageName
531 private function startPageWrapper( $currentPageName ) {
532 $s = "<div class=\"config-page-wrapper\">\n";
533 $s .= "<div class=\"config-page\">\n";
534 $s .= "<div class=\"config-page-list\"><ul>\n";
537 foreach ( $this->pageSequence
as $id => $pageName ) {
538 $happy = !empty( $this->happyPages
[$id] );
539 $s .= $this->getPageListItem(
541 $happy ||
$lastHappy == $id - 1,
550 $s .= "</ul><br/><ul>\n";
551 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
553 $s .= "</ul></div>\n";
556 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
557 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
558 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
559 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
560 $s .= Html
::element( 'h2', [],
561 wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
563 $this->output
->addHTMLNoFlush( $s );
567 * Get a list item for the page list.
569 * @param string $pageName
570 * @param bool $enabled
571 * @param string $currentPageName
575 private function getPageListItem( $pageName, $enabled, $currentPageName ) {
576 $s = "<li class=\"config-page-list-item\">";
579 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
580 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
581 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
582 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
583 $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
586 $query = [ 'page' => $pageName ];
588 if ( !in_array( $pageName, $this->pageSequence
) ) {
589 if ( in_array( $currentPageName, $this->pageSequence
) ) {
590 $query['lastPage'] = $currentPageName;
593 $link = Html
::element( 'a',
595 'href' => $this->getUrl( $query )
600 $link = htmlspecialchars( $name );
603 if ( $pageName == $currentPageName ) {
604 $s .= "<span class=\"config-page-current\">$link</span>";
609 $s .= Html
::element( 'span',
611 'class' => 'config-page-disabled'
623 * Output some stuff after a page is finished.
625 private function endPageWrapper() {
626 $this->output
->addHTMLNoFlush(
627 "<div class=\"visualClear\"></div>\n" .
629 "<div class=\"visualClear\"></div>\n" .
634 * Get HTML for an error box with an icon.
636 * @param string $text Wikitext, get this with wfMessage()->plain()
640 public function getErrorBox( $text ) {
641 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
645 * Get HTML for a warning box with an icon.
647 * @param string $text Wikitext, get this with wfMessage()->plain()
651 public function getWarningBox( $text ) {
652 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
656 * Get HTML for an information message box with an icon.
658 * @param string|HtmlArmor $text Wikitext to be parsed (from Message::plain) or raw HTML.
659 * @param string|bool $icon Icon name, file in mw-config/images. Default: false
660 * @param string|bool $class Additional class name to add to the wrapper div. Default: false.
661 * @return string HTML
663 public function getInfoBox( $text, $icon = false, $class = false ) {
664 $html = ( $text instanceof HtmlArmor
) ?
665 HtmlArmor
::getHtml( $text ) :
666 $this->parse( $text, true );
667 $icon = ( $icon == false ) ?
668 'images/info-32.png' :
670 $alt = wfMessage( 'config-information' )->text();
672 return Html
::infoBox( $html, $icon, $alt, $class );
676 * Get small text indented help for a preceding form field.
677 * Parameters like wfMessage().
682 public function getHelpBox( $msg, ...$args ) {
683 $args = array_map( 'htmlspecialchars', $args );
684 $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
685 $html = $this->parse( $text, true );
686 $id = 'helpBox-' . $this->helpBoxId++
;
688 return "<div class=\"config-help-field-container\">\n" .
689 "<input type=\"checkbox\" class=\"config-help-field-checkbox\" id=\"$id\" />" .
690 "<label class=\"config-help-field-hint\" for=\"$id\" title=\"" .
691 wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
692 wfMessage( 'config-help' )->escaped() . "</label>\n" .
693 "<div class=\"config-help-field-data\">" . $html . "</div>\n" .
699 * @param string $msg Key for wfMessage()
700 * @param mixed ...$params
702 public function showHelpBox( $msg, ...$params ) {
703 $html = $this->getHelpBox( $msg, ...$params );
704 $this->output
->addHTML( $html );
708 * Show a short informational message.
709 * Output looks like a list.
712 * @param mixed ...$params
714 public function showMessage( $msg, ...$params ) {
715 $html = '<div class="config-message">' .
716 $this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) .
718 $this->output
->addHTML( $html );
722 * @param Status $status
724 public function showStatusMessage( Status
$status ) {
725 $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
726 foreach ( $errors as $error ) {
727 $this->showMessage( ...$error );
732 * Label a control by wrapping a config-input div around it and putting a
736 * @param string $forId
737 * @param string $contents
738 * @param string $helpData
741 public function label( $msg, $forId, $contents, $helpData = "" ) {
742 if ( strval( $msg ) == '' ) {
743 $labelText = "\u{00A0}";
745 $labelText = wfMessage( $msg )->escaped();
748 $attributes = [ 'class' => 'config-label' ];
751 $attributes['for'] = $forId;
754 return "<div class=\"config-block\">\n" .
755 " <div class=\"config-block-label\">\n" .
762 " <div class=\"config-block-elements\">\n" .
769 * Get a labelled text box to configure a variable.
771 * @param mixed[] $params
773 * var: The variable to be configured (required)
774 * label: The message name for the label (required)
775 * attribs: Additional attributes for the input element (optional)
776 * controlName: The name for the input element (optional)
777 * value: The current value of the variable (optional)
778 * help: The html for the help text (optional)
782 public function getTextBox( $params ) {
783 if ( !isset( $params['controlName'] ) ) {
784 $params['controlName'] = 'config_' . $params['var'];
787 if ( !isset( $params['value'] ) ) {
788 $params['value'] = $this->getVar( $params['var'] );
791 if ( !isset( $params['attribs'] ) ) {
792 $params['attribs'] = [];
794 if ( !isset( $params['help'] ) ) {
795 $params['help'] = "";
800 $params['controlName'],
802 $params['controlName'],
803 30, // intended to be overridden by CSS
805 $params['attribs'] +
[
806 'id' => $params['controlName'],
807 'class' => 'config-input-text',
808 'tabindex' => $this->nextTabIndex()
816 * Get a labelled textarea to configure a variable
818 * @param mixed[] $params
820 * var: The variable to be configured (required)
821 * label: The message name for the label (required)
822 * attribs: Additional attributes for the input element (optional)
823 * controlName: The name for the input element (optional)
824 * value: The current value of the variable (optional)
825 * help: The html for the help text (optional)
829 public function getTextArea( $params ) {
830 if ( !isset( $params['controlName'] ) ) {
831 $params['controlName'] = 'config_' . $params['var'];
834 if ( !isset( $params['value'] ) ) {
835 $params['value'] = $this->getVar( $params['var'] );
838 if ( !isset( $params['attribs'] ) ) {
839 $params['attribs'] = [];
841 if ( !isset( $params['help'] ) ) {
842 $params['help'] = "";
847 $params['controlName'],
849 $params['controlName'],
853 $params['attribs'] +
[
854 'id' => $params['controlName'],
855 'class' => 'config-input-text',
856 'tabindex' => $this->nextTabIndex()
864 * Get a labelled password box to configure a variable.
866 * Implements password hiding
867 * @param mixed[] $params
869 * var: The variable to be configured (required)
870 * label: The message name for the label (required)
871 * attribs: Additional attributes for the input element (optional)
872 * controlName: The name for the input element (optional)
873 * value: The current value of the variable (optional)
874 * help: The html for the help text (optional)
878 public function getPasswordBox( $params ) {
879 if ( !isset( $params['value'] ) ) {
880 $params['value'] = $this->getVar( $params['var'] );
883 if ( !isset( $params['attribs'] ) ) {
884 $params['attribs'] = [];
887 $params['value'] = $this->getFakePassword( $params['value'] );
888 $params['attribs']['type'] = 'password';
890 return $this->getTextBox( $params );
894 * Get a labelled checkbox to configure a boolean variable.
896 * @param mixed[] $params
898 * var: The variable to be configured (required)
899 * label: The message name for the label (required)
900 * labelAttribs:Additional attributes for the label element (optional)
901 * attribs: Additional attributes for the input element (optional)
902 * controlName: The name for the input element (optional)
903 * value: The current value of the variable (optional)
904 * help: The html for the help text (optional)
908 public function getCheckBox( $params ) {
909 if ( !isset( $params['controlName'] ) ) {
910 $params['controlName'] = 'config_' . $params['var'];
913 if ( !isset( $params['value'] ) ) {
914 $params['value'] = $this->getVar( $params['var'] );
917 if ( !isset( $params['attribs'] ) ) {
918 $params['attribs'] = [];
920 if ( !isset( $params['help'] ) ) {
921 $params['help'] = "";
923 if ( !isset( $params['labelAttribs'] ) ) {
924 $params['labelAttribs'] = [];
926 $labelText = $params['rawtext'] ??
$this->parse( wfMessage( $params['label'] )->plain() );
928 return "<div class=\"config-input-check\">\n" .
932 $params['labelAttribs'],
934 $params['controlName'],
936 $params['attribs'] +
[
937 'id' => $params['controlName'],
938 'tabindex' => $this->nextTabIndex(),
947 * Get a set of labelled radio buttons.
949 * @param mixed[] $params
951 * var: The variable to be configured (required)
952 * label: The message name for the label (required)
953 * itemLabelPrefix: The message name prefix for the item labels (required)
954 * itemLabels: List of message names to use for the item labels instead
955 * of itemLabelPrefix, keyed by values
956 * values: List of allowed values (required)
957 * itemAttribs: Array of attribute arrays, outer key is the value name (optional)
958 * commonAttribs: Attribute array applied to all items
959 * controlName: The name for the input element (optional)
960 * value: The current value of the variable (optional)
961 * help: The html for the help text (optional)
965 public function getRadioSet( $params ) {
966 $items = $this->getRadioElements( $params );
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 $value => $item ) {
980 $s .= "<li>$item</li>\n";
984 return $this->label( $label, $params['controlName'], $s, $params['help'] );
988 * Get a set of labelled radio buttons. You probably want to use getRadioSet(), not this.
992 * @param mixed[] $params
995 public function getRadioElements( $params ) {
996 if ( !isset( $params['controlName'] ) ) {
997 $params['controlName'] = 'config_' . $params['var'];
1000 if ( !isset( $params['value'] ) ) {
1001 $params['value'] = $this->getVar( $params['var'] );
1006 foreach ( $params['values'] as $value ) {
1009 if ( isset( $params['commonAttribs'] ) ) {
1010 $itemAttribs = $params['commonAttribs'];
1013 if ( isset( $params['itemAttribs'][$value] ) ) {
1014 $itemAttribs = $params['itemAttribs'][$value] +
$itemAttribs;
1017 $checked = $value == $params['value'];
1018 $id = $params['controlName'] . '_' . $value;
1019 $itemAttribs['id'] = $id;
1020 $itemAttribs['tabindex'] = $this->nextTabIndex();
1023 Xml
::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
1025 Xml
::tags( 'label', [ 'for' => $id ], $this->parse(
1026 isset( $params['itemLabels'] ) ?
1027 wfMessage( $params['itemLabels'][$value] )->plain() :
1028 wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
1036 * Output an error or warning box using a Status object.
1038 * @param Status $status
1040 public function showStatusBox( $status ) {
1041 if ( !$status->isGood() ) {
1042 $text = $status->getWikiText();
1044 if ( $status->isOK() ) {
1045 $box = $this->getWarningBox( $text );
1047 $box = $this->getErrorBox( $text );
1050 $this->output
->addHTML( $box );
1055 * Convenience function to set variables based on form data.
1056 * Assumes that variables containing "password" in the name are (potentially
1059 * @param string[] $varNames
1060 * @param string $prefix The prefix added to variables to obtain form names
1064 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
1067 foreach ( $varNames as $name ) {
1068 $value = $this->request
->getVal( $prefix . $name );
1069 // T32524, do not trim passwords
1070 if ( stripos( $name, 'password' ) === false ) {
1071 $value = trim( $value );
1073 $newValues[$name] = $value;
1075 if ( $value === null ) {
1077 $this->setVar( $name, false );
1078 } elseif ( stripos( $name, 'password' ) !== false ) {
1079 $this->setPassword( $name, $value );
1081 $this->setVar( $name, $value );
1089 * Helper for WebInstallerOutput
1091 * @internal For use by WebInstallerOutput
1092 * @param string $page
1095 public function getDocUrl( $page ) {
1096 $query = [ 'page' => $page ];
1098 if ( in_array( $this->currentPageName
, $this->pageSequence
) ) {
1099 $query['lastPage'] = $this->currentPageName
;
1102 return $this->getUrl( $query );
1106 * Helper for sidebar links.
1108 * @internal For use in WebInstallerOutput class
1109 * @param string $url
1110 * @param string $linkText
1111 * @return string HTML
1113 public function makeLinkItem( $url, $linkText ) {
1114 return Html
::rawElement( 'li', [],
1115 Html
::element( 'a', [ 'href' => $url ], $linkText )
1120 * Helper for "Download LocalSettings" link.
1122 * @internal For use in WebInstallerComplete class
1123 * @return string Html for download link
1125 public function makeDownloadLinkHtml() {
1126 $anchor = Html
::rawElement( 'a',
1127 [ 'href' => $this->getUrl( [ 'localsettings' => 1 ] ) ],
1128 wfMessage( 'config-download-localsettings' )->parse()
1131 return Html
::rawElement( 'div', [ 'class' => 'config-download-link' ], $anchor );
1135 * If the software package wants the LocalSettings.php file
1136 * to be placed in a specific location, override this function
1137 * (see mw-config/overrides/README) to return the path of
1138 * where the file should be saved, or false for a generic
1139 * "in the base of your install"
1142 * @return string|bool
1144 public function getLocalSettingsLocation() {
1151 public function envCheckPath() {
1152 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1153 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1154 // to get the path to the current script... hopefully it's reliable. SIGH
1156 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1157 $path = $_SERVER['PHP_SELF'];
1158 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1159 $path = $_SERVER['SCRIPT_NAME'];
1161 if ( $path === false ) {
1162 $this->showError( 'config-no-uri' );
1166 return parent
::envCheckPath();
1169 public function envPrepPath() {
1170 parent
::envPrepPath();
1171 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1172 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1173 // to get the path to the current script... hopefully it's reliable. SIGH
1175 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1176 $path = $_SERVER['PHP_SELF'];
1177 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1178 $path = $_SERVER['SCRIPT_NAME'];
1180 if ( $path !== false ) {
1181 $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
1183 $this->setVar( 'wgScriptPath', "$scriptPath" );
1184 // Update variables set from Setup.php that are derived from wgScriptPath
1185 $this->setVar( 'wgScript', "$scriptPath/index.php" );
1186 $this->setVar( 'wgLoadScript', "$scriptPath/load.php" );
1187 $this->setVar( 'wgStylePath', "$scriptPath/skins" );
1188 $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
1189 $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
1190 $this->setVar( 'wgUploadPath', "$scriptPath/images" );
1191 $this->setVar( 'wgResourceBasePath', "$scriptPath" );
1198 protected function envGetDefaultServer() {
1199 return WebRequest
::detectServer();
1203 * Actually output LocalSettings.php for download
1205 * @suppress SecurityCheck-XSS
1207 private function outputLS() {
1208 $this->request
->response()->header( 'Content-type: application/x-httpd-php' );
1209 $this->request
->response()->header(
1210 'Content-Disposition: attachment; filename="LocalSettings.php"'
1213 $ls = InstallerOverrides
::getLocalSettingsGenerator( $this );
1214 $rightsProfile = $this->rightsProfiles
[$this->getVar( '_RightsProfile' )];
1215 foreach ( $rightsProfile as $group => $rightsArr ) {
1216 $ls->setGroupRights( $group, $rightsArr );
1218 echo $ls->getText();
1222 * Output stylesheet for web installer pages
1224 public function outputCss() {
1225 $this->request
->response()->header( 'Content-type: text/css' );
1226 echo $this->output
->getCSS();
1232 public function getPhpErrors() {
1233 return $this->phpErrors
;