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 * Name of the page we're on
132 protected $currentPageName;
135 * @param WebRequest $request
137 public function __construct( WebRequest
$request ) {
138 parent
::__construct();
139 $this->output
= new WebInstallerOutput( $this );
140 $this->request
= $request;
144 $wgParser->setHook( 'downloadlink', [ $this, 'downloadLinkHook' ] );
145 $wgParser->setHook( 'doclink', [ $this, 'docLink' ] );
151 * @param array[] $session Initial session array
153 * @return array[] New session array
155 public function execute( array $session ) {
156 $this->session
= $session;
158 if ( isset( $session['settings'] ) ) {
159 $this->settings
= $session['settings'] +
$this->settings
;
160 // T187586 MediaWikiServices works with globals
161 foreach ( $this->settings
as $key => $val ) {
162 $GLOBALS[$key] = $val;
166 $this->setupLanguage();
168 if ( ( $this->getVar( '_InstallDone' ) ||
$this->getVar( '_UpgradeDone' ) )
169 && $this->request
->getVal( 'localsettings' )
172 return $this->session
;
175 $isCSS = $this->request
->getVal( 'css' );
178 return $this->session
;
181 if ( isset( $session['happyPages'] ) ) {
182 $this->happyPages
= $session['happyPages'];
184 $this->happyPages
= [];
187 if ( isset( $session['skippedPages'] ) ) {
188 $this->skippedPages
= $session['skippedPages'];
190 $this->skippedPages
= [];
193 $lowestUnhappy = $this->getLowestUnhappy();
195 # Special case for Creative Commons partner chooser box.
196 if ( $this->request
->getVal( 'SubmitCC' ) ) {
197 $page = $this->getPageByName( 'Options' );
198 $this->output
->useShortHeader();
199 $this->output
->allowFrames();
202 return $this->finish();
205 if ( $this->request
->getVal( 'ShowCC' ) ) {
206 $page = $this->getPageByName( 'Options' );
207 $this->output
->useShortHeader();
208 $this->output
->allowFrames();
209 $this->output
->addHTML( $page->getCCDoneBox() );
211 return $this->finish();
215 $pageName = $this->request
->getVal( 'page' );
217 if ( in_array( $pageName, $this->otherPages
) ) {
220 $page = $this->getPageByName( $pageName );
223 if ( !$pageName ||
!in_array( $pageName, $this->pageSequence
) ) {
224 $pageId = $lowestUnhappy;
226 $pageId = array_search( $pageName, $this->pageSequence
);
229 # If necessary, move back to the lowest-numbered unhappy page
230 if ( $pageId > $lowestUnhappy ) {
231 $pageId = $lowestUnhappy;
232 if ( $lowestUnhappy == 0 ) {
233 # Knocked back to start, possible loss of session data.
234 $this->showSessionWarning
= true;
238 $pageName = $this->pageSequence
[$pageId];
239 $page = $this->getPageByName( $pageName );
242 # If a back button was submitted, go back without submitting the form data.
243 if ( $this->request
->wasPosted() && $this->request
->getBool( 'submit-back' ) ) {
244 if ( $this->request
->getVal( 'lastPage' ) ) {
245 $nextPage = $this->request
->getVal( 'lastPage' );
246 } elseif ( $pageId !== false ) {
248 # Skip the skipped pages
249 $nextPageId = $pageId;
253 $nextPage = $this->pageSequence
[$nextPageId];
254 } while ( isset( $this->skippedPages
[$nextPage] ) );
256 $nextPage = $this->pageSequence
[$lowestUnhappy];
259 $this->output
->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
261 return $this->finish();
265 $this->currentPageName
= $page->getName();
266 $this->startPageWrapper( $pageName );
268 if ( $page->isSlow() ) {
269 $this->disableTimeLimit();
272 $result = $page->execute();
274 $this->endPageWrapper();
276 if ( $result == 'skip' ) {
277 # Page skipped without explicit submission.
278 # Skip it when we click "back" so that we don't just go forward again.
279 $this->skippedPages
[$pageName] = true;
280 $result = 'continue';
282 unset( $this->skippedPages
[$pageName] );
285 # If it was posted, the page can request a continue to the next page.
286 if ( $result === 'continue' && !$this->output
->headerDone() ) {
287 if ( $pageId !== false ) {
288 $this->happyPages
[$pageId] = true;
291 $lowestUnhappy = $this->getLowestUnhappy();
293 if ( $this->request
->getVal( 'lastPage' ) ) {
294 $nextPage = $this->request
->getVal( 'lastPage' );
295 } elseif ( $pageId !== false ) {
296 $nextPage = $this->pageSequence
[$pageId +
1];
298 $nextPage = $this->pageSequence
[$lowestUnhappy];
301 if ( array_search( $nextPage, $this->pageSequence
) > $lowestUnhappy ) {
302 $nextPage = $this->pageSequence
[$lowestUnhappy];
305 $this->output
->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
308 return $this->finish();
312 * Find the next page in sequence that hasn't been completed
315 public function getLowestUnhappy() {
316 if ( count( $this->happyPages
) == 0 ) {
319 return max( array_keys( $this->happyPages
) ) +
1;
324 * Start the PHP session. This may be called before execute() to start the PHP session.
329 public function startSession() {
330 if ( wfIniGetBool( 'session.auto_start' ) ||
session_id() ) {
335 $this->phpErrors
= [];
336 set_error_handler( [ $this, 'errorHandler' ] );
338 session_name( 'mw_installer_session' );
340 } catch ( Exception
$e ) {
341 restore_error_handler();
344 restore_error_handler();
346 if ( $this->phpErrors
) {
354 * Get a hash of data identifying this MW installation.
356 * This is used by mw-config/index.php to prevent multiple installations of MW
357 * on the same cookie domain from interfering with each other.
361 public function getFingerprint() {
362 // Get the base URL of the installation
363 $url = $this->request
->getFullRequestURL();
364 if ( preg_match( '!^(.*\?)!', $url, $m ) ) {
368 if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
369 // This... seems to try to get the base path from
370 // the /mw-config/index.php. Kinda scary though?
374 return md5( serialize( [
375 'local path' => dirname( __DIR__
),
377 'version' => $GLOBALS['wgVersion']
382 * Show an error message in a box. Parameters are like wfMessage(), or
383 * alternatively, pass a Message object in.
384 * @param string|Message $msg
386 public function showError( $msg /*...*/ ) {
387 if ( !( $msg instanceof Message
) ) {
388 $args = func_get_args();
389 array_shift( $args );
390 $args = array_map( 'htmlspecialchars', $args );
391 $msg = wfMessage( $msg, $args );
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 if ( !isset( $this->session
[$name] ) ) {
474 return $this->session
[$name];
479 * Set a session variable.
481 * @param string $name Key for the variable
482 * @param mixed $value
484 public function setSession( $name, $value ) {
485 $this->session
[$name] = $value;
489 * Get the next tabindex attribute value.
493 public function nextTabIndex() {
494 return $this->tabIndex++
;
498 * Initializes language-related variables.
500 public function setupLanguage() {
501 global $wgLang, $wgContLang, $wgLanguageCode;
503 if ( $this->getSession( 'test' ) === null && !$this->request
->wasPosted() ) {
504 $wgLanguageCode = $this->getAcceptLanguage();
505 $wgLang = Language
::factory( $wgLanguageCode );
506 RequestContext
::getMain()->setLanguage( $wgLang );
507 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
508 $this->setVar( '_UserLang', $wgLanguageCode );
510 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
512 $wgContLang = MediaWikiServices
::getInstance()->getContentLanguage();
516 * Retrieves MediaWiki language from Accept-Language HTTP header.
520 public function getAcceptLanguage() {
521 global $wgLanguageCode, $wgRequest;
523 $mwLanguages = Language
::fetchLanguageNames( null, 'mwfile' );
524 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
526 foreach ( $headerLanguages as $lang ) {
527 if ( isset( $mwLanguages[$lang] ) ) {
532 return $wgLanguageCode;
536 * Called by execute() before page output starts, to show a page list.
538 * @param string $currentPageName
540 private function startPageWrapper( $currentPageName ) {
541 $s = "<div class=\"config-page-wrapper\">\n";
542 $s .= "<div class=\"config-page\">\n";
543 $s .= "<div class=\"config-page-list\"><ul>\n";
546 foreach ( $this->pageSequence
as $id => $pageName ) {
547 $happy = !empty( $this->happyPages
[$id] );
548 $s .= $this->getPageListItem(
550 $happy ||
$lastHappy == $id - 1,
559 $s .= "</ul><br/><ul>\n";
560 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
562 $s .= "</ul></div>\n";
565 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
566 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
567 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
568 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
569 $s .= Html
::element( 'h2', [],
570 wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
572 $this->output
->addHTMLNoFlush( $s );
576 * Get a list item for the page list.
578 * @param string $pageName
579 * @param bool $enabled
580 * @param string $currentPageName
584 private function getPageListItem( $pageName, $enabled, $currentPageName ) {
585 $s = "<li class=\"config-page-list-item\">";
588 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
589 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
590 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
591 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
592 $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
595 $query = [ 'page' => $pageName ];
597 if ( !in_array( $pageName, $this->pageSequence
) ) {
598 if ( in_array( $currentPageName, $this->pageSequence
) ) {
599 $query['lastPage'] = $currentPageName;
602 $link = Html
::element( 'a',
604 'href' => $this->getUrl( $query )
609 $link = htmlspecialchars( $name );
612 if ( $pageName == $currentPageName ) {
613 $s .= "<span class=\"config-page-current\">$link</span>";
618 $s .= Html
::element( 'span',
620 'class' => 'config-page-disabled'
632 * Output some stuff after a page is finished.
634 private function endPageWrapper() {
635 $this->output
->addHTMLNoFlush(
636 "<div class=\"visualClear\"></div>\n" .
638 "<div class=\"visualClear\"></div>\n" .
643 * Get HTML for an error box with an icon.
645 * @param string $text Wikitext, get this with wfMessage()->plain()
649 public function getErrorBox( $text ) {
650 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
654 * Get HTML for a warning box with an icon.
656 * @param string $text Wikitext, get this with wfMessage()->plain()
660 public function getWarningBox( $text ) {
661 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
665 * Get HTML for an info box with an icon.
667 * @param string $text Wikitext, get this with wfMessage()->plain()
668 * @param string|bool $icon Icon name, file in mw-config/images. Default: false
669 * @param string|bool $class Additional class name to add to the wrapper div. Default: false.
673 public function getInfoBox( $text, $icon = false, $class = false ) {
674 $text = $this->parse( $text, true );
675 $icon = ( $icon == false ) ?
676 'images/info-32.png' :
678 $alt = wfMessage( 'config-information' )->text();
680 return Html
::infoBox( $text, $icon, $alt, $class );
684 * Get small text indented help for a preceding form field.
685 * Parameters like wfMessage().
690 public function getHelpBox( $msg /*, ... */ ) {
691 $args = func_get_args();
692 array_shift( $args );
693 $args = array_map( 'htmlspecialchars', $args );
694 $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
695 $html = $this->parse( $text, true );
697 return "<div class=\"config-help-field-container\">\n" .
698 "<span class=\"config-help-field-hint\" title=\"" .
699 wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
700 wfMessage( 'config-help' )->escaped() . "</span>\n" .
701 "<div class=\"config-help-field-data\">" . $html . "</div>\n" .
707 * @param string $msg Key for wfMessage()
709 public function showHelpBox( $msg /*, ... */ ) {
710 $args = func_get_args();
711 $html = $this->getHelpBox( ...$args );
712 $this->output
->addHTML( $html );
716 * Show a short informational message.
717 * Output looks like a list.
721 public function showMessage( $msg /*, ... */ ) {
722 $args = func_get_args();
723 array_shift( $args );
724 $html = '<div class="config-message">' .
725 $this->parse( wfMessage( $msg, $args )->useDatabase( false )->plain() ) .
727 $this->output
->addHTML( $html );
731 * @param Status $status
733 public function showStatusMessage( Status
$status ) {
734 $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
735 foreach ( $errors as $error ) {
736 $this->showMessage( ...$error );
741 * Label a control by wrapping a config-input div around it and putting a
745 * @param string $forId
746 * @param string $contents
747 * @param string $helpData
750 public function label( $msg, $forId, $contents, $helpData = "" ) {
751 if ( strval( $msg ) == '' ) {
752 $labelText = "\u{00A0}";
754 $labelText = wfMessage( $msg )->escaped();
757 $attributes = [ 'class' => 'config-label' ];
760 $attributes['for'] = $forId;
763 return "<div class=\"config-block\">\n" .
764 " <div class=\"config-block-label\">\n" .
771 " <div class=\"config-block-elements\">\n" .
778 * Get a labelled text box to configure a variable.
780 * @param mixed[] $params
782 * var: The variable to be configured (required)
783 * label: The message name for the label (required)
784 * attribs: Additional attributes for the input element (optional)
785 * controlName: The name for the input element (optional)
786 * value: The current value of the variable (optional)
787 * help: The html for the help text (optional)
791 public function getTextBox( $params ) {
792 if ( !isset( $params['controlName'] ) ) {
793 $params['controlName'] = 'config_' . $params['var'];
796 if ( !isset( $params['value'] ) ) {
797 $params['value'] = $this->getVar( $params['var'] );
800 if ( !isset( $params['attribs'] ) ) {
801 $params['attribs'] = [];
803 if ( !isset( $params['help'] ) ) {
804 $params['help'] = "";
809 $params['controlName'],
811 $params['controlName'],
812 30, // intended to be overridden by CSS
814 $params['attribs'] +
[
815 'id' => $params['controlName'],
816 'class' => 'config-input-text',
817 'tabindex' => $this->nextTabIndex()
825 * Get a labelled textarea to configure a variable
827 * @param mixed[] $params
829 * var: The variable to be configured (required)
830 * label: The message name for the label (required)
831 * attribs: Additional attributes for the input element (optional)
832 * controlName: The name for the input element (optional)
833 * value: The current value of the variable (optional)
834 * help: The html for the help text (optional)
838 public function getTextArea( $params ) {
839 if ( !isset( $params['controlName'] ) ) {
840 $params['controlName'] = 'config_' . $params['var'];
843 if ( !isset( $params['value'] ) ) {
844 $params['value'] = $this->getVar( $params['var'] );
847 if ( !isset( $params['attribs'] ) ) {
848 $params['attribs'] = [];
850 if ( !isset( $params['help'] ) ) {
851 $params['help'] = "";
856 $params['controlName'],
858 $params['controlName'],
862 $params['attribs'] +
[
863 'id' => $params['controlName'],
864 'class' => 'config-input-text',
865 'tabindex' => $this->nextTabIndex()
873 * Get a labelled password box to configure a variable.
875 * Implements password hiding
876 * @param mixed[] $params
878 * var: The variable to be configured (required)
879 * label: The message name for the label (required)
880 * attribs: Additional attributes for the input element (optional)
881 * controlName: The name for the input element (optional)
882 * value: The current value of the variable (optional)
883 * help: The html for the help text (optional)
887 public function getPasswordBox( $params ) {
888 if ( !isset( $params['value'] ) ) {
889 $params['value'] = $this->getVar( $params['var'] );
892 if ( !isset( $params['attribs'] ) ) {
893 $params['attribs'] = [];
896 $params['value'] = $this->getFakePassword( $params['value'] );
897 $params['attribs']['type'] = 'password';
899 return $this->getTextBox( $params );
903 * Get a labelled checkbox to configure a boolean variable.
905 * @param mixed[] $params
907 * var: The variable to be configured (required)
908 * label: The message name for the label (required)
909 * labelAttribs:Additional attributes for the label element (optional)
910 * attribs: Additional attributes for the input element (optional)
911 * controlName: The name for the input element (optional)
912 * value: The current value of the variable (optional)
913 * help: The html for the help text (optional)
917 public function getCheckBox( $params ) {
918 if ( !isset( $params['controlName'] ) ) {
919 $params['controlName'] = 'config_' . $params['var'];
922 if ( !isset( $params['value'] ) ) {
923 $params['value'] = $this->getVar( $params['var'] );
926 if ( !isset( $params['attribs'] ) ) {
927 $params['attribs'] = [];
929 if ( !isset( $params['help'] ) ) {
930 $params['help'] = "";
932 if ( !isset( $params['labelAttribs'] ) ) {
933 $params['labelAttribs'] = [];
935 if ( isset( $params['rawtext'] ) ) {
936 $labelText = $params['rawtext'];
938 $labelText = $this->parse( wfMessage( $params['label'] )->text() );
941 return "<div class=\"config-input-check\">\n" .
945 $params['labelAttribs'],
947 $params['controlName'],
949 $params['attribs'] +
[
950 'id' => $params['controlName'],
951 'tabindex' => $this->nextTabIndex(),
960 * Get a set of labelled radio buttons.
962 * @param mixed[] $params
964 * var: The variable to be configured (required)
965 * label: The message name for the label (required)
966 * itemLabelPrefix: The message name prefix for the item labels (required)
967 * itemLabels: List of message names to use for the item labels instead
968 * of itemLabelPrefix, keyed by values
969 * values: List of allowed values (required)
970 * itemAttribs: Array of attribute arrays, outer key is the value name (optional)
971 * commonAttribs: Attribute array applied to all items
972 * controlName: The name for the input element (optional)
973 * value: The current value of the variable (optional)
974 * help: The html for the help text (optional)
978 public function getRadioSet( $params ) {
979 $items = $this->getRadioElements( $params );
981 if ( !isset( $params['label'] ) ) {
984 $label = $params['label'];
987 if ( !isset( $params['controlName'] ) ) {
988 $params['controlName'] = 'config_' . $params['var'];
991 if ( !isset( $params['help'] ) ) {
992 $params['help'] = "";
996 foreach ( $items as $value => $item ) {
997 $s .= "<li>$item</li>\n";
1001 return $this->label( $label, $params['controlName'], $s, $params['help'] );
1005 * Get a set of labelled radio buttons. You probably want to use getRadioSet(), not this.
1009 * @param mixed[] $params
1012 public function getRadioElements( $params ) {
1013 if ( !isset( $params['controlName'] ) ) {
1014 $params['controlName'] = 'config_' . $params['var'];
1017 if ( !isset( $params['value'] ) ) {
1018 $params['value'] = $this->getVar( $params['var'] );
1023 foreach ( $params['values'] as $value ) {
1026 if ( isset( $params['commonAttribs'] ) ) {
1027 $itemAttribs = $params['commonAttribs'];
1030 if ( isset( $params['itemAttribs'][$value] ) ) {
1031 $itemAttribs = $params['itemAttribs'][$value] +
$itemAttribs;
1034 $checked = $value == $params['value'];
1035 $id = $params['controlName'] . '_' . $value;
1036 $itemAttribs['id'] = $id;
1037 $itemAttribs['tabindex'] = $this->nextTabIndex();
1040 Xml
::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
1042 Xml
::tags( 'label', [ 'for' => $id ], $this->parse(
1043 isset( $params['itemLabels'] ) ?
1044 wfMessage( $params['itemLabels'][$value] )->plain() :
1045 wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
1053 * Output an error or warning box using a Status object.
1055 * @param Status $status
1057 public function showStatusBox( $status ) {
1058 if ( !$status->isGood() ) {
1059 $text = $status->getWikiText();
1061 if ( $status->isOK() ) {
1062 $box = $this->getWarningBox( $text );
1064 $box = $this->getErrorBox( $text );
1067 $this->output
->addHTML( $box );
1072 * Convenience function to set variables based on form data.
1073 * Assumes that variables containing "password" in the name are (potentially
1076 * @param string[] $varNames
1077 * @param string $prefix The prefix added to variables to obtain form names
1081 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
1084 foreach ( $varNames as $name ) {
1085 $value = $this->request
->getVal( $prefix . $name );
1086 // T32524, do not trim passwords
1087 if ( stripos( $name, 'password' ) === false ) {
1088 $value = trim( $value );
1090 $newValues[$name] = $value;
1092 if ( $value === null ) {
1094 $this->setVar( $name, false );
1096 if ( stripos( $name, 'password' ) !== false ) {
1097 $this->setPassword( $name, $value );
1099 $this->setVar( $name, $value );
1108 * Helper for Installer::docLink()
1110 * @param string $page
1114 protected function getDocUrl( $page ) {
1115 $query = [ 'page' => $page ];
1117 if ( in_array( $this->currentPageName
, $this->pageSequence
) ) {
1118 $query['lastPage'] = $this->currentPageName
;
1121 return $this->getUrl( $query );
1125 * Extension tag hook for a documentation link.
1127 * @param string $linkText
1128 * @param string[] $attribs
1129 * @param Parser $parser Unused
1133 public function docLink( $linkText, $attribs, $parser ) {
1134 $url = $this->getDocUrl( $attribs['href'] );
1136 return Html
::element( 'a', [ 'href' => $url ], $linkText );
1140 * Helper for "Download LocalSettings" link on WebInstall_Complete
1142 * @param string $text Unused
1143 * @param string[] $attribs Unused
1144 * @param Parser $parser Unused
1146 * @return string Html for download link
1148 public function downloadLinkHook( $text, $attribs, $parser ) {
1149 $anchor = Html
::rawElement( 'a',
1150 [ 'href' => $this->getUrl( [ 'localsettings' => 1 ] ) ],
1151 wfMessage( 'config-download-localsettings' )->parse()
1154 return Html
::rawElement( 'div', [ 'class' => 'config-download-link' ], $anchor );
1158 * If the software package wants the LocalSettings.php file
1159 * to be placed in a specific location, override this function
1160 * (see mw-config/overrides/README) to return the path of
1161 * where the file should be saved, or false for a generic
1162 * "in the base of your install"
1165 * @return string|bool
1167 public function getLocalSettingsLocation() {
1174 public function envCheckPath() {
1175 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1176 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1177 // to get the path to the current script... hopefully it's reliable. SIGH
1179 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1180 $path = $_SERVER['PHP_SELF'];
1181 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1182 $path = $_SERVER['SCRIPT_NAME'];
1184 if ( $path === false ) {
1185 $this->showError( 'config-no-uri' );
1189 return parent
::envCheckPath();
1192 public function envPrepPath() {
1193 parent
::envPrepPath();
1194 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1195 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1196 // to get the path to the current script... hopefully it's reliable. SIGH
1198 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1199 $path = $_SERVER['PHP_SELF'];
1200 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1201 $path = $_SERVER['SCRIPT_NAME'];
1203 if ( $path !== false ) {
1204 $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
1206 $this->setVar( 'wgScriptPath', "$scriptPath" );
1207 // Update variables set from Setup.php that are derived from wgScriptPath
1208 $this->setVar( 'wgScript', "$scriptPath/index.php" );
1209 $this->setVar( 'wgLoadScript', "$scriptPath/load.php" );
1210 $this->setVar( 'wgStylePath', "$scriptPath/skins" );
1211 $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
1212 $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
1213 $this->setVar( 'wgUploadPath', "$scriptPath/images" );
1214 $this->setVar( 'wgResourceBasePath', "$scriptPath" );
1221 protected function envGetDefaultServer() {
1222 return WebRequest
::detectServer();
1226 * Actually output LocalSettings.php for download
1228 * @suppress SecurityCheck-XSS
1230 private function outputLS() {
1231 $this->request
->response()->header( 'Content-type: application/x-httpd-php' );
1232 $this->request
->response()->header(
1233 'Content-Disposition: attachment; filename="LocalSettings.php"'
1236 $ls = InstallerOverrides
::getLocalSettingsGenerator( $this );
1237 $rightsProfile = $this->rightsProfiles
[$this->getVar( '_RightsProfile' )];
1238 foreach ( $rightsProfile as $group => $rightsArr ) {
1239 $ls->setGroupRights( $group, $rightsArr );
1241 echo $ls->getText();
1245 * Output stylesheet for web installer pages
1247 public function outputCss() {
1248 $this->request
->response()->header( 'Content-type: text/css' );
1249 echo $this->output
->getCSS();
1255 public function getPhpErrors() {
1256 return $this->phpErrors
;