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;
150 $parser = MediaWikiServices
::getInstance()->getParser();
151 $parser->setHook( 'downloadlink', [ $this, 'downloadLinkHook' ] );
152 $parser->setHook( 'doclink', [ $this, 'docLink' ] );
158 * @param array[] $session Initial session array
160 * @return array[] New session array
162 public function execute( array $session ) {
163 $this->session
= $session;
165 if ( isset( $session['settings'] ) ) {
166 $this->settings
= $session['settings'] +
$this->settings
;
167 // T187586 MediaWikiServices works with globals
168 foreach ( $this->settings
as $key => $val ) {
169 $GLOBALS[$key] = $val;
173 $this->setupLanguage();
175 if ( ( $this->getVar( '_InstallDone' ) ||
$this->getVar( '_UpgradeDone' ) )
176 && $this->request
->getVal( 'localsettings' )
179 return $this->session
;
182 $isCSS = $this->request
->getVal( 'css' );
185 return $this->session
;
188 $this->happyPages
= $session['happyPages'] ??
[];
190 $this->skippedPages
= $session['skippedPages'] ??
[];
192 $lowestUnhappy = $this->getLowestUnhappy();
194 # Special case for Creative Commons partner chooser box.
195 if ( $this->request
->getVal( 'SubmitCC' ) ) {
196 $page = $this->getPageByName( 'Options' );
197 $this->output
->useShortHeader();
198 $this->output
->allowFrames();
201 return $this->finish();
204 if ( $this->request
->getVal( 'ShowCC' ) ) {
205 $page = $this->getPageByName( 'Options' );
206 $this->output
->useShortHeader();
207 $this->output
->allowFrames();
208 $this->output
->addHTML( $page->getCCDoneBox() );
210 return $this->finish();
214 $pageName = $this->request
->getVal( 'page' );
216 if ( in_array( $pageName, $this->otherPages
) ) {
219 $page = $this->getPageByName( $pageName );
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];
238 $page = $this->getPageByName( $pageName );
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 ] ) );
260 return $this->finish();
264 $this->currentPageName
= $page->getName();
265 $this->startPageWrapper( $pageName );
267 if ( $page->isSlow() ) {
268 $this->disableTimeLimit();
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;
290 $lowestUnhappy = $this->getLowestUnhappy();
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 ] ) );
307 return $this->finish();
311 * Find the next page in sequence that hasn't been completed
314 public function getLowestUnhappy() {
315 if ( count( $this->happyPages
) == 0 ) {
318 return max( array_keys( $this->happyPages
) ) +
1;
323 * Start the PHP session. This may be called before execute() to start the PHP session.
328 public function startSession() {
329 if ( wfIniGetBool( 'session.auto_start' ) ||
session_id() ) {
334 $this->phpErrors
= [];
335 set_error_handler( [ $this, 'errorHandler' ] );
337 session_name( 'mw_installer_session' );
339 } catch ( Exception
$e ) {
340 restore_error_handler();
343 restore_error_handler();
345 if ( $this->phpErrors
) {
353 * Get a hash of data identifying this MW installation.
355 * This is used by mw-config/index.php to prevent multiple installations of MW
356 * on the same cookie domain from interfering with each other.
360 public function getFingerprint() {
361 // Get the base URL of the installation
362 $url = $this->request
->getFullRequestURL();
363 if ( preg_match( '!^(.*\?)!', $url, $m ) ) {
367 if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
368 // This... seems to try to get the base path from
369 // the /mw-config/index.php. Kinda scary though?
373 return md5( serialize( [
374 'local path' => dirname( __DIR__
),
376 'version' => $GLOBALS['wgVersion']
381 * Show an error message in a box. Parameters are like wfMessage(), or
382 * alternatively, pass a Message object in.
383 * @param string|Message $msg
384 * @param mixed ...$params
386 public function showError( $msg, ...$params ) {
387 if ( !( $msg instanceof Message
) ) {
390 array_map( 'htmlspecialchars', $params )
393 $text = $msg->useDatabase( false )->plain();
394 $this->output
->addHTML( $this->getErrorBox( $text ) );
398 * Temporary error handler for session start debugging.
400 * @param int $errno Unused
401 * @param string $errstr
403 public function errorHandler( $errno, $errstr ) {
404 $this->phpErrors
[] = $errstr;
408 * Clean up from execute()
412 public function finish() {
413 $this->output
->output();
415 $this->session
['happyPages'] = $this->happyPages
;
416 $this->session
['skippedPages'] = $this->skippedPages
;
417 $this->session
['settings'] = $this->settings
;
419 return $this->session
;
423 * We're restarting the installation, reset the session, happyPages, etc
425 public function reset() {
427 $this->happyPages
= [];
428 $this->settings
= [];
432 * Get a URL for submission back to the same script.
434 * @param string[] $query
438 public function getUrl( $query = [] ) {
439 $url = $this->request
->getRequestURL();
440 # Remove existing query
441 $url = preg_replace( '/\?.*$/', '', $url );
444 $url .= '?' . wfArrayToCgi( $query );
451 * Get a WebInstallerPage by name.
453 * @param string $pageName
454 * @return WebInstallerPage
456 public function getPageByName( $pageName ) {
457 $pageClass = 'WebInstaller' . $pageName;
459 return new $pageClass( $this );
463 * Get a session variable.
465 * @param string $name
466 * @param array|null $default
470 public function getSession( $name, $default = null ) {
471 return $this->session
[$name] ??
$default;
475 * Set a session variable.
477 * @param string $name Key for the variable
478 * @param mixed $value
480 public function setSession( $name, $value ) {
481 $this->session
[$name] = $value;
485 * Get the next tabindex attribute value.
489 public function nextTabIndex() {
490 return $this->tabIndex++
;
494 * Initializes language-related variables.
496 public function setupLanguage() {
497 global $wgLang, $wgContLang, $wgLanguageCode;
499 if ( $this->getSession( 'test' ) === null && !$this->request
->wasPosted() ) {
500 $wgLanguageCode = $this->getAcceptLanguage();
501 $wgLang = Language
::factory( $wgLanguageCode );
502 RequestContext
::getMain()->setLanguage( $wgLang );
503 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
504 $this->setVar( '_UserLang', $wgLanguageCode );
506 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
508 $wgContLang = MediaWikiServices
::getInstance()->getContentLanguage();
512 * Retrieves MediaWiki language from Accept-Language HTTP header.
516 public function getAcceptLanguage() {
517 global $wgLanguageCode, $wgRequest;
519 $mwLanguages = Language
::fetchLanguageNames( null, 'mwfile' );
520 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
522 foreach ( $headerLanguages as $lang ) {
523 if ( isset( $mwLanguages[$lang] ) ) {
528 return $wgLanguageCode;
532 * Called by execute() before page output starts, to show a page list.
534 * @param string $currentPageName
536 private function startPageWrapper( $currentPageName ) {
537 $s = "<div class=\"config-page-wrapper\">\n";
538 $s .= "<div class=\"config-page\">\n";
539 $s .= "<div class=\"config-page-list\"><ul>\n";
542 foreach ( $this->pageSequence
as $id => $pageName ) {
543 $happy = !empty( $this->happyPages
[$id] );
544 $s .= $this->getPageListItem(
546 $happy ||
$lastHappy == $id - 1,
555 $s .= "</ul><br/><ul>\n";
556 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
558 $s .= "</ul></div>\n";
561 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
562 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
563 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
564 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
565 $s .= Html
::element( 'h2', [],
566 wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
568 $this->output
->addHTMLNoFlush( $s );
572 * Get a list item for the page list.
574 * @param string $pageName
575 * @param bool $enabled
576 * @param string $currentPageName
580 private function getPageListItem( $pageName, $enabled, $currentPageName ) {
581 $s = "<li class=\"config-page-list-item\">";
584 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
585 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
586 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
587 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
588 $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
591 $query = [ 'page' => $pageName ];
593 if ( !in_array( $pageName, $this->pageSequence
) ) {
594 if ( in_array( $currentPageName, $this->pageSequence
) ) {
595 $query['lastPage'] = $currentPageName;
598 $link = Html
::element( 'a',
600 'href' => $this->getUrl( $query )
605 $link = htmlspecialchars( $name );
608 if ( $pageName == $currentPageName ) {
609 $s .= "<span class=\"config-page-current\">$link</span>";
614 $s .= Html
::element( 'span',
616 'class' => 'config-page-disabled'
628 * Output some stuff after a page is finished.
630 private function endPageWrapper() {
631 $this->output
->addHTMLNoFlush(
632 "<div class=\"visualClear\"></div>\n" .
634 "<div class=\"visualClear\"></div>\n" .
639 * Get HTML for an error box with an icon.
641 * @param string $text Wikitext, get this with wfMessage()->plain()
645 public function getErrorBox( $text ) {
646 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
650 * Get HTML for a warning box with an icon.
652 * @param string $text Wikitext, get this with wfMessage()->plain()
656 public function getWarningBox( $text ) {
657 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
661 * Get HTML for an info box with an icon.
663 * @param string $text Wikitext, get this with wfMessage()->plain()
664 * @param string|bool $icon Icon name, file in mw-config/images. Default: false
665 * @param string|bool $class Additional class name to add to the wrapper div. Default: false.
669 public function getInfoBox( $text, $icon = false, $class = false ) {
670 $text = $this->parse( $text, true );
671 $icon = ( $icon == false ) ?
672 'images/info-32.png' :
674 $alt = wfMessage( 'config-information' )->text();
676 return Html
::infoBox( $text, $icon, $alt, $class );
680 * Get small text indented help for a preceding form field.
681 * Parameters like wfMessage().
686 public function getHelpBox( $msg, ...$args ) {
687 $args = array_map( 'htmlspecialchars', $args );
688 $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
689 $html = $this->parse( $text, true );
690 $id = 'helpBox-' . $this->helpBoxId++
;
692 return "<div class=\"config-help-field-container\">\n" .
693 "<input type=\"checkbox\" class=\"config-help-field-checkbox\" id=\"$id\" />" .
694 "<label class=\"config-help-field-hint\" for=\"$id\" title=\"" .
695 wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
696 wfMessage( 'config-help' )->escaped() . "</label>\n" .
697 "<div class=\"config-help-field-data\">" . $html . "</div>\n" .
703 * @param string $msg Key for wfMessage()
704 * @param mixed ...$params
706 public function showHelpBox( $msg, ...$params ) {
707 $html = $this->getHelpBox( $msg, ...$params );
708 $this->output
->addHTML( $html );
712 * Show a short informational message.
713 * Output looks like a list.
716 * @param mixed ...$params
718 public function showMessage( $msg, ...$params ) {
719 $html = '<div class="config-message">' .
720 $this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) .
722 $this->output
->addHTML( $html );
726 * @param Status $status
728 public function showStatusMessage( Status
$status ) {
729 $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
730 foreach ( $errors as $error ) {
731 $this->showMessage( ...$error );
736 * Label a control by wrapping a config-input div around it and putting a
740 * @param string $forId
741 * @param string $contents
742 * @param string $helpData
745 public function label( $msg, $forId, $contents, $helpData = "" ) {
746 if ( strval( $msg ) == '' ) {
747 $labelText = "\u{00A0}";
749 $labelText = wfMessage( $msg )->escaped();
752 $attributes = [ 'class' => 'config-label' ];
755 $attributes['for'] = $forId;
758 return "<div class=\"config-block\">\n" .
759 " <div class=\"config-block-label\">\n" .
766 " <div class=\"config-block-elements\">\n" .
773 * Get a labelled text box to configure a variable.
775 * @param mixed[] $params
777 * var: The variable to be configured (required)
778 * label: The message name for the label (required)
779 * attribs: Additional attributes for the input element (optional)
780 * controlName: The name for the input element (optional)
781 * value: The current value of the variable (optional)
782 * help: The html for the help text (optional)
786 public function getTextBox( $params ) {
787 if ( !isset( $params['controlName'] ) ) {
788 $params['controlName'] = 'config_' . $params['var'];
791 if ( !isset( $params['value'] ) ) {
792 $params['value'] = $this->getVar( $params['var'] );
795 if ( !isset( $params['attribs'] ) ) {
796 $params['attribs'] = [];
798 if ( !isset( $params['help'] ) ) {
799 $params['help'] = "";
804 $params['controlName'],
806 $params['controlName'],
807 30, // intended to be overridden by CSS
809 $params['attribs'] +
[
810 'id' => $params['controlName'],
811 'class' => 'config-input-text',
812 'tabindex' => $this->nextTabIndex()
820 * Get a labelled textarea to configure a variable
822 * @param mixed[] $params
824 * var: The variable to be configured (required)
825 * label: The message name for the label (required)
826 * attribs: Additional attributes for the input element (optional)
827 * controlName: The name for the input element (optional)
828 * value: The current value of the variable (optional)
829 * help: The html for the help text (optional)
833 public function getTextArea( $params ) {
834 if ( !isset( $params['controlName'] ) ) {
835 $params['controlName'] = 'config_' . $params['var'];
838 if ( !isset( $params['value'] ) ) {
839 $params['value'] = $this->getVar( $params['var'] );
842 if ( !isset( $params['attribs'] ) ) {
843 $params['attribs'] = [];
845 if ( !isset( $params['help'] ) ) {
846 $params['help'] = "";
851 $params['controlName'],
853 $params['controlName'],
857 $params['attribs'] +
[
858 'id' => $params['controlName'],
859 'class' => 'config-input-text',
860 'tabindex' => $this->nextTabIndex()
868 * Get a labelled password box to configure a variable.
870 * Implements password hiding
871 * @param mixed[] $params
873 * var: The variable to be configured (required)
874 * label: The message name for the label (required)
875 * attribs: Additional attributes for the input element (optional)
876 * controlName: The name for the input element (optional)
877 * value: The current value of the variable (optional)
878 * help: The html for the help text (optional)
882 public function getPasswordBox( $params ) {
883 if ( !isset( $params['value'] ) ) {
884 $params['value'] = $this->getVar( $params['var'] );
887 if ( !isset( $params['attribs'] ) ) {
888 $params['attribs'] = [];
891 $params['value'] = $this->getFakePassword( $params['value'] );
892 $params['attribs']['type'] = 'password';
894 return $this->getTextBox( $params );
898 * Get a labelled checkbox to configure a boolean variable.
900 * @param mixed[] $params
902 * var: The variable to be configured (required)
903 * label: The message name for the label (required)
904 * labelAttribs:Additional attributes for the label element (optional)
905 * attribs: Additional attributes for the input element (optional)
906 * controlName: The name for the input element (optional)
907 * value: The current value of the variable (optional)
908 * help: The html for the help text (optional)
912 public function getCheckBox( $params ) {
913 if ( !isset( $params['controlName'] ) ) {
914 $params['controlName'] = 'config_' . $params['var'];
917 if ( !isset( $params['value'] ) ) {
918 $params['value'] = $this->getVar( $params['var'] );
921 if ( !isset( $params['attribs'] ) ) {
922 $params['attribs'] = [];
924 if ( !isset( $params['help'] ) ) {
925 $params['help'] = "";
927 if ( !isset( $params['labelAttribs'] ) ) {
928 $params['labelAttribs'] = [];
930 $labelText = $params['rawtext'] ??
$this->parse( wfMessage( $params['label'] )->plain() );
932 return "<div class=\"config-input-check\">\n" .
936 $params['labelAttribs'],
938 $params['controlName'],
940 $params['attribs'] +
[
941 'id' => $params['controlName'],
942 'tabindex' => $this->nextTabIndex(),
951 * Get a set of labelled radio buttons.
953 * @param mixed[] $params
955 * var: The variable to be configured (required)
956 * label: The message name for the label (required)
957 * itemLabelPrefix: The message name prefix for the item labels (required)
958 * itemLabels: List of message names to use for the item labels instead
959 * of itemLabelPrefix, keyed by values
960 * values: List of allowed values (required)
961 * itemAttribs: Array of attribute arrays, outer key is the value name (optional)
962 * commonAttribs: Attribute array applied to all items
963 * controlName: The name for the input element (optional)
964 * value: The current value of the variable (optional)
965 * help: The html for the help text (optional)
969 public function getRadioSet( $params ) {
970 $items = $this->getRadioElements( $params );
972 $label = $params['label'] ??
'';
974 if ( !isset( $params['controlName'] ) ) {
975 $params['controlName'] = 'config_' . $params['var'];
978 if ( !isset( $params['help'] ) ) {
979 $params['help'] = "";
983 foreach ( $items as $value => $item ) {
984 $s .= "<li>$item</li>\n";
988 return $this->label( $label, $params['controlName'], $s, $params['help'] );
992 * Get a set of labelled radio buttons. You probably want to use getRadioSet(), not this.
996 * @param mixed[] $params
999 public function getRadioElements( $params ) {
1000 if ( !isset( $params['controlName'] ) ) {
1001 $params['controlName'] = 'config_' . $params['var'];
1004 if ( !isset( $params['value'] ) ) {
1005 $params['value'] = $this->getVar( $params['var'] );
1010 foreach ( $params['values'] as $value ) {
1013 if ( isset( $params['commonAttribs'] ) ) {
1014 $itemAttribs = $params['commonAttribs'];
1017 if ( isset( $params['itemAttribs'][$value] ) ) {
1018 $itemAttribs = $params['itemAttribs'][$value] +
$itemAttribs;
1021 $checked = $value == $params['value'];
1022 $id = $params['controlName'] . '_' . $value;
1023 $itemAttribs['id'] = $id;
1024 $itemAttribs['tabindex'] = $this->nextTabIndex();
1027 Xml
::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
1029 Xml
::tags( 'label', [ 'for' => $id ], $this->parse(
1030 isset( $params['itemLabels'] ) ?
1031 wfMessage( $params['itemLabels'][$value] )->plain() :
1032 wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
1040 * Output an error or warning box using a Status object.
1042 * @param Status $status
1044 public function showStatusBox( $status ) {
1045 if ( !$status->isGood() ) {
1046 $text = $status->getWikiText();
1048 if ( $status->isOK() ) {
1049 $box = $this->getWarningBox( $text );
1051 $box = $this->getErrorBox( $text );
1054 $this->output
->addHTML( $box );
1059 * Convenience function to set variables based on form data.
1060 * Assumes that variables containing "password" in the name are (potentially
1063 * @param string[] $varNames
1064 * @param string $prefix The prefix added to variables to obtain form names
1068 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
1071 foreach ( $varNames as $name ) {
1072 $value = $this->request
->getVal( $prefix . $name );
1073 // T32524, do not trim passwords
1074 if ( stripos( $name, 'password' ) === false ) {
1075 $value = trim( $value );
1077 $newValues[$name] = $value;
1079 if ( $value === null ) {
1081 $this->setVar( $name, false );
1082 } elseif ( stripos( $name, 'password' ) !== false ) {
1083 $this->setPassword( $name, $value );
1085 $this->setVar( $name, $value );
1093 * Helper for Installer::docLink()
1095 * @param string $page
1099 protected function getDocUrl( $page ) {
1100 $query = [ 'page' => $page ];
1102 if ( in_array( $this->currentPageName
, $this->pageSequence
) ) {
1103 $query['lastPage'] = $this->currentPageName
;
1106 return $this->getUrl( $query );
1110 * Extension tag hook for a documentation link.
1112 * @param string $linkText
1113 * @param string[] $attribs
1114 * @param Parser $parser Unused
1118 public function docLink( $linkText, $attribs, $parser ) {
1119 $url = $this->getDocUrl( $attribs['href'] );
1121 return Html
::element( 'a', [ 'href' => $url ], $linkText );
1125 * Helper for "Download LocalSettings" link on WebInstall_Complete
1127 * @param string $text Unused
1128 * @param string[] $attribs Unused
1129 * @param Parser $parser Unused
1131 * @return string Html for download link
1133 public function downloadLinkHook( $text, $attribs, $parser ) {
1134 $anchor = Html
::rawElement( 'a',
1135 [ 'href' => $this->getUrl( [ 'localsettings' => 1 ] ) ],
1136 wfMessage( 'config-download-localsettings' )->parse()
1139 return Html
::rawElement( 'div', [ 'class' => 'config-download-link' ], $anchor );
1143 * If the software package wants the LocalSettings.php file
1144 * to be placed in a specific location, override this function
1145 * (see mw-config/overrides/README) to return the path of
1146 * where the file should be saved, or false for a generic
1147 * "in the base of your install"
1150 * @return string|bool
1152 public function getLocalSettingsLocation() {
1159 public function envCheckPath() {
1160 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1161 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1162 // to get the path to the current script... hopefully it's reliable. SIGH
1164 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1165 $path = $_SERVER['PHP_SELF'];
1166 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1167 $path = $_SERVER['SCRIPT_NAME'];
1169 if ( $path === false ) {
1170 $this->showError( 'config-no-uri' );
1174 return parent
::envCheckPath();
1177 public function envPrepPath() {
1178 parent
::envPrepPath();
1179 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1180 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1181 // to get the path to the current script... hopefully it's reliable. SIGH
1183 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1184 $path = $_SERVER['PHP_SELF'];
1185 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1186 $path = $_SERVER['SCRIPT_NAME'];
1188 if ( $path !== false ) {
1189 $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
1191 $this->setVar( 'wgScriptPath', "$scriptPath" );
1192 // Update variables set from Setup.php that are derived from wgScriptPath
1193 $this->setVar( 'wgScript', "$scriptPath/index.php" );
1194 $this->setVar( 'wgLoadScript', "$scriptPath/load.php" );
1195 $this->setVar( 'wgStylePath', "$scriptPath/skins" );
1196 $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
1197 $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
1198 $this->setVar( 'wgUploadPath', "$scriptPath/images" );
1199 $this->setVar( 'wgResourceBasePath', "$scriptPath" );
1206 protected function envGetDefaultServer() {
1207 return WebRequest
::detectServer();
1211 * Actually output LocalSettings.php for download
1213 * @suppress SecurityCheck-XSS
1215 private function outputLS() {
1216 $this->request
->response()->header( 'Content-type: application/x-httpd-php' );
1217 $this->request
->response()->header(
1218 'Content-Disposition: attachment; filename="LocalSettings.php"'
1221 $ls = InstallerOverrides
::getLocalSettingsGenerator( $this );
1222 $rightsProfile = $this->rightsProfiles
[$this->getVar( '_RightsProfile' )];
1223 foreach ( $rightsProfile as $group => $rightsArr ) {
1224 $ls->setGroupRights( $group, $rightsArr );
1226 echo $ls->getText();
1230 * Output stylesheet for web installer pages
1232 public function outputCss() {
1233 $this->request
->response()->header( 'Content-type: text/css' );
1234 echo $this->output
->getCSS();
1240 public function getPhpErrors() {
1241 return $this->phpErrors
;