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' )
169 $this->request
->response()->header( 'Content-type: application/x-httpd-php' );
170 $this->request
->response()->header(
171 'Content-Disposition: attachment; filename="LocalSettings.php"'
174 $ls = InstallerOverrides
::getLocalSettingsGenerator( $this );
175 $rightsProfile = $this->rightsProfiles
[$this->getVar( '_RightsProfile' )];
176 foreach ( $rightsProfile as $group => $rightsArr ) {
177 $ls->setGroupRights( $group, $rightsArr );
181 return $this->session
;
184 $isCSS = $this->request
->getVal( 'css' );
187 return $this->session
;
190 if ( isset( $session['happyPages'] ) ) {
191 $this->happyPages
= $session['happyPages'];
193 $this->happyPages
= [];
196 if ( isset( $session['skippedPages'] ) ) {
197 $this->skippedPages
= $session['skippedPages'];
199 $this->skippedPages
= [];
202 $lowestUnhappy = $this->getLowestUnhappy();
204 # Special case for Creative Commons partner chooser box.
205 if ( $this->request
->getVal( 'SubmitCC' ) ) {
206 $page = $this->getPageByName( 'Options' );
207 $this->output
->useShortHeader();
208 $this->output
->allowFrames();
211 return $this->finish();
214 if ( $this->request
->getVal( 'ShowCC' ) ) {
215 $page = $this->getPageByName( 'Options' );
216 $this->output
->useShortHeader();
217 $this->output
->allowFrames();
218 $this->output
->addHTML( $page->getCCDoneBox() );
220 return $this->finish();
224 $pageName = $this->request
->getVal( 'page' );
226 if ( in_array( $pageName, $this->otherPages
) ) {
229 $page = $this->getPageByName( $pageName );
232 if ( !$pageName ||
!in_array( $pageName, $this->pageSequence
) ) {
233 $pageId = $lowestUnhappy;
235 $pageId = array_search( $pageName, $this->pageSequence
);
238 # If necessary, move back to the lowest-numbered unhappy page
239 if ( $pageId > $lowestUnhappy ) {
240 $pageId = $lowestUnhappy;
241 if ( $lowestUnhappy == 0 ) {
242 # Knocked back to start, possible loss of session data.
243 $this->showSessionWarning
= true;
247 $pageName = $this->pageSequence
[$pageId];
248 $page = $this->getPageByName( $pageName );
251 # If a back button was submitted, go back without submitting the form data.
252 if ( $this->request
->wasPosted() && $this->request
->getBool( 'submit-back' ) ) {
253 if ( $this->request
->getVal( 'lastPage' ) ) {
254 $nextPage = $this->request
->getVal( 'lastPage' );
255 } elseif ( $pageId !== false ) {
257 # Skip the skipped pages
258 $nextPageId = $pageId;
262 $nextPage = $this->pageSequence
[$nextPageId];
263 } while ( isset( $this->skippedPages
[$nextPage] ) );
265 $nextPage = $this->pageSequence
[$lowestUnhappy];
268 $this->output
->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
270 return $this->finish();
274 $this->currentPageName
= $page->getName();
275 $this->startPageWrapper( $pageName );
277 if ( $page->isSlow() ) {
278 $this->disableTimeLimit();
281 $result = $page->execute();
283 $this->endPageWrapper();
285 if ( $result == 'skip' ) {
286 # Page skipped without explicit submission.
287 # Skip it when we click "back" so that we don't just go forward again.
288 $this->skippedPages
[$pageName] = true;
289 $result = 'continue';
291 unset( $this->skippedPages
[$pageName] );
294 # If it was posted, the page can request a continue to the next page.
295 if ( $result === 'continue' && !$this->output
->headerDone() ) {
296 if ( $pageId !== false ) {
297 $this->happyPages
[$pageId] = true;
300 $lowestUnhappy = $this->getLowestUnhappy();
302 if ( $this->request
->getVal( 'lastPage' ) ) {
303 $nextPage = $this->request
->getVal( 'lastPage' );
304 } elseif ( $pageId !== false ) {
305 $nextPage = $this->pageSequence
[$pageId +
1];
307 $nextPage = $this->pageSequence
[$lowestUnhappy];
310 if ( array_search( $nextPage, $this->pageSequence
) > $lowestUnhappy ) {
311 $nextPage = $this->pageSequence
[$lowestUnhappy];
314 $this->output
->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
317 return $this->finish();
321 * Find the next page in sequence that hasn't been completed
324 public function getLowestUnhappy() {
325 if ( count( $this->happyPages
) == 0 ) {
328 return max( array_keys( $this->happyPages
) ) +
1;
333 * Start the PHP session. This may be called before execute() to start the PHP session.
338 public function startSession() {
339 if ( wfIniGetBool( 'session.auto_start' ) ||
session_id() ) {
344 // Use secure cookies if we are on HTTPS
346 if ( $this->request
->getProtocol() === 'https' ) {
347 $options['cookie_secure'] = '1';
350 $this->phpErrors
= [];
351 set_error_handler( [ $this, 'errorHandler' ] );
353 session_name( 'mw_installer_session' );
354 session_start( $options );
355 } catch ( Exception
$e ) {
356 restore_error_handler();
359 restore_error_handler();
361 if ( $this->phpErrors
) {
369 * Get a hash of data identifying this MW installation.
371 * This is used by mw-config/index.php to prevent multiple installations of MW
372 * on the same cookie domain from interfering with each other.
376 public function getFingerprint() {
377 // Get the base URL of the installation
378 $url = $this->request
->getFullRequestURL();
379 if ( preg_match( '!^(.*\?)!', $url, $m ) ) {
383 if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
384 // This... seems to try to get the base path from
385 // the /mw-config/index.php. Kinda scary though?
389 return md5( serialize( [
390 'local path' => dirname( __DIR__
),
392 'version' => $GLOBALS['wgVersion']
397 * Show an error message in a box. Parameters are like wfMessage(), or
398 * alternatively, pass a Message object in.
399 * @param string|Message $msg
401 public function showError( $msg /*...*/ ) {
402 if ( !( $msg instanceof Message
) ) {
403 $args = func_get_args();
404 array_shift( $args );
405 $args = array_map( 'htmlspecialchars', $args );
406 $msg = wfMessage( $msg, $args );
408 $text = $msg->useDatabase( false )->plain();
409 $this->output
->addHTML( $this->getErrorBox( $text ) );
413 * Temporary error handler for session start debugging.
415 * @param int $errno Unused
416 * @param string $errstr
418 public function errorHandler( $errno, $errstr ) {
419 $this->phpErrors
[] = $errstr;
423 * Clean up from execute()
427 public function finish() {
428 $this->output
->output();
430 $this->session
['happyPages'] = $this->happyPages
;
431 $this->session
['skippedPages'] = $this->skippedPages
;
432 $this->session
['settings'] = $this->settings
;
434 return $this->session
;
438 * We're restarting the installation, reset the session, happyPages, etc
440 public function reset() {
442 $this->happyPages
= [];
443 $this->settings
= [];
447 * Get a URL for submission back to the same script.
449 * @param string[] $query
453 public function getUrl( $query = [] ) {
454 $url = $this->request
->getRequestURL();
455 # Remove existing query
456 $url = preg_replace( '/\?.*$/', '', $url );
459 $url .= '?' . wfArrayToCgi( $query );
466 * Get a WebInstallerPage by name.
468 * @param string $pageName
469 * @return WebInstallerPage
471 public function getPageByName( $pageName ) {
472 $pageClass = 'WebInstaller' . $pageName;
474 return new $pageClass( $this );
478 * Get a session variable.
480 * @param string $name
481 * @param array $default
485 public function getSession( $name, $default = null ) {
486 if ( !isset( $this->session
[$name] ) ) {
489 return $this->session
[$name];
494 * Set a session variable.
496 * @param string $name Key for the variable
497 * @param mixed $value
499 public function setSession( $name, $value ) {
500 $this->session
[$name] = $value;
504 * Get the next tabindex attribute value.
508 public function nextTabIndex() {
509 return $this->tabIndex++
;
513 * Initializes language-related variables.
515 public function setupLanguage() {
516 global $wgLang, $wgContLang, $wgLanguageCode;
518 if ( $this->getSession( 'test' ) === null && !$this->request
->wasPosted() ) {
519 $wgLanguageCode = $this->getAcceptLanguage();
520 $wgLang = $wgContLang = Language
::factory( $wgLanguageCode );
521 RequestContext
::getMain()->setLanguage( $wgLang );
522 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
523 $this->setVar( '_UserLang', $wgLanguageCode );
525 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
526 $wgContLang = Language
::factory( $wgLanguageCode );
531 * Retrieves MediaWiki language from Accept-Language HTTP header.
535 public function getAcceptLanguage() {
536 global $wgLanguageCode, $wgRequest;
538 $mwLanguages = Language
::fetchLanguageNames();
539 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
541 foreach ( $headerLanguages as $lang ) {
542 if ( isset( $mwLanguages[$lang] ) ) {
547 return $wgLanguageCode;
551 * Called by execute() before page output starts, to show a page list.
553 * @param string $currentPageName
555 private function startPageWrapper( $currentPageName ) {
556 $s = "<div class=\"config-page-wrapper\">\n";
557 $s .= "<div class=\"config-page\">\n";
558 $s .= "<div class=\"config-page-list\"><ul>\n";
561 foreach ( $this->pageSequence
as $id => $pageName ) {
562 $happy = !empty( $this->happyPages
[$id] );
563 $s .= $this->getPageListItem(
565 $happy ||
$lastHappy == $id - 1,
574 $s .= "</ul><br/><ul>\n";
575 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
577 $s .= "</ul></div>\n";
580 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
581 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
582 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
583 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
584 $s .= Html
::element( 'h2', [],
585 wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
587 $this->output
->addHTMLNoFlush( $s );
591 * Get a list item for the page list.
593 * @param string $pageName
594 * @param bool $enabled
595 * @param string $currentPageName
599 private function getPageListItem( $pageName, $enabled, $currentPageName ) {
600 $s = "<li class=\"config-page-list-item\">";
603 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
604 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
605 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
606 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
607 $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
610 $query = [ 'page' => $pageName ];
612 if ( !in_array( $pageName, $this->pageSequence
) ) {
613 if ( in_array( $currentPageName, $this->pageSequence
) ) {
614 $query['lastPage'] = $currentPageName;
617 $link = Html
::element( 'a',
619 'href' => $this->getUrl( $query )
624 $link = htmlspecialchars( $name );
627 if ( $pageName == $currentPageName ) {
628 $s .= "<span class=\"config-page-current\">$link</span>";
633 $s .= Html
::element( 'span',
635 'class' => 'config-page-disabled'
647 * Output some stuff after a page is finished.
649 private function endPageWrapper() {
650 $this->output
->addHTMLNoFlush(
651 "<div class=\"visualClear\"></div>\n" .
653 "<div class=\"visualClear\"></div>\n" .
658 * Get HTML for an error box with an icon.
660 * @param string $text Wikitext, get this with wfMessage()->plain()
664 public function getErrorBox( $text ) {
665 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
669 * Get HTML for a warning box with an icon.
671 * @param string $text Wikitext, get this with wfMessage()->plain()
675 public function getWarningBox( $text ) {
676 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
680 * Get HTML for an info box with an icon.
682 * @param string $text Wikitext, get this with wfMessage()->plain()
683 * @param string|bool $icon Icon name, file in mw-config/images. Default: false
684 * @param string|bool $class Additional class name to add to the wrapper div. Default: false.
688 public function getInfoBox( $text, $icon = false, $class = false ) {
689 $text = $this->parse( $text, true );
690 $icon = ( $icon == false ) ?
691 'images/info-32.png' :
693 $alt = wfMessage( 'config-information' )->text();
695 return Html
::infoBox( $text, $icon, $alt, $class );
699 * Get small text indented help for a preceding form field.
700 * Parameters like wfMessage().
705 public function getHelpBox( $msg /*, ... */ ) {
706 $args = func_get_args();
707 array_shift( $args );
708 $args = array_map( 'htmlspecialchars', $args );
709 $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
710 $html = $this->parse( $text, true );
712 return "<div class=\"config-help-field-container\">\n" .
713 "<span class=\"config-help-field-hint\" title=\"" .
714 wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
715 wfMessage( 'config-help' )->escaped() . "</span>\n" .
716 "<div class=\"config-help-field-data\">" . $html . "</div>\n" .
722 * @param string $msg Key for wfMessage()
724 public function showHelpBox( $msg /*, ... */ ) {
725 $args = func_get_args();
726 $html = call_user_func_array( [ $this, 'getHelpBox' ], $args );
727 $this->output
->addHTML( $html );
731 * Show a short informational message.
732 * Output looks like a list.
736 public function showMessage( $msg /*, ... */ ) {
737 $args = func_get_args();
738 array_shift( $args );
739 $html = '<div class="config-message">' .
740 $this->parse( wfMessage( $msg, $args )->useDatabase( false )->plain() ) .
742 $this->output
->addHTML( $html );
746 * @param Status $status
748 public function showStatusMessage( Status
$status ) {
749 $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
750 foreach ( $errors as $error ) {
751 call_user_func_array( [ $this, 'showMessage' ], $error );
756 * Label a control by wrapping a config-input div around it and putting a
760 * @param string $forId
761 * @param string $contents
762 * @param string $helpData
765 public function label( $msg, $forId, $contents, $helpData = "" ) {
766 if ( strval( $msg ) == '' ) {
767 $labelText = ' ';
769 $labelText = wfMessage( $msg )->escaped();
772 $attributes = [ 'class' => 'config-label' ];
775 $attributes['for'] = $forId;
778 return "<div class=\"config-block\">\n" .
779 " <div class=\"config-block-label\">\n" .
786 " <div class=\"config-block-elements\">\n" .
793 * Get a labelled text box to configure a variable.
795 * @param mixed[] $params
797 * var: The variable to be configured (required)
798 * label: The message name for the label (required)
799 * attribs: Additional attributes for the input element (optional)
800 * controlName: The name for the input element (optional)
801 * value: The current value of the variable (optional)
802 * help: The html for the help text (optional)
806 public function getTextBox( $params ) {
807 if ( !isset( $params['controlName'] ) ) {
808 $params['controlName'] = 'config_' . $params['var'];
811 if ( !isset( $params['value'] ) ) {
812 $params['value'] = $this->getVar( $params['var'] );
815 if ( !isset( $params['attribs'] ) ) {
816 $params['attribs'] = [];
818 if ( !isset( $params['help'] ) ) {
819 $params['help'] = "";
824 $params['controlName'],
826 $params['controlName'],
827 30, // intended to be overridden by CSS
829 $params['attribs'] +
[
830 'id' => $params['controlName'],
831 'class' => 'config-input-text',
832 'tabindex' => $this->nextTabIndex()
840 * Get a labelled textarea to configure a variable
842 * @param mixed[] $params
844 * var: The variable to be configured (required)
845 * label: The message name for the label (required)
846 * attribs: Additional attributes for the input element (optional)
847 * controlName: The name for the input element (optional)
848 * value: The current value of the variable (optional)
849 * help: The html for the help text (optional)
853 public function getTextArea( $params ) {
854 if ( !isset( $params['controlName'] ) ) {
855 $params['controlName'] = 'config_' . $params['var'];
858 if ( !isset( $params['value'] ) ) {
859 $params['value'] = $this->getVar( $params['var'] );
862 if ( !isset( $params['attribs'] ) ) {
863 $params['attribs'] = [];
865 if ( !isset( $params['help'] ) ) {
866 $params['help'] = "";
871 $params['controlName'],
873 $params['controlName'],
877 $params['attribs'] +
[
878 'id' => $params['controlName'],
879 'class' => 'config-input-text',
880 'tabindex' => $this->nextTabIndex()
888 * Get a labelled password box to configure a variable.
890 * Implements password hiding
891 * @param mixed[] $params
893 * var: The variable to be configured (required)
894 * label: The message name for the label (required)
895 * attribs: Additional attributes for the input element (optional)
896 * controlName: The name for the input element (optional)
897 * value: The current value of the variable (optional)
898 * help: The html for the help text (optional)
902 public function getPasswordBox( $params ) {
903 if ( !isset( $params['value'] ) ) {
904 $params['value'] = $this->getVar( $params['var'] );
907 if ( !isset( $params['attribs'] ) ) {
908 $params['attribs'] = [];
911 $params['value'] = $this->getFakePassword( $params['value'] );
912 $params['attribs']['type'] = 'password';
914 return $this->getTextBox( $params );
918 * Get a labelled checkbox to configure a boolean variable.
920 * @param mixed[] $params
922 * var: The variable to be configured (required)
923 * label: The message name for the label (required)
924 * labelAttribs:Additional attributes for the label element (optional)
925 * attribs: Additional attributes for the input element (optional)
926 * controlName: The name for the input element (optional)
927 * value: The current value of the variable (optional)
928 * help: The html for the help text (optional)
932 public function getCheckBox( $params ) {
933 if ( !isset( $params['controlName'] ) ) {
934 $params['controlName'] = 'config_' . $params['var'];
937 if ( !isset( $params['value'] ) ) {
938 $params['value'] = $this->getVar( $params['var'] );
941 if ( !isset( $params['attribs'] ) ) {
942 $params['attribs'] = [];
944 if ( !isset( $params['help'] ) ) {
945 $params['help'] = "";
947 if ( !isset( $params['labelAttribs'] ) ) {
948 $params['labelAttribs'] = [];
950 if ( isset( $params['rawtext'] ) ) {
951 $labelText = $params['rawtext'];
953 $labelText = $this->parse( wfMessage( $params['label'] )->text() );
956 return "<div class=\"config-input-check\">\n" .
960 $params['labelAttribs'],
962 $params['controlName'],
964 $params['attribs'] +
[
965 'id' => $params['controlName'],
966 'tabindex' => $this->nextTabIndex(),
975 * Get a set of labelled radio buttons.
977 * @param mixed[] $params
979 * var: The variable to be configured (required)
980 * label: The message name for the label (required)
981 * itemLabelPrefix: The message name prefix for the item labels (required)
982 * itemLabels: List of message names to use for the item labels instead
983 * of itemLabelPrefix, keyed by values
984 * values: List of allowed values (required)
985 * itemAttribs: Array of attribute arrays, outer key is the value name (optional)
986 * commonAttribs: Attribute array applied to all items
987 * controlName: The name for the input element (optional)
988 * value: The current value of the variable (optional)
989 * help: The html for the help text (optional)
993 public function getRadioSet( $params ) {
994 $items = $this->getRadioElements( $params );
996 if ( !isset( $params['label'] ) ) {
999 $label = $params['label'];
1002 if ( !isset( $params['controlName'] ) ) {
1003 $params['controlName'] = 'config_' . $params['var'];
1006 if ( !isset( $params['help'] ) ) {
1007 $params['help'] = "";
1011 foreach ( $items as $value => $item ) {
1012 $s .= "<li>$item</li>\n";
1016 return $this->label( $label, $params['controlName'], $s, $params['help'] );
1020 * Get a set of labelled radio buttons. You probably want to use getRadioSet(), not this.
1024 * @param mixed[] $params
1027 public function getRadioElements( $params ) {
1028 if ( !isset( $params['controlName'] ) ) {
1029 $params['controlName'] = 'config_' . $params['var'];
1032 if ( !isset( $params['value'] ) ) {
1033 $params['value'] = $this->getVar( $params['var'] );
1038 foreach ( $params['values'] as $value ) {
1041 if ( isset( $params['commonAttribs'] ) ) {
1042 $itemAttribs = $params['commonAttribs'];
1045 if ( isset( $params['itemAttribs'][$value] ) ) {
1046 $itemAttribs = $params['itemAttribs'][$value] +
$itemAttribs;
1049 $checked = $value == $params['value'];
1050 $id = $params['controlName'] . '_' . $value;
1051 $itemAttribs['id'] = $id;
1052 $itemAttribs['tabindex'] = $this->nextTabIndex();
1055 Xml
::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
1057 Xml
::tags( 'label', [ 'for' => $id ], $this->parse(
1058 isset( $params['itemLabels'] ) ?
1059 wfMessage( $params['itemLabels'][$value] )->plain() :
1060 wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
1068 * Output an error or warning box using a Status object.
1070 * @param Status $status
1072 public function showStatusBox( $status ) {
1073 if ( !$status->isGood() ) {
1074 $text = $status->getWikiText();
1076 if ( $status->isOK() ) {
1077 $box = $this->getWarningBox( $text );
1079 $box = $this->getErrorBox( $text );
1082 $this->output
->addHTML( $box );
1087 * Convenience function to set variables based on form data.
1088 * Assumes that variables containing "password" in the name are (potentially
1091 * @param string[] $varNames
1092 * @param string $prefix The prefix added to variables to obtain form names
1096 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
1099 foreach ( $varNames as $name ) {
1100 $value = $this->request
->getVal( $prefix . $name );
1101 // T32524, do not trim passwords
1102 if ( stripos( $name, 'password' ) === false ) {
1103 $value = trim( $value );
1105 $newValues[$name] = $value;
1107 if ( $value === null ) {
1109 $this->setVar( $name, false );
1111 if ( stripos( $name, 'password' ) !== false ) {
1112 $this->setPassword( $name, $value );
1114 $this->setVar( $name, $value );
1123 * Helper for Installer::docLink()
1125 * @param string $page
1129 protected function getDocUrl( $page ) {
1130 $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
1132 if ( in_array( $this->currentPageName
, $this->pageSequence
) ) {
1133 $url .= '&lastPage=' . urlencode( $this->currentPageName
);
1140 * Extension tag hook for a documentation link.
1142 * @param string $linkText
1143 * @param string[] $attribs
1144 * @param Parser $parser Unused
1148 public function docLink( $linkText, $attribs, $parser ) {
1149 $url = $this->getDocUrl( $attribs['href'] );
1151 return '<a href="' . htmlspecialchars( $url ) . '">' .
1152 htmlspecialchars( $linkText ) .
1157 * Helper for "Download LocalSettings" link on WebInstall_Complete
1159 * @param string $text Unused
1160 * @param string[] $attribs Unused
1161 * @param Parser $parser Unused
1163 * @return string Html for download link
1165 public function downloadLinkHook( $text, $attribs, $parser ) {
1166 $anchor = Html
::rawElement( 'a',
1167 [ 'href' => $this->getUrl( [ 'localsettings' => 1 ] ) ],
1168 wfMessage( 'config-download-localsettings' )->parse()
1171 return Html
::rawElement( 'div', [ 'class' => 'config-download-link' ], $anchor );
1175 * If the software package wants the LocalSettings.php file
1176 * to be placed in a specific location, override this function
1177 * (see mw-config/overrides/README) to return the path of
1178 * where the file should be saved, or false for a generic
1179 * "in the base of your install"
1182 * @return string|bool
1184 public function getLocalSettingsLocation() {
1191 public function envCheckPath() {
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 $this->showError( 'config-no-uri' );
1206 return parent
::envCheckPath();
1209 public function envPrepPath() {
1210 parent
::envPrepPath();
1211 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1212 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1213 // to get the path to the current script... hopefully it's reliable. SIGH
1215 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1216 $path = $_SERVER['PHP_SELF'];
1217 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1218 $path = $_SERVER['SCRIPT_NAME'];
1220 if ( $path !== false ) {
1221 $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
1223 $this->setVar( 'wgScriptPath', "$scriptPath" );
1224 // Update variables set from Setup.php that are derived from wgScriptPath
1225 $this->setVar( 'wgScript', "$scriptPath/index.php" );
1226 $this->setVar( 'wgLoadScript', "$scriptPath/load.php" );
1227 $this->setVar( 'wgStylePath', "$scriptPath/skins" );
1228 $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
1229 $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
1230 $this->setVar( 'wgUploadPath', "$scriptPath/images" );
1231 $this->setVar( 'wgResourceBasePath', "$scriptPath" );
1238 protected function envGetDefaultServer() {
1239 return WebRequest
::detectServer();
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
;