Merge "Remove not used private member variable mParserWarnings from OutputPage"
[mediawiki.git] / includes / installer / WebInstaller.php
blobe8433f2a97764b2d5b6357a987212301fea04cf1
1 <?php
2 /**
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
20 * @file
21 * @ingroup Deployment
24 /**
25 * Class for the core installer web interface.
27 * @ingroup Deployment
28 * @since 1.17
30 class WebInstaller extends Installer {
32 /**
33 * @var WebInstallerOutput
35 public $output;
37 /**
38 * WebRequest object.
40 * @var WebRequest
42 public $request;
44 /**
45 * Cached session array.
47 * @var array[]
49 protected $session;
51 /**
52 * Captured PHP error text. Temporary.
54 * @var string[]
56 protected $phpErrors;
58 /**
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
66 * @var string[]
68 public $pageSequence = array(
69 'Language',
70 'ExistingWiki',
71 'Welcome',
72 'DBConnect',
73 'Upgrade',
74 'DBSettings',
75 'Name',
76 'Options',
77 'Install',
78 'Complete',
81 /**
82 * Out of sequence pages, selectable by the user at any time.
84 * @var string[]
86 protected $otherPages = array(
87 'Restart',
88 'Readme',
89 'ReleaseNotes',
90 'Copying',
91 'UpgradeDoc', // Can't use Upgrade due to Upgrade step
94 /**
95 * Array of pages which have declared that they have been submitted, have validated
96 * their input, and need no further processing.
98 * @var bool[]
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.
107 * @var bool[]
109 protected $skippedPages;
112 * Flag indicating that session data may have been lost.
114 * @var bool
116 public $showSessionWarning = false;
119 * Numeric index of the page we're on
121 * @var int
123 protected $tabIndex = 1;
126 * Name of the page we're on
128 * @var string
130 protected $currentPageName;
133 * Constructor.
135 * @param WebRequest $request
137 public function __construct( WebRequest $request ) {
138 parent::__construct();
139 $this->output = new WebInstallerOutput( $this );
140 $this->request = $request;
142 // Add parser hooks
143 global $wgParser;
144 $wgParser->setHook( 'downloadlink', array( $this, 'downloadLinkHook' ) );
145 $wgParser->setHook( 'doclink', array( $this, 'docLink' ) );
149 * Main entry point.
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;
162 $this->setupLanguage();
164 if ( ( $this->getVar( '_InstallDone' ) || $this->getVar( '_UpgradeDone' ) )
165 && $this->request->getVal( 'localsettings' )
167 $this->request->response()->header( 'Content-type: application/x-httpd-php' );
168 $this->request->response()->header(
169 'Content-Disposition: attachment; filename="LocalSettings.php"'
172 $ls = InstallerOverrides::getLocalSettingsGenerator( $this );
173 $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )];
174 foreach ( $rightsProfile as $group => $rightsArr ) {
175 $ls->setGroupRights( $group, $rightsArr );
177 echo $ls->getText();
179 return $this->session;
182 $isCSS = $this->request->getVal( 'css' );
183 if ( $isCSS ) {
184 $this->outputCss();
185 return $this->session;
188 if ( isset( $session['happyPages'] ) ) {
189 $this->happyPages = $session['happyPages'];
190 } else {
191 $this->happyPages = array();
194 if ( isset( $session['skippedPages'] ) ) {
195 $this->skippedPages = $session['skippedPages'];
196 } else {
197 $this->skippedPages = array();
200 $lowestUnhappy = $this->getLowestUnhappy();
202 # Special case for Creative Commons partner chooser box.
203 if ( $this->request->getVal( 'SubmitCC' ) ) {
204 $page = $this->getPageByName( 'Options' );
205 $this->output->useShortHeader();
206 $this->output->allowFrames();
207 $page->submitCC();
209 return $this->finish();
212 if ( $this->request->getVal( 'ShowCC' ) ) {
213 $page = $this->getPageByName( 'Options' );
214 $this->output->useShortHeader();
215 $this->output->allowFrames();
216 $this->output->addHTML( $page->getCCDoneBox() );
218 return $this->finish();
221 # Get the page name.
222 $pageName = $this->request->getVal( 'page' );
224 if ( in_array( $pageName, $this->otherPages ) ) {
225 # Out of sequence
226 $pageId = false;
227 $page = $this->getPageByName( $pageName );
228 } else {
229 # Main sequence
230 if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) {
231 $pageId = $lowestUnhappy;
232 } else {
233 $pageId = array_search( $pageName, $this->pageSequence );
236 # If necessary, move back to the lowest-numbered unhappy page
237 if ( $pageId > $lowestUnhappy ) {
238 $pageId = $lowestUnhappy;
239 if ( $lowestUnhappy == 0 ) {
240 # Knocked back to start, possible loss of session data.
241 $this->showSessionWarning = true;
245 $pageName = $this->pageSequence[$pageId];
246 $page = $this->getPageByName( $pageName );
249 # If a back button was submitted, go back without submitting the form data.
250 if ( $this->request->wasPosted() && $this->request->getBool( 'submit-back' ) ) {
251 if ( $this->request->getVal( 'lastPage' ) ) {
252 $nextPage = $this->request->getVal( 'lastPage' );
253 } elseif ( $pageId !== false ) {
254 # Main sequence page
255 # Skip the skipped pages
256 $nextPageId = $pageId;
258 do {
259 $nextPageId--;
260 $nextPage = $this->pageSequence[$nextPageId];
261 } while ( isset( $this->skippedPages[$nextPage] ) );
262 } else {
263 $nextPage = $this->pageSequence[$lowestUnhappy];
266 $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
268 return $this->finish();
271 # Execute the page.
272 $this->currentPageName = $page->getName();
273 $this->startPageWrapper( $pageName );
275 if ( $page->isSlow() ) {
276 $this->disableTimeLimit();
279 $result = $page->execute();
281 $this->endPageWrapper();
283 if ( $result == 'skip' ) {
284 # Page skipped without explicit submission.
285 # Skip it when we click "back" so that we don't just go forward again.
286 $this->skippedPages[$pageName] = true;
287 $result = 'continue';
288 } else {
289 unset( $this->skippedPages[$pageName] );
292 # If it was posted, the page can request a continue to the next page.
293 if ( $result === 'continue' && !$this->output->headerDone() ) {
294 if ( $pageId !== false ) {
295 $this->happyPages[$pageId] = true;
298 $lowestUnhappy = $this->getLowestUnhappy();
300 if ( $this->request->getVal( 'lastPage' ) ) {
301 $nextPage = $this->request->getVal( 'lastPage' );
302 } elseif ( $pageId !== false ) {
303 $nextPage = $this->pageSequence[$pageId + 1];
304 } else {
305 $nextPage = $this->pageSequence[$lowestUnhappy];
308 if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) {
309 $nextPage = $this->pageSequence[$lowestUnhappy];
312 $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
315 return $this->finish();
319 * Find the next page in sequence that hasn't been completed
320 * @return int
322 public function getLowestUnhappy() {
323 if ( count( $this->happyPages ) == 0 ) {
324 return 0;
325 } else {
326 return max( array_keys( $this->happyPages ) ) + 1;
331 * Start the PHP session. This may be called before execute() to start the PHP session.
333 * @throws Exception
334 * @return bool
336 public function startSession() {
337 if ( wfIniGetBool( 'session.auto_start' ) || session_id() ) {
338 // Done already
339 return true;
342 $this->phpErrors = array();
343 set_error_handler( array( $this, 'errorHandler' ) );
344 try {
345 session_name( 'mw_installer_session' );
346 session_start();
347 } catch ( Exception $e ) {
348 restore_error_handler();
349 throw $e;
351 restore_error_handler();
353 if ( $this->phpErrors ) {
354 return false;
357 return true;
361 * Get a hash of data identifying this MW installation.
363 * This is used by mw-config/index.php to prevent multiple installations of MW
364 * on the same cookie domain from interfering with each other.
366 * @return string
368 public function getFingerprint() {
369 // Get the base URL of the installation
370 $url = $this->request->getFullRequestURL();
371 if ( preg_match( '!^(.*\?)!', $url, $m ) ) {
372 // Trim query string
373 $url = $m[1];
375 if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
376 // This... seems to try to get the base path from
377 // the /mw-config/index.php. Kinda scary though?
378 $url = $m[1];
381 return md5( serialize( array(
382 'local path' => dirname( __DIR__ ),
383 'url' => $url,
384 'version' => $GLOBALS['wgVersion']
385 ) ) );
389 * Show an error message in a box. Parameters are like wfMessage(), or
390 * alternatively, pass a Message object in.
391 * @param string|Message $msg
393 public function showError( $msg /*...*/ ) {
394 if ( !( $msg instanceof Message ) ) {
395 $args = func_get_args();
396 array_shift( $args );
397 $args = array_map( 'htmlspecialchars', $args );
398 $msg = wfMessage( $msg, $args );
400 $text = $msg->useDatabase( false )->plain();
401 $this->output->addHTML( $this->getErrorBox( $text ) );
405 * Temporary error handler for session start debugging.
407 * @param int $errno Unused
408 * @param string $errstr
410 public function errorHandler( $errno, $errstr ) {
411 $this->phpErrors[] = $errstr;
415 * Clean up from execute()
417 * @return array[]
419 public function finish() {
420 $this->output->output();
422 $this->session['happyPages'] = $this->happyPages;
423 $this->session['skippedPages'] = $this->skippedPages;
424 $this->session['settings'] = $this->settings;
426 return $this->session;
430 * We're restarting the installation, reset the session, happyPages, etc
432 public function reset() {
433 $this->session = array();
434 $this->happyPages = array();
435 $this->settings = array();
439 * Get a URL for submission back to the same script.
441 * @param string[] $query
443 * @return string
445 public function getUrl( $query = array() ) {
446 $url = $this->request->getRequestURL();
447 # Remove existing query
448 $url = preg_replace( '/\?.*$/', '', $url );
450 if ( $query ) {
451 $url .= '?' . wfArrayToCgi( $query );
454 return $url;
458 * Get a WebInstallerPage by name.
460 * @param string $pageName
461 * @return WebInstallerPage
463 public function getPageByName( $pageName ) {
464 $pageClass = 'WebInstaller' . $pageName;
466 return new $pageClass( $this );
470 * Get a session variable.
472 * @param string $name
473 * @param array $default
475 * @return array
477 public function getSession( $name, $default = null ) {
478 if ( !isset( $this->session[$name] ) ) {
479 return $default;
480 } else {
481 return $this->session[$name];
486 * Set a session variable.
488 * @param string $name Key for the variable
489 * @param mixed $value
491 public function setSession( $name, $value ) {
492 $this->session[$name] = $value;
496 * Get the next tabindex attribute value.
498 * @return int
500 public function nextTabIndex() {
501 return $this->tabIndex++;
505 * Initializes language-related variables.
507 public function setupLanguage() {
508 global $wgLang, $wgContLang, $wgLanguageCode;
510 if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
511 $wgLanguageCode = $this->getAcceptLanguage();
512 $wgLang = $wgContLang = Language::factory( $wgLanguageCode );
513 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
514 $this->setVar( '_UserLang', $wgLanguageCode );
515 } else {
516 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
517 $wgContLang = Language::factory( $wgLanguageCode );
522 * Retrieves MediaWiki language from Accept-Language HTTP header.
524 * @return string
526 public function getAcceptLanguage() {
527 global $wgLanguageCode, $wgRequest;
529 $mwLanguages = Language::fetchLanguageNames();
530 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
532 foreach ( $headerLanguages as $lang ) {
533 if ( isset( $mwLanguages[$lang] ) ) {
534 return $lang;
538 return $wgLanguageCode;
542 * Called by execute() before page output starts, to show a page list.
544 * @param string $currentPageName
546 private function startPageWrapper( $currentPageName ) {
547 $s = "<div class=\"config-page-wrapper\">\n";
548 $s .= "<div class=\"config-page\">\n";
549 $s .= "<div class=\"config-page-list\"><ul>\n";
550 $lastHappy = -1;
552 foreach ( $this->pageSequence as $id => $pageName ) {
553 $happy = !empty( $this->happyPages[$id] );
554 $s .= $this->getPageListItem(
555 $pageName,
556 $happy || $lastHappy == $id - 1,
557 $currentPageName
560 if ( $happy ) {
561 $lastHappy = $id;
565 $s .= "</ul><br/><ul>\n";
566 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
567 // End list pane
568 $s .= "</ul></div>\n";
570 // Messages:
571 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
572 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
573 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
574 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
575 $s .= Html::element( 'h2', array(),
576 wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
578 $this->output->addHTMLNoFlush( $s );
582 * Get a list item for the page list.
584 * @param string $pageName
585 * @param bool $enabled
586 * @param string $currentPageName
588 * @return string
590 private function getPageListItem( $pageName, $enabled, $currentPageName ) {
591 $s = "<li class=\"config-page-list-item\">";
593 // Messages:
594 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
595 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
596 // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
597 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
598 $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
600 if ( $enabled ) {
601 $query = array( 'page' => $pageName );
603 if ( !in_array( $pageName, $this->pageSequence ) ) {
604 if ( in_array( $currentPageName, $this->pageSequence ) ) {
605 $query['lastPage'] = $currentPageName;
608 $link = Html::element( 'a',
609 array(
610 'href' => $this->getUrl( $query )
612 $name
614 } else {
615 $link = htmlspecialchars( $name );
618 if ( $pageName == $currentPageName ) {
619 $s .= "<span class=\"config-page-current\">$link</span>";
620 } else {
621 $s .= $link;
623 } else {
624 $s .= Html::element( 'span',
625 array(
626 'class' => 'config-page-disabled'
628 $name
632 $s .= "</li>\n";
634 return $s;
638 * Output some stuff after a page is finished.
640 private function endPageWrapper() {
641 $this->output->addHTMLNoFlush(
642 "<div class=\"visualClear\"></div>\n" .
643 "</div>\n" .
644 "<div class=\"visualClear\"></div>\n" .
645 "</div>" );
649 * Get HTML for an error box with an icon.
651 * @param string $text Wikitext, get this with wfMessage()->plain()
653 * @return string
655 public function getErrorBox( $text ) {
656 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
660 * Get HTML for a warning box with an icon.
662 * @param string $text Wikitext, get this with wfMessage()->plain()
664 * @return string
666 public function getWarningBox( $text ) {
667 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
671 * Get HTML for an info box with an icon.
673 * @param string $text Wikitext, get this with wfMessage()->plain()
674 * @param string|bool $icon Icon name, file in mw-config/images. Default: false
675 * @param string|bool $class Additional class name to add to the wrapper div. Default: false.
677 * @return string
679 public function getInfoBox( $text, $icon = false, $class = false ) {
680 $text = $this->parse( $text, true );
681 $icon = ( $icon == false ) ?
682 'images/info-32.png' :
683 'images/' . $icon;
684 $alt = wfMessage( 'config-information' )->text();
686 return Html::infoBox( $text, $icon, $alt, $class );
690 * Get small text indented help for a preceding form field.
691 * Parameters like wfMessage().
693 * @param string $msg
694 * @return string
696 public function getHelpBox( $msg /*, ... */ ) {
697 $args = func_get_args();
698 array_shift( $args );
699 $args = array_map( 'htmlspecialchars', $args );
700 $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
701 $html = $this->parse( $text, true );
703 return "<div class=\"config-help-field-container\">\n" .
704 "<span class=\"config-help-field-hint\" title=\"" .
705 wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
706 wfMessage( 'config-help' )->escaped() . "</span>\n" .
707 "<span class=\"config-help-field-data\">" . $html . "</span>\n" .
708 "</div>\n";
712 * Output a help box.
713 * @param string $msg Key for wfMessage()
715 public function showHelpBox( $msg /*, ... */ ) {
716 $args = func_get_args();
717 $html = call_user_func_array( array( $this, 'getHelpBox' ), $args );
718 $this->output->addHTML( $html );
722 * Show a short informational message.
723 * Output looks like a list.
725 * @param string $msg
727 public function showMessage( $msg /*, ... */ ) {
728 $args = func_get_args();
729 array_shift( $args );
730 $html = '<div class="config-message">' .
731 $this->parse( wfMessage( $msg, $args )->useDatabase( false )->plain() ) .
732 "</div>\n";
733 $this->output->addHTML( $html );
737 * @param Status $status
739 public function showStatusMessage( Status $status ) {
740 $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
741 foreach ( $errors as $error ) {
742 call_user_func_array( array( $this, 'showMessage' ), $error );
747 * Label a control by wrapping a config-input div around it and putting a
748 * label before it.
750 * @param string $msg
751 * @param string $forId
752 * @param string $contents
753 * @param string $helpData
754 * @return string
756 public function label( $msg, $forId, $contents, $helpData = "" ) {
757 if ( strval( $msg ) == '' ) {
758 $labelText = '&#160;';
759 } else {
760 $labelText = wfMessage( $msg )->escaped();
763 $attributes = array( 'class' => 'config-label' );
765 if ( $forId ) {
766 $attributes['for'] = $forId;
769 return "<div class=\"config-block\">\n" .
770 " <div class=\"config-block-label\">\n" .
771 Xml::tags( 'label',
772 $attributes,
773 $labelText
774 ) . "\n" .
775 $helpData .
776 " </div>\n" .
777 " <div class=\"config-block-elements\">\n" .
778 $contents .
779 " </div>\n" .
780 "</div>\n";
784 * Get a labelled text box to configure a variable.
786 * @param mixed[] $params
787 * Parameters are:
788 * var: The variable to be configured (required)
789 * label: The message name for the label (required)
790 * attribs: Additional attributes for the input element (optional)
791 * controlName: The name for the input element (optional)
792 * value: The current value of the variable (optional)
793 * help: The html for the help text (optional)
795 * @return string
797 public function getTextBox( $params ) {
798 if ( !isset( $params['controlName'] ) ) {
799 $params['controlName'] = 'config_' . $params['var'];
802 if ( !isset( $params['value'] ) ) {
803 $params['value'] = $this->getVar( $params['var'] );
806 if ( !isset( $params['attribs'] ) ) {
807 $params['attribs'] = array();
809 if ( !isset( $params['help'] ) ) {
810 $params['help'] = "";
813 return $this->label(
814 $params['label'],
815 $params['controlName'],
816 Xml::input(
817 $params['controlName'],
818 30, // intended to be overridden by CSS
819 $params['value'],
820 $params['attribs'] + array(
821 'id' => $params['controlName'],
822 'class' => 'config-input-text',
823 'tabindex' => $this->nextTabIndex()
826 $params['help']
831 * Get a labelled textarea to configure a variable
833 * @param mixed[] $params
834 * Parameters are:
835 * var: The variable to be configured (required)
836 * label: The message name for the label (required)
837 * attribs: Additional attributes for the input element (optional)
838 * controlName: The name for the input element (optional)
839 * value: The current value of the variable (optional)
840 * help: The html for the help text (optional)
842 * @return string
844 public function getTextArea( $params ) {
845 if ( !isset( $params['controlName'] ) ) {
846 $params['controlName'] = 'config_' . $params['var'];
849 if ( !isset( $params['value'] ) ) {
850 $params['value'] = $this->getVar( $params['var'] );
853 if ( !isset( $params['attribs'] ) ) {
854 $params['attribs'] = array();
856 if ( !isset( $params['help'] ) ) {
857 $params['help'] = "";
860 return $this->label(
861 $params['label'],
862 $params['controlName'],
863 Xml::textarea(
864 $params['controlName'],
865 $params['value'],
868 $params['attribs'] + array(
869 'id' => $params['controlName'],
870 'class' => 'config-input-text',
871 'tabindex' => $this->nextTabIndex()
874 $params['help']
879 * Get a labelled password box to configure a variable.
881 * Implements password hiding
882 * @param mixed[] $params
883 * Parameters are:
884 * var: The variable to be configured (required)
885 * label: The message name for the label (required)
886 * attribs: Additional attributes for the input element (optional)
887 * controlName: The name for the input element (optional)
888 * value: The current value of the variable (optional)
889 * help: The html for the help text (optional)
891 * @return string
893 public function getPasswordBox( $params ) {
894 if ( !isset( $params['value'] ) ) {
895 $params['value'] = $this->getVar( $params['var'] );
898 if ( !isset( $params['attribs'] ) ) {
899 $params['attribs'] = array();
902 $params['value'] = $this->getFakePassword( $params['value'] );
903 $params['attribs']['type'] = 'password';
905 return $this->getTextBox( $params );
909 * Get a labelled checkbox to configure a boolean variable.
911 * @param mixed[] $params
912 * Parameters are:
913 * var: The variable to be configured (required)
914 * label: The message name for the label (required)
915 * attribs: Additional attributes for the input element (optional)
916 * controlName: The name for the input element (optional)
917 * value: The current value of the variable (optional)
918 * help: The html for the help text (optional)
920 * @return string
922 public function getCheckBox( $params ) {
923 if ( !isset( $params['controlName'] ) ) {
924 $params['controlName'] = 'config_' . $params['var'];
927 if ( !isset( $params['value'] ) ) {
928 $params['value'] = $this->getVar( $params['var'] );
931 if ( !isset( $params['attribs'] ) ) {
932 $params['attribs'] = array();
934 if ( !isset( $params['help'] ) ) {
935 $params['help'] = "";
937 if ( isset( $params['rawtext'] ) ) {
938 $labelText = $params['rawtext'];
939 } else {
940 $labelText = $this->parse( wfMessage( $params['label'] )->text() );
943 return "<div class=\"config-input-check\">\n" .
944 $params['help'] .
945 "<label>\n" .
946 Xml::check(
947 $params['controlName'],
948 $params['value'],
949 $params['attribs'] + array(
950 'id' => $params['controlName'],
951 'tabindex' => $this->nextTabIndex(),
954 $labelText . "\n" .
955 "</label>\n" .
956 "</div>\n";
960 * Get a set of labelled radio buttons.
962 * @param mixed[] $params
963 * Parameters are:
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)
976 * @return string
978 public function getRadioSet( $params ) {
979 $items = $this->getRadioElements( $params );
981 if ( !isset( $params['label'] ) ) {
982 $label = '';
983 } else {
984 $label = $params['label'];
987 if ( !isset( $params['controlName'] ) ) {
988 $params['controlName'] = 'config_' . $params['var'];
991 if ( !isset( $params['help'] ) ) {
992 $params['help'] = "";
995 $s = "<ul>\n";
996 foreach ( $items as $value => $item ) {
997 $s .= "<li>$item</li>\n";
999 $s .= "</ul>\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.
1007 * @see getRadioSet
1009 * @return array
1011 public function getRadioElements( $params ) {
1012 if ( !isset( $params['controlName'] ) ) {
1013 $params['controlName'] = 'config_' . $params['var'];
1016 if ( !isset( $params['value'] ) ) {
1017 $params['value'] = $this->getVar( $params['var'] );
1020 $items = array();
1022 foreach ( $params['values'] as $value ) {
1023 $itemAttribs = array();
1025 if ( isset( $params['commonAttribs'] ) ) {
1026 $itemAttribs = $params['commonAttribs'];
1029 if ( isset( $params['itemAttribs'][$value] ) ) {
1030 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
1033 $checked = $value == $params['value'];
1034 $id = $params['controlName'] . '_' . $value;
1035 $itemAttribs['id'] = $id;
1036 $itemAttribs['tabindex'] = $this->nextTabIndex();
1038 $items[$value] =
1039 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
1040 '&#160;' .
1041 Xml::tags( 'label', array( 'for' => $id ), $this->parse(
1042 isset( $params['itemLabels'] ) ?
1043 wfMessage( $params['itemLabels'][$value] )->plain() :
1044 wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
1045 ) );
1048 return $items;
1052 * Output an error or warning box using a Status object.
1054 * @param Status $status
1056 public function showStatusBox( $status ) {
1057 if ( !$status->isGood() ) {
1058 $text = $status->getWikiText();
1060 if ( $status->isOk() ) {
1061 $box = $this->getWarningBox( $text );
1062 } else {
1063 $box = $this->getErrorBox( $text );
1066 $this->output->addHTML( $box );
1071 * Convenience function to set variables based on form data.
1072 * Assumes that variables containing "password" in the name are (potentially
1073 * fake) passwords.
1075 * @param string[] $varNames
1076 * @param string $prefix The prefix added to variables to obtain form names
1078 * @return string[]
1080 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
1081 $newValues = array();
1083 foreach ( $varNames as $name ) {
1084 $value = $this->request->getVal( $prefix . $name );
1085 // bug 30524, do not trim passwords
1086 if ( stripos( $name, 'password' ) === false ) {
1087 $value = trim( $value );
1089 $newValues[$name] = $value;
1091 if ( $value === null ) {
1092 // Checkbox?
1093 $this->setVar( $name, false );
1094 } else {
1095 if ( stripos( $name, 'password' ) !== false ) {
1096 $this->setPassword( $name, $value );
1097 } else {
1098 $this->setVar( $name, $value );
1103 return $newValues;
1107 * Helper for Installer::docLink()
1109 * @param string $page
1111 * @return string
1113 protected function getDocUrl( $page ) {
1114 $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
1116 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
1117 $url .= '&lastPage=' . urlencode( $this->currentPageName );
1120 return $url;
1124 * Extension tag hook for a documentation link.
1126 * @param string $linkText
1127 * @param string[] $attribs
1128 * @param Parser $parser Unused
1130 * @return string
1132 public function docLink( $linkText, $attribs, $parser ) {
1133 $url = $this->getDocUrl( $attribs['href'] );
1135 return '<a href="' . htmlspecialchars( $url ) . '">' .
1136 htmlspecialchars( $linkText ) .
1137 '</a>';
1141 * Helper for "Download LocalSettings" link on WebInstall_Complete
1143 * @param string $text Unused
1144 * @param string[] $attribs Unused
1145 * @param Parser $parser Unused
1147 * @return string Html for download link
1149 public function downloadLinkHook( $text, $attribs, $parser ) {
1150 $anchor = Html::rawElement( 'a',
1151 array( 'href' => $this->getURL( array( 'localsettings' => 1 ) ) ),
1152 wfMessage( 'config-download-localsettings' )->parse()
1155 return Html::rawElement( 'div', array( 'class' => 'config-download-link' ), $anchor );
1159 * @return bool
1161 public function envCheckPath() {
1162 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1163 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1164 // to get the path to the current script... hopefully it's reliable. SIGH
1165 $path = false;
1166 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1167 $path = $_SERVER['PHP_SELF'];
1168 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1169 $path = $_SERVER['SCRIPT_NAME'];
1171 if ( $path === false ) {
1172 $this->showError( 'config-no-uri' );
1173 return false;
1176 return parent::envCheckPath();
1179 public function envPrepPath() {
1180 parent::envPrepPath();
1181 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1182 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1183 // to get the path to the current script... hopefully it's reliable. SIGH
1184 $path = false;
1185 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1186 $path = $_SERVER['PHP_SELF'];
1187 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1188 $path = $_SERVER['SCRIPT_NAME'];
1190 if ( $path !== false ) {
1191 $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
1193 $this->setVar( 'wgScriptPath', "$scriptPath" );
1194 // Update variables set from Setup.php that are derived from wgScriptPath
1195 $this->setVar( 'wgScript', "$scriptPath/index.php" );
1196 $this->setVar( 'wgLoadScript', "$scriptPath/load.php" );
1197 $this->setVar( 'wgStylePath', "$scriptPath/skins" );
1198 $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
1199 $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
1200 $this->setVar( 'wgUploadPath', "$scriptPath/images" );
1201 $this->setVar( 'wgResourceBasePath', "$scriptPath" );
1206 * @return string
1208 protected function envGetDefaultServer() {
1209 return WebRequest::detectServer();
1213 * Output stylesheet for web installer pages
1215 public function outputCss() {
1216 $this->request->response()->header( 'Content-type: text/css' );
1217 echo $this->output->getCSS();
1221 * @return string[]
1223 public function getPhpErrors() {
1224 return $this->phpErrors;