Allow downloading LocalSettings after upgrades
[lhc/web/wiklou.git] / includes / installer / WebInstaller.php
1 <?php
2 /**
3 * Core installer web interface.
4 *
5 * @file
6 * @ingroup Deployment
7 */
8
9 /**
10 * Class for the core installer web interface.
11 *
12 * @ingroup Deployment
13 * @since 1.17
14 */
15 class WebInstaller extends CoreInstaller {
16
17 /**
18 * @var WebInstallerOutput
19 */
20 public $output;
21
22 /**
23 * WebRequest object.
24 *
25 * @var WebRequest
26 */
27 public $request;
28
29 /**
30 * Cached session array.
31 *
32 * @var array
33 */
34 public $session;
35
36 /**
37 * Captured PHP error text. Temporary.
38 */
39 public $phpErrors;
40
41 /**
42 * The main sequence of page names. These will be displayed in turn.
43 * To add one:
44 * * Add it here
45 * * Add a config-page-<name> message
46 * * Add a WebInstaller_<name> class
47 */
48 public $pageSequence = array(
49 'Language',
50 'Welcome',
51 'DBConnect',
52 'Upgrade',
53 'DBSettings',
54 'Name',
55 'Options',
56 'Install',
57 'Complete',
58 );
59
60 /**
61 * Out of sequence pages, selectable by the user at any time.
62 */
63 public $otherPages = array(
64 'Restart',
65 'Readme',
66 'ReleaseNotes',
67 'Copying',
68 'UpgradeDoc', // Can't use Upgrade due to Upgrade step
69 );
70
71 /**
72 * Array of pages which have declared that they have been submitted, have validated
73 * their input, and need no further processing.
74 */
75 public $happyPages;
76
77 /**
78 * List of "skipped" pages. These are pages that will automatically continue
79 * to the next page on any GET request. To avoid breaking the "back" button,
80 * they need to be skipped during a back operation.
81 */
82 public $skippedPages;
83
84 /**
85 * Flag indicating that session data may have been lost.
86 */
87 public $showSessionWarning = false;
88
89 public $tabIndex = 1;
90
91 public $currentPageName;
92
93 /**
94 * Constructor.
95 *
96 * @param $request WebRequest
97 */
98 public function __construct( WebRequest $request ) {
99 parent::__construct();
100 $this->output = new WebInstallerOutput( $this );
101 $this->request = $request;
102 }
103
104 /**
105 * Main entry point.
106 *
107 * @param $session Array: initial session array
108 *
109 * @return Array: new session array
110 */
111 public function execute( array $session ) {
112 $this->session = $session;
113
114 if ( isset( $session['settings'] ) ) {
115 $this->settings = $session['settings'] + $this->settings;
116 }
117
118 $this->exportVars();
119 $this->setupLanguage();
120
121 if( ( $this->getVar( '_InstallDone' ) || $this->getVar( '_UpgradeDone' ) )
122 && $this->request->getVal( 'localsettings' ) )
123 {
124 $this->request->response()->header( 'Content-type: text/plain' );
125 $this->request->response()->header(
126 'Content-Disposition: attachment; filename="LocalSettings.php"'
127 );
128
129 $ls = new LocalSettingsGenerator( $this );
130 echo $ls->getText();
131 return $this->session;
132 }
133
134 $cssDir = $this->request->getVal( 'css' );
135 if( $cssDir ) {
136 $cssDir = ( $cssDir == 'rtl' ? 'rtl' : 'ltr' );
137 $this->request->response()->header( 'Content-type: text/css' );
138 echo $this->output->getCSS( $cssDir );
139 return $this->session;
140 }
141
142 if ( isset( $session['happyPages'] ) ) {
143 $this->happyPages = $session['happyPages'];
144 } else {
145 $this->happyPages = array();
146 }
147
148 if ( isset( $session['skippedPages'] ) ) {
149 $this->skippedPages = $session['skippedPages'];
150 } else {
151 $this->skippedPages = array();
152 }
153
154 $lowestUnhappy = $this->getLowestUnhappy();
155
156 # Special case for Creative Commons partner chooser box.
157 if ( $this->request->getVal( 'SubmitCC' ) ) {
158 $page = $this->getPageByName( 'Options' );
159 $this->output->useShortHeader();
160 $page->submitCC();
161 return $this->finish();
162 }
163
164 if ( $this->request->getVal( 'ShowCC' ) ) {
165 $page = $this->getPageByName( 'Options' );
166 $this->output->useShortHeader();
167 $this->output->addHTML( $page->getCCDoneBox() );
168 return $this->finish();
169 }
170
171 # Get the page name.
172 $pageName = $this->request->getVal( 'page' );
173
174 # Check LocalSettings status
175 $localSettings = $this->getLocalSettingsStatus();
176
177 if( !$localSettings->isGood() && $this->getVar( '_LocalSettingsLocked' ) ) {
178 $pageName = 'Locked';
179 $pageId = false;
180 $page = $this->getPageByName( $pageName );
181 $page->setLocalSettingsStatus( $localSettings );
182 } elseif ( in_array( $pageName, $this->otherPages ) ) {
183 # Out of sequence
184 $pageId = false;
185 $page = $this->getPageByName( $pageName );
186 } else {
187 # Main sequence
188 if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) {
189 $pageId = $lowestUnhappy;
190 } else {
191 $pageId = array_search( $pageName, $this->pageSequence );
192 }
193
194 # If necessary, move back to the lowest-numbered unhappy page
195 if ( $pageId > $lowestUnhappy ) {
196 $pageId = $lowestUnhappy;
197 if ( $lowestUnhappy == 0 ) {
198 # Knocked back to start, possible loss of session data.
199 $this->showSessionWarning = true;
200 }
201 }
202
203 $pageName = $this->pageSequence[$pageId];
204 $page = $this->getPageByName( $pageName );
205 }
206
207 # If a back button was submitted, go back without submitting the form data.
208 if ( $this->request->wasPosted() && $this->request->getBool( 'submit-back' ) ) {
209 if ( $this->request->getVal( 'lastPage' ) ) {
210 $nextPage = $this->request->getVal( 'lastPage' );
211 } elseif ( $pageId !== false ) {
212 # Main sequence page
213 # Skip the skipped pages
214 $nextPageId = $pageId;
215
216 do {
217 $nextPageId--;
218 $nextPage = $this->pageSequence[$nextPageId];
219 } while( isset( $this->skippedPages[$nextPage] ) );
220 } else {
221 $nextPage = $this->pageSequence[$lowestUnhappy];
222 }
223
224 $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
225 return $this->finish();
226 }
227
228 # Execute the page.
229 $this->currentPageName = $page->getName();
230 $this->startPageWrapper( $pageName );
231
232 $result = $page->execute();
233
234 $this->endPageWrapper();
235
236 if ( $result == 'skip' ) {
237 # Page skipped without explicit submission.
238 # Skip it when we click "back" so that we don't just go forward again.
239 $this->skippedPages[$pageName] = true;
240 $result = 'continue';
241 } else {
242 unset( $this->skippedPages[$pageName] );
243 }
244
245 # If it was posted, the page can request a continue to the next page.
246 if ( $result === 'continue' && !$this->output->headerDone() ) {
247 if ( $pageId !== false ) {
248 $this->happyPages[$pageId] = true;
249 }
250
251 $lowestUnhappy = $this->getLowestUnhappy();
252
253 if ( $this->request->getVal( 'lastPage' ) ) {
254 $nextPage = $this->request->getVal( 'lastPage' );
255 } elseif ( $pageId !== false ) {
256 $nextPage = $this->pageSequence[$pageId + 1];
257 } else {
258 $nextPage = $this->pageSequence[$lowestUnhappy];
259 }
260
261 if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) {
262 $nextPage = $this->pageSequence[$lowestUnhappy];
263 }
264
265 $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
266 }
267
268 return $this->finish();
269 }
270
271 public function getLowestUnhappy() {
272 if ( count( $this->happyPages ) == 0 ) {
273 return 0;
274 } else {
275 return max( array_keys( $this->happyPages ) ) + 1;
276 }
277 }
278
279 /**
280 * Start the PHP session. This may be called before execute() to start the PHP session.
281 */
282 public function startSession() {
283 $sessPath = $this->getSessionSavePath();
284
285 if( $sessPath != '' ) {
286 if( strval( ini_get( 'open_basedir' ) ) != '' ) {
287 // we need to skip the following check when open_basedir is on.
288 // The session path probably *wont* be writable by the current
289 // user, and telling them to change it is bad. Bug 23021.
290 } elseif( !is_dir( $sessPath ) || !is_writeable( $sessPath ) ) {
291 $this->showError( 'config-session-path-bad', $sessPath );
292 return false;
293 }
294 } else {
295 // If the path is unset it'll default to some system bit, which *probably* is ok...
296 // not sure how to actually get what will be used.
297 }
298
299 if( wfIniGetBool( 'session.auto_start' ) || session_id() ) {
300 // Done already
301 return true;
302 }
303
304 $this->phpErrors = array();
305 set_error_handler( array( $this, 'errorHandler' ) );
306 session_start();
307 restore_error_handler();
308
309 if ( $this->phpErrors ) {
310 $this->showError( 'config-session-error', $this->phpErrors[0] );
311 return false;
312 }
313
314 return true;
315 }
316
317 /**
318 * Get the value of session.save_path
319 *
320 * Per http://www.php.net/manual/en/session.configuration.php#ini.session.save-path,
321 * this may have an initial integer value to indicate the depth of session
322 * storage (eg /tmp/a/b/c). Explode on ; and check and see if this part is
323 * there or not. Should also allow paths with semicolons in them (if you
324 * really wanted your session files stored in /tmp/some;dir) which PHP
325 * supposedly supports.
326 *
327 * @return String
328 */
329 private function getSessionSavePath() {
330 $parts = explode( ';', ini_get( 'session.save_path' ), 2 );
331 return count( $parts ) == 1 ? $parts[0] : $parts[1];
332 }
333
334 /**
335 * Show an error message in a box. Parameters are like wfMsg().
336 */
337 public function showError( $msg /*...*/ ) {
338 $args = func_get_args();
339 array_shift( $args );
340 $args = array_map( 'htmlspecialchars', $args );
341 $msg = wfMsgReal( $msg, $args, false, false, false );
342 $this->output->addHTML( $this->getErrorBox( $msg ) );
343 }
344
345 /**
346 * Temporary error handler for session start debugging.
347 */
348 public function errorHandler( $errno, $errstr ) {
349 $this->phpErrors[] = $errstr;
350 }
351
352 /**
353 * Clean up from execute()
354 *
355 * @return array
356 */
357 public function finish() {
358 $this->output->output();
359
360 $this->session['happyPages'] = $this->happyPages;
361 $this->session['skippedPages'] = $this->skippedPages;
362 $this->session['settings'] = $this->settings;
363
364 return $this->session;
365 }
366
367 /**
368 * Get a URL for submission back to the same script.
369 *
370 * @param $query: Array
371 */
372 public function getUrl( $query = array() ) {
373 $url = $this->request->getRequestURL();
374 # Remove existing query
375 $url = preg_replace( '/\?.*$/', '', $url );
376
377 if ( $query ) {
378 $url .= '?' . wfArrayToCGI( $query );
379 }
380
381 return $url;
382 }
383
384 /**
385 * Get a WebInstallerPage by name.
386 *
387 * @param $pageName String
388 *
389 * @return WebInstallerPage
390 */
391 public function getPageByName( $pageName ) {
392 // Totally lame way to force autoload of WebInstallerPage.php
393 class_exists( 'WebInstallerPage' );
394
395 $pageClass = 'WebInstaller_' . $pageName;
396
397 return new $pageClass( $this );
398 }
399
400 /**
401 * Get a session variable.
402 *
403 * @param $name String
404 * @param $default
405 */
406 public function getSession( $name, $default = null ) {
407 if ( !isset( $this->session[$name] ) ) {
408 return $default;
409 } else {
410 return $this->session[$name];
411 }
412 }
413
414 /**
415 * Set a session variable.
416 */
417 public function setSession( $name, $value ) {
418 $this->session[$name] = $value;
419 }
420
421 /**
422 * Get the next tabindex attribute value.
423 */
424 public function nextTabIndex() {
425 return $this->tabIndex++;
426 }
427
428 /**
429 * Initializes language-related variables.
430 */
431 public function setupLanguage() {
432 global $wgLang, $wgContLang, $wgLanguageCode;
433
434 if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
435 $wgLanguageCode = $this->getAcceptLanguage();
436 $wgLang = $wgContLang = Language::factory( $wgLanguageCode );
437 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
438 $this->setVar( '_UserLang', $wgLanguageCode );
439 } else {
440 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
441 $wgLang = Language::factory( $this->getVar( '_UserLang' ) );
442 $wgContLang = Language::factory( $wgLanguageCode );
443 }
444 }
445
446 /**
447 * Retrieves MediaWiki language from Accept-Language HTTP header.
448 *
449 * @return string
450 */
451 public function getAcceptLanguage() {
452 global $wgLanguageCode, $wgRequest;
453
454 $mwLanguages = Language::getLanguageNames();
455 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
456
457 foreach ( $headerLanguages as $lang ) {
458 if ( isset( $mwLanguages[$lang] ) ) {
459 return $lang;
460 }
461 }
462
463 return $wgLanguageCode;
464 }
465
466 /**
467 * Called by execute() before page output starts, to show a page list.
468 *
469 * @param $currentPageName String
470 */
471 private function startPageWrapper( $currentPageName ) {
472 $s = "<div class=\"config-page-wrapper\">\n" .
473 "<div class=\"config-page-list\"><ul>\n";
474 $lastHappy = -1;
475
476 foreach ( $this->pageSequence as $id => $pageName ) {
477 $happy = !empty( $this->happyPages[$id] );
478 $s .= $this->getPageListItem(
479 $pageName,
480 $happy || $lastHappy == $id - 1,
481 $currentPageName
482 );
483
484 if ( $happy ) {
485 $lastHappy = $id;
486 }
487 }
488
489 $s .= "</ul><br/><ul>\n";
490
491 foreach ( $this->otherPages as $pageName ) {
492 $s .= $this->getPageListItem( $pageName, true, $currentPageName );
493 }
494
495 $s .= "</ul></div>\n". // end list pane
496 "<div class=\"config-page\">\n" .
497 Html::element( 'h2', array(),
498 wfMsg( 'config-page-' . strtolower( $currentPageName ) ) );
499
500 $this->output->addHTMLNoFlush( $s );
501 }
502
503 /**
504 * Get a list item for the page list.
505 *
506 * @param $pageName String
507 * @param $enabled Boolean
508 * @param $currentPageName String
509 *
510 * @return string
511 */
512 private function getPageListItem( $pageName, $enabled, $currentPageName ) {
513 $s = "<li class=\"config-page-list-item\">";
514 $name = wfMsg( 'config-page-' . strtolower( $pageName ) );
515
516 if ( $enabled ) {
517 $query = array( 'page' => $pageName );
518
519 if ( !in_array( $pageName, $this->pageSequence ) ) {
520 if ( in_array( $currentPageName, $this->pageSequence ) ) {
521 $query['lastPage'] = $currentPageName;
522 }
523
524 $link = Html::element( 'a',
525 array(
526 'href' => $this->getUrl( $query )
527 ),
528 $name
529 );
530 } else {
531 $link = htmlspecialchars( $name );
532 }
533
534 if ( $pageName == $currentPageName ) {
535 $s .= "<span class=\"config-page-current\">$link</span>";
536 } else {
537 $s .= $link;
538 }
539 } else {
540 $s .= Html::element( 'span',
541 array(
542 'class' => 'config-page-disabled'
543 ),
544 $name
545 );
546 }
547
548 $s .= "</li>\n";
549
550 return $s;
551 }
552
553 /**
554 * Output some stuff after a page is finished.
555 */
556 private function endPageWrapper() {
557 $this->output->addHTMLNoFlush(
558 "</div>\n" .
559 "<br style=\"clear:both\"/>\n" .
560 "</div>" );
561 }
562
563 /**
564 * Get HTML for an error box with an icon.
565 *
566 * @param $text String: wikitext, get this with wfMsgNoTrans()
567 */
568 public function getErrorBox( $text ) {
569 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
570 }
571
572 /**
573 * Get HTML for a warning box with an icon.
574 *
575 * @param $text String: wikitext, get this with wfMsgNoTrans()
576 */
577 public function getWarningBox( $text ) {
578 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
579 }
580
581 /**
582 * Get HTML for an info box with an icon.
583 *
584 * @param $text String: wikitext, get this with wfMsgNoTrans()
585 * @param $icon String: icon name, file in skins/common/images
586 * @param $class String: additional class name to add to the wrapper div
587 */
588 public function getInfoBox( $text, $icon = 'info-32.png', $class = false ) {
589 $s =
590 "<div class=\"config-info $class\">\n" .
591 "<div class=\"config-info-left\">\n" .
592 Html::element( 'img',
593 array(
594 'src' => '../skins/common/images/' . $icon,
595 'alt' => wfMsg( 'config-information' ),
596 )
597 ) . "\n" .
598 "</div>\n" .
599 "<div class=\"config-info-right\">\n" .
600 $this->parse( $text ) . "\n" .
601 "</div>\n" .
602 "<div style=\"clear: left;\"></div>\n" .
603 "</div>\n";
604 return $s;
605 }
606
607 /**
608 * Get small text indented help for a preceding form field.
609 * Parameters like wfMsg().
610 */
611 public function getHelpBox( $msg /*, ... */ ) {
612 $args = func_get_args();
613 array_shift( $args );
614 $args = array_map( 'htmlspecialchars', $args );
615 $text = wfMsgReal( $msg, $args, false, false, false );
616 //$html = $this->parse( $text, true );
617 $html = $text;
618 return
619 "<span class=\"mw-help-field-hint\"\n" .
620 " title=\"" . $html . "\"\n" .
621 " original-title=\"" . $html . "\"></span>\n";
622 }
623
624 /**
625 * Output a help box.
626 */
627 public function showHelpBox( $msg /*, ... */ ) {
628 $args = func_get_args();
629 $html = call_user_func_array( array( $this, 'getHelpBox' ), $args );
630 $this->output->addHTML( $html );
631 }
632
633 /**
634 * Show a short informational message.
635 * Output looks like a list.
636 *
637 * @param $msg string
638 */
639 public function showMessage( $msg /*, ... */ ) {
640 $args = func_get_args();
641 array_shift( $args );
642 $html = '<div class="config-message">' .
643 $this->parse( wfMsgReal( $msg, $args, false, false, false ) ) .
644 "</div>\n";
645 $this->output->addHTML( $html );
646 }
647
648 /**
649 * @param $status Status
650 */
651 public function showStatusMessage( Status $status ) {
652 $text = $status->getWikiText();
653 $this->output->addWikiText(
654 "<div class=\"config-message\">\n" .
655 $text .
656 "</div>"
657 );
658 }
659
660 /**
661 * Label a control by wrapping a config-input div around it and putting a
662 * label before it.
663 */
664 public function label( $msg, $forId, $contents, $helpData = "" ) {
665 if ( strval( $msg ) == '' ) {
666 $labelText = '&#160;';
667 } else {
668 $labelText = wfMsgHtml( $msg );
669 }
670
671 $attributes = array( 'class' => 'config-label' );
672
673 if ( $forId ) {
674 $attributes['for'] = $forId;
675 }
676
677 return
678 "<div class=\"config-block\">\n" .
679 " <div class=\"config-block-label\">\n" .
680 Xml::tags( 'label',
681 $attributes,
682 $labelText ) . "\n" .
683 $helpData .
684 " </div>\n" .
685 " <div class=\"config-block-elements\">\n" .
686 $contents .
687 " </div>\n" .
688 "</div>\n";
689 }
690
691 /**
692 * Get a labelled text box to configure a variable.
693 *
694 * @param $params Array
695 * Parameters are:
696 * var: The variable to be configured (required)
697 * label: The message name for the label (required)
698 * attribs: Additional attributes for the input element (optional)
699 * controlName: The name for the input element (optional)
700 * value: The current value of the variable (optional)
701 * help: The html for the help text (optional)
702 */
703 public function getTextBox( $params ) {
704 if ( !isset( $params['controlName'] ) ) {
705 $params['controlName'] = 'config_' . $params['var'];
706 }
707
708 if ( !isset( $params['value'] ) ) {
709 $params['value'] = $this->getVar( $params['var'] );
710 }
711
712 if ( !isset( $params['attribs'] ) ) {
713 $params['attribs'] = array();
714 }
715 if ( !isset( $params['help'] ) ) {
716 $params['help'] = "";
717 }
718 return
719 $this->label(
720 $params['label'],
721 $params['controlName'],
722 Xml::input(
723 $params['controlName'],
724 30, // intended to be overridden by CSS
725 $params['value'],
726 $params['attribs'] + array(
727 'id' => $params['controlName'],
728 'class' => 'config-input-text',
729 'tabindex' => $this->nextTabIndex()
730 )
731 ),
732 $params['help']
733 );
734 }
735
736 /**
737 * Get a labelled password box to configure a variable.
738 *
739 * Implements password hiding
740 * @param $params Array
741 * Parameters are:
742 * var: The variable to be configured (required)
743 * label: The message name for the label (required)
744 * attribs: Additional attributes for the input element (optional)
745 * controlName: The name for the input element (optional)
746 * value: The current value of the variable (optional)
747 * help: The html for the help text (optional)
748 */
749 public function getPasswordBox( $params ) {
750 if ( !isset( $params['value'] ) ) {
751 $params['value'] = $this->getVar( $params['var'] );
752 }
753
754 if ( !isset( $params['attribs'] ) ) {
755 $params['attribs'] = array();
756 }
757
758 $params['value'] = $this->getFakePassword( $params['value'] );
759 $params['attribs']['type'] = 'password';
760
761 return $this->getTextBox( $params );
762 }
763
764 /**
765 * Get a labelled checkbox to configure a boolean variable.
766 *
767 * @param $params Array
768 * Parameters are:
769 * var: The variable to be configured (required)
770 * label: The message name for the label (required)
771 * attribs: Additional attributes for the input element (optional)
772 * controlName: The name for the input element (optional)
773 * value: The current value of the variable (optional)
774 * help: The html for the help text (optional)
775 */
776 public function getCheckBox( $params ) {
777 if ( !isset( $params['controlName'] ) ) {
778 $params['controlName'] = 'config_' . $params['var'];
779 }
780
781 if ( !isset( $params['value'] ) ) {
782 $params['value'] = $this->getVar( $params['var'] );
783 }
784
785 if ( !isset( $params['attribs'] ) ) {
786 $params['attribs'] = array();
787 }
788 if ( !isset( $params['help'] ) ) {
789 $params['help'] = "";
790 }
791 if( isset( $params['rawtext'] ) ) {
792 $labelText = $params['rawtext'];
793 } else {
794 $labelText = $this->parse( wfMsg( $params['label'] ) );
795 }
796
797 return
798 "<div class=\"config-input-check\">\n" .
799 "<label>\n" .
800 Xml::check(
801 $params['controlName'],
802 $params['value'],
803 $params['attribs'] + array(
804 'id' => $params['controlName'],
805 'class' => 'config-input-text',
806 'tabindex' => $this->nextTabIndex(),
807 )
808 ) .
809 $labelText . "\n" .
810 "</label>\n" .
811 $params['help'] .
812 "</div>\n";
813 }
814
815 /**
816 * Get a set of labelled radio buttons.
817 *
818 * @param $params Array
819 * Parameters are:
820 * var: The variable to be configured (required)
821 * label: The message name for the label (required)
822 * itemLabelPrefix: The message name prefix for the item labels (required)
823 * values: List of allowed values (required)
824 * itemAttribs Array of attribute arrays, outer key is the value name (optional)
825 * commonAttribs Attribute array applied to all items
826 * controlName: The name for the input element (optional)
827 * value: The current value of the variable (optional)
828 * help: The html for the help text (optional)
829 */
830 public function getRadioSet( $params ) {
831 if ( !isset( $params['controlName'] ) ) {
832 $params['controlName'] = 'config_' . $params['var'];
833 }
834
835 if ( !isset( $params['value'] ) ) {
836 $params['value'] = $this->getVar( $params['var'] );
837 }
838
839 if ( !isset( $params['label'] ) ) {
840 $label = '';
841 } else {
842 $label = $params['label'];
843 }
844 if ( !isset( $params['help'] ) ) {
845 $params['help'] = "";
846 }
847 $s = "<ul>\n";
848 foreach ( $params['values'] as $value ) {
849 $itemAttribs = array();
850
851 if ( isset( $params['commonAttribs'] ) ) {
852 $itemAttribs = $params['commonAttribs'];
853 }
854
855 if ( isset( $params['itemAttribs'][$value] ) ) {
856 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
857 }
858
859 $checked = $value == $params['value'];
860 $id = $params['controlName'] . '_' . $value;
861 $itemAttribs['id'] = $id;
862 $itemAttribs['tabindex'] = $this->nextTabIndex();
863
864 $s .=
865 '<li>' .
866 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
867 '&#160;' .
868 Xml::tags( 'label', array( 'for' => $id ), $this->parse(
869 wfMsgNoTrans( $params['itemLabelPrefix'] . strtolower( $value ) )
870 ) ) .
871 "</li>\n";
872 }
873
874 $s .= "</ul>\n";
875
876 return $this->label( $label, $params['controlName'], $s, $params['help'] );
877 }
878
879 /**
880 * Output an error or warning box using a Status object.
881 */
882 public function showStatusBox( $status ) {
883 if( !$status->isGood() ) {
884 $text = $status->getWikiText();
885
886 if( $status->isOk() ) {
887 $box = $this->getWarningBox( $text );
888 } else {
889 $box = $this->getErrorBox( $text );
890 }
891
892 $this->output->addHTML( $box );
893 }
894 }
895
896 /**
897 * Convenience function to set variables based on form data.
898 * Assumes that variables containing "password" in the name are (potentially
899 * fake) passwords.
900 *
901 * @param $varNames Array
902 * @param $prefix String: the prefix added to variables to obtain form names
903 */
904 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
905 $newValues = array();
906
907 foreach ( $varNames as $name ) {
908 $value = trim( $this->request->getVal( $prefix . $name ) );
909 $newValues[$name] = $value;
910
911 if ( $value === null ) {
912 // Checkbox?
913 $this->setVar( $name, false );
914 } else {
915 if ( stripos( $name, 'password' ) !== false ) {
916 $this->setPassword( $name, $value );
917 } else {
918 $this->setVar( $name, $value );
919 }
920 }
921 }
922
923 return $newValues;
924 }
925
926 /**
927 * Helper for Installer::docLink()
928 */
929 protected function getDocUrl( $page ) {
930 $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
931
932 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
933 $url .= '&lastPage=' . urlencode( $this->currentPageName );
934 }
935
936 return $url;
937 }
938
939 }