Add a way for packagers to override some installation details
[mediawiki.git] / includes / installer / WebInstaller.php
blob4f31195e8495b6b7400b550b97d2efdbfb3308c4
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.
53 * @var array
55 protected $phpErrors;
57 /**
58 * The main sequence of page names. These will be displayed in turn.
59 * To add one:
60 * * Add it here
61 * * Add a config-page-<name> message
62 * * Add a WebInstaller_<name> class
63 * @var array
65 public $pageSequence = array(
66 'Language',
67 'ExistingWiki',
68 'Welcome',
69 'DBConnect',
70 'Upgrade',
71 'DBSettings',
72 'Name',
73 'Options',
74 'Install',
75 'Complete',
78 /**
79 * Out of sequence pages, selectable by the user at any time.
80 * @var array
82 protected $otherPages = array(
83 'Restart',
84 'Readme',
85 'ReleaseNotes',
86 'Copying',
87 'UpgradeDoc', // Can't use Upgrade due to Upgrade step
90 /**
91 * Array of pages which have declared that they have been submitted, have validated
92 * their input, and need no further processing.
93 * @var array
95 protected $happyPages;
97 /**
98 * List of "skipped" pages. These are pages that will automatically continue
99 * to the next page on any GET request. To avoid breaking the "back" button,
100 * they need to be skipped during a back operation.
101 * @var array
103 protected $skippedPages;
106 * Flag indicating that session data may have been lost.
107 * @var bool
109 public $showSessionWarning = false;
112 * Numeric index of the page we're on
113 * @var int
115 protected $tabIndex = 1;
118 * Name of the page we're on
119 * @var string
121 protected $currentPageName;
124 * Constructor.
126 * @param $request WebRequest
128 public function __construct( WebRequest $request ) {
129 parent::__construct();
130 $this->output = new WebInstallerOutput( $this );
131 $this->request = $request;
133 // Add parser hooks
134 global $wgParser;
135 $wgParser->setHook( 'downloadlink', array( $this, 'downloadLinkHook' ) );
136 $wgParser->setHook( 'doclink', array( $this, 'docLink' ) );
140 * Main entry point.
142 * @param $session Array: initial session array
144 * @return Array: new session array
146 public function execute( array $session ) {
147 $this->session = $session;
149 if ( isset( $session['settings'] ) ) {
150 $this->settings = $session['settings'] + $this->settings;
153 $this->exportVars();
154 $this->setupLanguage();
156 if( ( $this->getVar( '_InstallDone' ) || $this->getVar( '_UpgradeDone' ) )
157 && $this->request->getVal( 'localsettings' ) )
159 $this->request->response()->header( 'Content-type: application/x-httpd-php' );
160 $this->request->response()->header(
161 'Content-Disposition: attachment; filename="LocalSettings.php"'
164 $ls = InstallerOverrides::getLocalSettingsGenerator( $this );
165 $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )];
166 foreach( $rightsProfile as $group => $rightsArr ) {
167 $ls->setGroupRights( $group, $rightsArr );
169 echo $ls->getText();
170 return $this->session;
173 $cssDir = $this->request->getVal( 'css' );
174 if( $cssDir ) {
175 $cssDir = ( $cssDir == 'rtl' ? 'rtl' : 'ltr' );
176 $this->request->response()->header( 'Content-type: text/css' );
177 echo $this->output->getCSS( $cssDir );
178 return $this->session;
181 if ( isset( $session['happyPages'] ) ) {
182 $this->happyPages = $session['happyPages'];
183 } else {
184 $this->happyPages = array();
187 if ( isset( $session['skippedPages'] ) ) {
188 $this->skippedPages = $session['skippedPages'];
189 } else {
190 $this->skippedPages = array();
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();
200 $page->submitCC();
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() );
209 return $this->finish();
212 # Get the page name.
213 $pageName = $this->request->getVal( 'page' );
215 if ( in_array( $pageName, $this->otherPages ) ) {
216 # Out of sequence
217 $pageId = false;
218 $page = $this->getPageByName( $pageName );
219 } else {
220 # Main sequence
221 if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) {
222 $pageId = $lowestUnhappy;
223 } else {
224 $pageId = array_search( $pageName, $this->pageSequence );
227 # If necessary, move back to the lowest-numbered unhappy page
228 if ( $pageId > $lowestUnhappy ) {
229 $pageId = $lowestUnhappy;
230 if ( $lowestUnhappy == 0 ) {
231 # Knocked back to start, possible loss of session data.
232 $this->showSessionWarning = true;
236 $pageName = $this->pageSequence[$pageId];
237 $page = $this->getPageByName( $pageName );
240 # If a back button was submitted, go back without submitting the form data.
241 if ( $this->request->wasPosted() && $this->request->getBool( 'submit-back' ) ) {
242 if ( $this->request->getVal( 'lastPage' ) ) {
243 $nextPage = $this->request->getVal( 'lastPage' );
244 } elseif ( $pageId !== false ) {
245 # Main sequence page
246 # Skip the skipped pages
247 $nextPageId = $pageId;
249 do {
250 $nextPageId--;
251 $nextPage = $this->pageSequence[$nextPageId];
252 } while( isset( $this->skippedPages[$nextPage] ) );
253 } else {
254 $nextPage = $this->pageSequence[$lowestUnhappy];
257 $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
258 return $this->finish();
261 # Execute the page.
262 $this->currentPageName = $page->getName();
263 $this->startPageWrapper( $pageName );
265 if( $page->isSlow() ) {
266 $this->disableTimeLimit();
269 $result = $page->execute();
271 $this->endPageWrapper();
273 if ( $result == 'skip' ) {
274 # Page skipped without explicit submission.
275 # Skip it when we click "back" so that we don't just go forward again.
276 $this->skippedPages[$pageName] = true;
277 $result = 'continue';
278 } else {
279 unset( $this->skippedPages[$pageName] );
282 # If it was posted, the page can request a continue to the next page.
283 if ( $result === 'continue' && !$this->output->headerDone() ) {
284 if ( $pageId !== false ) {
285 $this->happyPages[$pageId] = true;
288 $lowestUnhappy = $this->getLowestUnhappy();
290 if ( $this->request->getVal( 'lastPage' ) ) {
291 $nextPage = $this->request->getVal( 'lastPage' );
292 } elseif ( $pageId !== false ) {
293 $nextPage = $this->pageSequence[$pageId + 1];
294 } else {
295 $nextPage = $this->pageSequence[$lowestUnhappy];
298 if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) {
299 $nextPage = $this->pageSequence[$lowestUnhappy];
302 $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
305 return $this->finish();
309 * Find the next page in sequence that hasn't been completed
310 * @return int
312 public function getLowestUnhappy() {
313 if ( count( $this->happyPages ) == 0 ) {
314 return 0;
315 } else {
316 return max( array_keys( $this->happyPages ) ) + 1;
321 * Start the PHP session. This may be called before execute() to start the PHP session.
323 * @return bool
325 public function startSession() {
326 if( wfIniGetBool( 'session.auto_start' ) || session_id() ) {
327 // Done already
328 return true;
331 $this->phpErrors = array();
332 set_error_handler( array( $this, 'errorHandler' ) );
333 session_start();
334 restore_error_handler();
336 if ( $this->phpErrors ) {
337 $this->showError( 'config-session-error', $this->phpErrors[0] );
338 return false;
341 return true;
345 * Get a hash of data identifying this MW installation.
347 * This is used by mw-config/index.php to prevent multiple installations of MW
348 * on the same cookie domain from interfering with each other.
350 * @return string
352 public function getFingerprint() {
353 // Get the base URL of the installation
354 $url = $this->request->getFullRequestURL();
355 if ( preg_match( '!^(.*\?)!', $url, $m) ) {
356 // Trim query string
357 $url = $m[1];
359 if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
360 // This... seems to try to get the base path from
361 // the /mw-config/index.php. Kinda scary though?
362 $url = $m[1];
364 return md5( serialize( array(
365 'local path' => dirname( dirname( __FILE__ ) ),
366 'url' => $url,
367 'version' => $GLOBALS['wgVersion']
368 ) ) );
372 * Show an error message in a box. Parameters are like wfMsg().
373 * @param $msg
375 public function showError( $msg /*...*/ ) {
376 $args = func_get_args();
377 array_shift( $args );
378 $args = array_map( 'htmlspecialchars', $args );
379 $msg = wfMsgReal( $msg, $args, false, false, false );
380 $this->output->addHTML( $this->getErrorBox( $msg ) );
384 * Temporary error handler for session start debugging.
385 * @param $errno
386 * @param $errstr string
388 public function errorHandler( $errno, $errstr ) {
389 $this->phpErrors[] = $errstr;
393 * Clean up from execute()
395 * @return array
397 public function finish() {
398 $this->output->output();
400 $this->session['happyPages'] = $this->happyPages;
401 $this->session['skippedPages'] = $this->skippedPages;
402 $this->session['settings'] = $this->settings;
404 return $this->session;
408 * We're restarting the installation, reset the session, happyPages, etc
410 public function reset() {
411 $this->session = array();
412 $this->happyPages = array();
413 $this->settings = array();
417 * Get a URL for submission back to the same script.
419 * @param $query array
420 * @return string
422 public function getUrl( $query = array() ) {
423 $url = $this->request->getRequestURL();
424 # Remove existing query
425 $url = preg_replace( '/\?.*$/', '', $url );
427 if ( $query ) {
428 $url .= '?' . wfArrayToCGI( $query );
431 return $url;
435 * Get a WebInstallerPage by name.
437 * @param $pageName String
438 * @return WebInstallerPage
440 public function getPageByName( $pageName ) {
441 $pageClass = 'WebInstaller_' . $pageName;
443 return new $pageClass( $this );
447 * Get a session variable.
449 * @param $name String
450 * @param $default
451 * @return null
453 public function getSession( $name, $default = null ) {
454 if ( !isset( $this->session[$name] ) ) {
455 return $default;
456 } else {
457 return $this->session[$name];
462 * Set a session variable.
463 * @param $name String key for the variable
464 * @param $value Mixed
466 public function setSession( $name, $value ) {
467 $this->session[$name] = $value;
471 * Get the next tabindex attribute value.
472 * @return int
474 public function nextTabIndex() {
475 return $this->tabIndex++;
479 * Initializes language-related variables.
481 public function setupLanguage() {
482 global $wgLang, $wgContLang, $wgLanguageCode;
484 if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
485 $wgLanguageCode = $this->getAcceptLanguage();
486 $wgLang = $wgContLang = Language::factory( $wgLanguageCode );
487 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
488 $this->setVar( '_UserLang', $wgLanguageCode );
489 } else {
490 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
491 $wgContLang = Language::factory( $wgLanguageCode );
496 * Retrieves MediaWiki language from Accept-Language HTTP header.
498 * @return string
500 public function getAcceptLanguage() {
501 global $wgLanguageCode, $wgRequest;
503 $mwLanguages = Language::fetchLanguageNames();
504 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
506 foreach ( $headerLanguages as $lang ) {
507 if ( isset( $mwLanguages[$lang] ) ) {
508 return $lang;
512 return $wgLanguageCode;
516 * Called by execute() before page output starts, to show a page list.
518 * @param $currentPageName String
520 private function startPageWrapper( $currentPageName ) {
521 $s = "<div class=\"config-page-wrapper\">\n";
522 $s .= "<div class=\"config-page\">\n";
523 $s .= "<div class=\"config-page-list\"><ul>\n";
524 $lastHappy = -1;
526 foreach ( $this->pageSequence as $id => $pageName ) {
527 $happy = !empty( $this->happyPages[$id] );
528 $s .= $this->getPageListItem(
529 $pageName,
530 $happy || $lastHappy == $id - 1,
531 $currentPageName
534 if ( $happy ) {
535 $lastHappy = $id;
539 $s .= "</ul><br/><ul>\n";
540 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
541 $s .= "</ul></div>\n"; // end list pane
542 $s .= Html::element( 'h2', array(),
543 wfMsg( 'config-page-' . strtolower( $currentPageName ) ) );
545 $this->output->addHTMLNoFlush( $s );
549 * Get a list item for the page list.
551 * @param $pageName String
552 * @param $enabled Boolean
553 * @param $currentPageName String
555 * @return string
557 private function getPageListItem( $pageName, $enabled, $currentPageName ) {
558 $s = "<li class=\"config-page-list-item\">";
559 $name = wfMsg( 'config-page-' . strtolower( $pageName ) );
561 if ( $enabled ) {
562 $query = array( 'page' => $pageName );
564 if ( !in_array( $pageName, $this->pageSequence ) ) {
565 if ( in_array( $currentPageName, $this->pageSequence ) ) {
566 $query['lastPage'] = $currentPageName;
569 $link = Html::element( 'a',
570 array(
571 'href' => $this->getUrl( $query )
573 $name
575 } else {
576 $link = htmlspecialchars( $name );
579 if ( $pageName == $currentPageName ) {
580 $s .= "<span class=\"config-page-current\">$link</span>";
581 } else {
582 $s .= $link;
584 } else {
585 $s .= Html::element( 'span',
586 array(
587 'class' => 'config-page-disabled'
589 $name
593 $s .= "</li>\n";
595 return $s;
599 * Output some stuff after a page is finished.
601 private function endPageWrapper() {
602 $this->output->addHTMLNoFlush(
603 "<div class=\"visualClear\"></div>\n" .
604 "</div>\n" .
605 "<div class=\"visualClear\"></div>\n" .
606 "</div>" );
610 * Get HTML for an error box with an icon.
612 * @param $text String: wikitext, get this with wfMsgNoTrans()
614 * @return string
616 public function getErrorBox( $text ) {
617 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
621 * Get HTML for a warning box with an icon.
623 * @param $text String: wikitext, get this with wfMsgNoTrans()
625 * @return string
627 public function getWarningBox( $text ) {
628 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
632 * Get HTML for an info box with an icon.
634 * @param $text String: wikitext, get this with wfMsgNoTrans()
635 * @param $icon String: icon name, file in skins/common/images
636 * @param $class String: additional class name to add to the wrapper div
638 * @return string
640 public function getInfoBox( $text, $icon = false, $class = false ) {
641 $text = $this->parse( $text, true );
642 $icon = ( $icon == false ) ? '../skins/common/images/info-32.png' : '../skins/common/images/'.$icon;
643 $alt = wfMsg( 'config-information' );
644 return Html::infoBox( $text, $icon, $alt, $class, false );
648 * Get small text indented help for a preceding form field.
649 * Parameters like wfMsg().
651 * @param $msg
652 * @return string
654 public function getHelpBox( $msg /*, ... */ ) {
655 $args = func_get_args();
656 array_shift( $args );
657 $args = array_map( 'htmlspecialchars', $args );
658 $text = wfMsgReal( $msg, $args, false, false, false );
659 $html = $this->parse( $text, true );
661 return "<div class=\"mw-help-field-container\">\n" .
662 "<span class=\"mw-help-field-hint\">" . wfMsgHtml( 'config-help' ) . "</span>\n" .
663 "<span class=\"mw-help-field-data\">" . $html . "</span>\n" .
664 "</div>\n";
668 * Output a help box.
669 * @param $msg String key for wfMsg()
671 public function showHelpBox( $msg /*, ... */ ) {
672 $args = func_get_args();
673 $html = call_user_func_array( array( $this, 'getHelpBox' ), $args );
674 $this->output->addHTML( $html );
678 * Show a short informational message.
679 * Output looks like a list.
681 * @param $msg string
683 public function showMessage( $msg /*, ... */ ) {
684 $args = func_get_args();
685 array_shift( $args );
686 $html = '<div class="config-message">' .
687 $this->parse( wfMsgReal( $msg, $args, false, false, false ) ) .
688 "</div>\n";
689 $this->output->addHTML( $html );
693 * @param $status Status
695 public function showStatusMessage( Status $status ) {
696 $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
697 foreach ( $errors as $error ) {
698 call_user_func_array( array( $this, 'showMessage' ), $error );
703 * Label a control by wrapping a config-input div around it and putting a
704 * label before it.
706 * @param $msg
707 * @param $forId
708 * @param $contents
709 * @param $helpData string
710 * @return string
712 public function label( $msg, $forId, $contents, $helpData = "" ) {
713 if ( strval( $msg ) == '' ) {
714 $labelText = '&#160;';
715 } else {
716 $labelText = wfMsgHtml( $msg );
719 $attributes = array( 'class' => 'config-label' );
721 if ( $forId ) {
722 $attributes['for'] = $forId;
725 return
726 "<div class=\"config-block\">\n" .
727 " <div class=\"config-block-label\">\n" .
728 Xml::tags( 'label',
729 $attributes,
730 $labelText ) . "\n" .
731 $helpData .
732 " </div>\n" .
733 " <div class=\"config-block-elements\">\n" .
734 $contents .
735 " </div>\n" .
736 "</div>\n";
740 * Get a labelled text box to configure a variable.
742 * @param $params Array
743 * Parameters are:
744 * var: The variable to be configured (required)
745 * label: The message name for the label (required)
746 * attribs: Additional attributes for the input element (optional)
747 * controlName: The name for the input element (optional)
748 * value: The current value of the variable (optional)
749 * help: The html for the help text (optional)
751 * @return string
753 public function getTextBox( $params ) {
754 if ( !isset( $params['controlName'] ) ) {
755 $params['controlName'] = 'config_' . $params['var'];
758 if ( !isset( $params['value'] ) ) {
759 $params['value'] = $this->getVar( $params['var'] );
762 if ( !isset( $params['attribs'] ) ) {
763 $params['attribs'] = array();
765 if ( !isset( $params['help'] ) ) {
766 $params['help'] = "";
768 return
769 $this->label(
770 $params['label'],
771 $params['controlName'],
772 Xml::input(
773 $params['controlName'],
774 30, // intended to be overridden by CSS
775 $params['value'],
776 $params['attribs'] + array(
777 'id' => $params['controlName'],
778 'class' => 'config-input-text',
779 'tabindex' => $this->nextTabIndex()
782 $params['help']
787 * Get a labelled textarea to configure a variable
789 * @param $params Array
790 * Parameters are:
791 * var: The variable to be configured (required)
792 * label: The message name for the label (required)
793 * attribs: Additional attributes for the input element (optional)
794 * controlName: The name for the input element (optional)
795 * value: The current value of the variable (optional)
796 * help: The html for the help text (optional)
798 * @return string
800 public function getTextArea( $params ) {
801 if ( !isset( $params['controlName'] ) ) {
802 $params['controlName'] = 'config_' . $params['var'];
805 if ( !isset( $params['value'] ) ) {
806 $params['value'] = $this->getVar( $params['var'] );
809 if ( !isset( $params['attribs'] ) ) {
810 $params['attribs'] = array();
812 if ( !isset( $params['help'] ) ) {
813 $params['help'] = "";
815 return
816 $this->label(
817 $params['label'],
818 $params['controlName'],
819 Xml::textarea(
820 $params['controlName'],
821 $params['value'],
824 $params['attribs'] + array(
825 'id' => $params['controlName'],
826 'class' => 'config-input-text',
827 'tabindex' => $this->nextTabIndex()
830 $params['help']
835 * Get a labelled password box to configure a variable.
837 * Implements password hiding
838 * @param $params Array
839 * Parameters are:
840 * var: The variable to be configured (required)
841 * label: The message name for the label (required)
842 * attribs: Additional attributes for the input element (optional)
843 * controlName: The name for the input element (optional)
844 * value: The current value of the variable (optional)
845 * help: The html for the help text (optional)
847 * @return string
849 public function getPasswordBox( $params ) {
850 if ( !isset( $params['value'] ) ) {
851 $params['value'] = $this->getVar( $params['var'] );
854 if ( !isset( $params['attribs'] ) ) {
855 $params['attribs'] = array();
858 $params['value'] = $this->getFakePassword( $params['value'] );
859 $params['attribs']['type'] = 'password';
861 return $this->getTextBox( $params );
865 * Get a labelled checkbox to configure a boolean variable.
867 * @param $params Array
868 * Parameters are:
869 * var: The variable to be configured (required)
870 * label: The message name for the label (required)
871 * attribs: Additional attributes for the input element (optional)
872 * controlName: The name for the input element (optional)
873 * value: The current value of the variable (optional)
874 * help: The html for the help text (optional)
876 * @return string
878 public function getCheckBox( $params ) {
879 if ( !isset( $params['controlName'] ) ) {
880 $params['controlName'] = 'config_' . $params['var'];
883 if ( !isset( $params['value'] ) ) {
884 $params['value'] = $this->getVar( $params['var'] );
887 if ( !isset( $params['attribs'] ) ) {
888 $params['attribs'] = array();
890 if ( !isset( $params['help'] ) ) {
891 $params['help'] = "";
893 if( isset( $params['rawtext'] ) ) {
894 $labelText = $params['rawtext'];
895 } else {
896 $labelText = $this->parse( wfMsg( $params['label'] ) );
899 return
900 "<div class=\"config-input-check\">\n" .
901 $params['help'] .
902 "<label>\n" .
903 Xml::check(
904 $params['controlName'],
905 $params['value'],
906 $params['attribs'] + array(
907 'id' => $params['controlName'],
908 'tabindex' => $this->nextTabIndex(),
911 $labelText . "\n" .
912 "</label>\n" .
913 "</div>\n";
917 * Get a set of labelled radio buttons.
919 * @param $params Array
920 * Parameters are:
921 * var: The variable to be configured (required)
922 * label: The message name for the label (required)
923 * itemLabelPrefix: The message name prefix for the item labels (required)
924 * values: List of allowed values (required)
925 * itemAttribs Array of attribute arrays, outer key is the value name (optional)
926 * commonAttribs Attribute array applied to all items
927 * controlName: The name for the input element (optional)
928 * value: The current value of the variable (optional)
929 * help: The html for the help text (optional)
931 * @return string
933 public function getRadioSet( $params ) {
934 if ( !isset( $params['controlName'] ) ) {
935 $params['controlName'] = 'config_' . $params['var'];
938 if ( !isset( $params['value'] ) ) {
939 $params['value'] = $this->getVar( $params['var'] );
942 if ( !isset( $params['label'] ) ) {
943 $label = '';
944 } else {
945 $label = $params['label'];
947 if ( !isset( $params['help'] ) ) {
948 $params['help'] = "";
950 $s = "<ul>\n";
951 foreach ( $params['values'] as $value ) {
952 $itemAttribs = array();
954 if ( isset( $params['commonAttribs'] ) ) {
955 $itemAttribs = $params['commonAttribs'];
958 if ( isset( $params['itemAttribs'][$value] ) ) {
959 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
962 $checked = $value == $params['value'];
963 $id = $params['controlName'] . '_' . $value;
964 $itemAttribs['id'] = $id;
965 $itemAttribs['tabindex'] = $this->nextTabIndex();
967 $s .=
968 '<li>' .
969 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
970 '&#160;' .
971 Xml::tags( 'label', array( 'for' => $id ), $this->parse(
972 wfMsgNoTrans( $params['itemLabelPrefix'] . strtolower( $value ) )
973 ) ) .
974 "</li>\n";
977 $s .= "</ul>\n";
979 return $this->label( $label, $params['controlName'], $s, $params['help'] );
983 * Output an error or warning box using a Status object.
985 * @param $status Status
987 public function showStatusBox( $status ) {
988 if( !$status->isGood() ) {
989 $text = $status->getWikiText();
991 if( $status->isOk() ) {
992 $box = $this->getWarningBox( $text );
993 } else {
994 $box = $this->getErrorBox( $text );
997 $this->output->addHTML( $box );
1002 * Convenience function to set variables based on form data.
1003 * Assumes that variables containing "password" in the name are (potentially
1004 * fake) passwords.
1006 * @param $varNames Array
1007 * @param $prefix String: the prefix added to variables to obtain form names
1009 * @return array
1011 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
1012 $newValues = array();
1014 foreach ( $varNames as $name ) {
1015 $value = trim( $this->request->getVal( $prefix . $name ) );
1016 $newValues[$name] = $value;
1018 if ( $value === null ) {
1019 // Checkbox?
1020 $this->setVar( $name, false );
1021 } else {
1022 if ( stripos( $name, 'password' ) !== false ) {
1023 $this->setPassword( $name, $value );
1024 } else {
1025 $this->setVar( $name, $value );
1030 return $newValues;
1034 * Helper for Installer::docLink()
1036 * @param $page
1037 * @return string
1039 protected function getDocUrl( $page ) {
1040 $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
1042 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
1043 $url .= '&lastPage=' . urlencode( $this->currentPageName );
1046 return $url;
1050 * Extension tag hook for a documentation link.
1052 * @param $linkText
1053 * @param $attribs
1054 * @param $parser
1055 * @return string
1057 public function docLink( $linkText, $attribs, $parser ) {
1058 $url = $this->getDocUrl( $attribs['href'] );
1059 return '<a href="' . htmlspecialchars( $url ) . '">' .
1060 htmlspecialchars( $linkText ) .
1061 '</a>';
1065 * Helper for "Download LocalSettings" link on WebInstall_Complete
1067 * @param $text
1068 * @param $attribs
1069 * @param $parser
1070 * @return String Html for download link
1072 public function downloadLinkHook( $text, $attribs, $parser ) {
1073 $img = Html::element( 'img', array(
1074 'src' => '../skins/common/images/download-32.png',
1075 'width' => '32',
1076 'height' => '32',
1077 ) );
1078 $anchor = Html::rawElement( 'a',
1079 array( 'href' => $this->getURL( array( 'localsettings' => 1 ) ) ),
1080 $img . ' ' . wfMsgHtml( 'config-download-localsettings' ) );
1081 return Html::rawElement( 'div', array( 'class' => 'config-download-link' ), $anchor );
1085 * @return bool
1087 public function envCheckPath( ) {
1088 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1089 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1090 // to get the path to the current script... hopefully it's reliable. SIGH
1091 $path = false;
1092 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1093 $path = $_SERVER['PHP_SELF'];
1094 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1095 $path = $_SERVER['SCRIPT_NAME'];
1097 if ($path !== false) {
1098 $uri = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
1099 $this->setVar( 'wgScriptPath', $uri );
1100 } else {
1101 $this->showError( 'config-no-uri' );
1102 return false;
1104 return parent::envCheckPath();
1107 protected function envGetDefaultServer() {
1108 return WebRequest::detectServer();