Reverted r75832 per my comments on CR, unanswered for 19 days. Moving all help inform...
[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 $s .= "<div class=\"config-page\">\n";
474 $s .= "<div class=\"config-page-list\"><ul>\n";
475 $lastHappy = -1;
476
477 foreach ( $this->pageSequence as $id => $pageName ) {
478 $happy = !empty( $this->happyPages[$id] );
479 $s .= $this->getPageListItem(
480 $pageName,
481 $happy || $lastHappy == $id - 1,
482 $currentPageName
483 );
484
485 if ( $happy ) {
486 $lastHappy = $id;
487 }
488 }
489
490 $s .= "</ul><br/><ul>\n";
491
492 foreach ( $this->otherPages as $pageName ) {
493 $s .= $this->getPageListItem( $pageName, true, $currentPageName );
494 }
495
496 $s .= "</ul></div>\n"; // end list pane
497 $s .= 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
618 return
619 "<div class=\"config-help-wrapper\">\n" .
620 "<div class=\"config-help-message\">\n" .
621 $html .
622 "</div>\n" .
623 "<div class=\"config-show-help\">\n" .
624 "<a href=\"#\">" .
625 wfMsgHtml( 'config-show-help' ) .
626 "</a></div>\n" .
627 "<div class=\"config-hide-help\">\n" .
628 "<a href=\"#\">" .
629 wfMsgHtml( 'config-hide-help' ) .
630 "</a></div>\n</div>\n";
631 }
632
633 /**
634 * Output a help box.
635 */
636 public function showHelpBox( $msg /*, ... */ ) {
637 $args = func_get_args();
638 $html = call_user_func_array( array( $this, 'getHelpBox' ), $args );
639 $this->output->addHTML( $html );
640 }
641
642 /**
643 * Show a short informational message.
644 * Output looks like a list.
645 *
646 * @param $msg string
647 */
648 public function showMessage( $msg /*, ... */ ) {
649 $args = func_get_args();
650 array_shift( $args );
651 $html = '<div class="config-message">' .
652 $this->parse( wfMsgReal( $msg, $args, false, false, false ) ) .
653 "</div>\n";
654 $this->output->addHTML( $html );
655 }
656
657 /**
658 * @param $status Status
659 */
660 public function showStatusMessage( Status $status ) {
661 $text = $status->getWikiText();
662 $this->output->addWikiText(
663 "<div class=\"config-message\">\n" .
664 $text .
665 "</div>"
666 );
667 }
668
669 /**
670 * Label a control by wrapping a config-input div around it and putting a
671 * label before it.
672 */
673 public function label( $msg, $forId, $contents ) {
674 if ( strval( $msg ) == '' ) {
675 $labelText = '&#160;';
676 } else {
677 $labelText = wfMsgHtml( $msg );
678 }
679
680 $attributes = array( 'class' => 'config-label' );
681
682 if ( $forId ) {
683 $attributes['for'] = $forId;
684 }
685
686 return
687 "<div class=\"config-input\">\n" .
688 Xml::tags( 'label',
689 $attributes,
690 $labelText ) . "\n" .
691 $contents .
692 "</div>\n";
693 }
694
695 /**
696 * Get a labelled text box to configure a variable.
697 *
698 * @param $params Array
699 * Parameters are:
700 * var: The variable to be configured (required)
701 * label: The message name for the label (required)
702 * attribs: Additional attributes for the input element (optional)
703 * controlName: The name for the input element (optional)
704 * value: The current value of the variable (optional)
705 */
706 public function getTextBox( $params ) {
707 if ( !isset( $params['controlName'] ) ) {
708 $params['controlName'] = 'config_' . $params['var'];
709 }
710
711 if ( !isset( $params['value'] ) ) {
712 $params['value'] = $this->getVar( $params['var'] );
713 }
714
715 if ( !isset( $params['attribs'] ) ) {
716 $params['attribs'] = array();
717 }
718
719 return
720 $this->label(
721 $params['label'],
722 $params['controlName'],
723 Xml::input(
724 $params['controlName'],
725 30, // intended to be overridden by CSS
726 $params['value'],
727 $params['attribs'] + array(
728 'id' => $params['controlName'],
729 'class' => 'config-input-text',
730 'tabindex' => $this->nextTabIndex()
731 )
732 )
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 */
748 public function getPasswordBox( $params ) {
749 if ( !isset( $params['value'] ) ) {
750 $params['value'] = $this->getVar( $params['var'] );
751 }
752
753 if ( !isset( $params['attribs'] ) ) {
754 $params['attribs'] = array();
755 }
756
757 $params['value'] = $this->getFakePassword( $params['value'] );
758 $params['attribs']['type'] = 'password';
759
760 return $this->getTextBox( $params );
761 }
762
763 /**
764 * Get a labelled checkbox to configure a boolean variable.
765 *
766 * @param $params Array
767 * Parameters are:
768 * var: The variable to be configured (required)
769 * label: The message name for the label (required)
770 * attribs: Additional attributes for the input element (optional)
771 * controlName: The name for the input element (optional)
772 * value: The current value of the variable (optional)
773 */
774 public function getCheckBox( $params ) {
775 if ( !isset( $params['controlName'] ) ) {
776 $params['controlName'] = 'config_' . $params['var'];
777 }
778
779 if ( !isset( $params['value'] ) ) {
780 $params['value'] = $this->getVar( $params['var'] );
781 }
782
783 if ( !isset( $params['attribs'] ) ) {
784 $params['attribs'] = array();
785 }
786
787 if( isset( $params['rawtext'] ) ) {
788 $labelText = $params['rawtext'];
789 } else {
790 $labelText = $this->parse( wfMsg( $params['label'] ) );
791 }
792
793 return
794 "<div class=\"config-input-check\">\n" .
795 "<label>\n" .
796 Xml::check(
797 $params['controlName'],
798 $params['value'],
799 $params['attribs'] + array(
800 'id' => $params['controlName'],
801 'tabindex' => $this->nextTabIndex(),
802 )
803 ) .
804 $labelText . "\n" .
805 "</label>\n" .
806 "</div>\n";
807 }
808
809 /**
810 * Get a set of labelled radio buttons.
811 *
812 * @param $params Array
813 * Parameters are:
814 * var: The variable to be configured (required)
815 * label: The message name for the label (required)
816 * itemLabelPrefix: The message name prefix for the item labels (required)
817 * values: List of allowed values (required)
818 * itemAttribs Array of attribute arrays, outer key is the value name (optional)
819 * commonAttribs Attribute array applied to all items
820 * controlName: The name for the input element (optional)
821 * value: The current value of the variable (optional)
822 */
823 public function getRadioSet( $params ) {
824 if ( !isset( $params['controlName'] ) ) {
825 $params['controlName'] = 'config_' . $params['var'];
826 }
827
828 if ( !isset( $params['value'] ) ) {
829 $params['value'] = $this->getVar( $params['var'] );
830 }
831
832 if ( !isset( $params['label'] ) ) {
833 $label = '';
834 } else {
835 $label = $this->parse( wfMsgNoTrans( $params['label'] ) );
836 }
837
838 $s = "<label class=\"config-label\">\n" .
839 $label .
840 "</label>\n" .
841 "<ul class=\"config-settings-block\">\n";
842 foreach ( $params['values'] as $value ) {
843 $itemAttribs = array();
844
845 if ( isset( $params['commonAttribs'] ) ) {
846 $itemAttribs = $params['commonAttribs'];
847 }
848
849 if ( isset( $params['itemAttribs'][$value] ) ) {
850 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
851 }
852
853 $checked = $value == $params['value'];
854 $id = $params['controlName'] . '_' . $value;
855 $itemAttribs['id'] = $id;
856 $itemAttribs['tabindex'] = $this->nextTabIndex();
857
858 $s .=
859 '<li>' .
860 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
861 '&#160;' .
862 Xml::tags( 'label', array( 'for' => $id ), $this->parse(
863 wfMsgNoTrans( $params['itemLabelPrefix'] . strtolower( $value ) )
864 ) ) .
865 "</li>\n";
866 }
867
868 $s .= "</ul>\n";
869 return $s;
870 }
871
872 /**
873 * Output an error or warning box using a Status object.
874 */
875 public function showStatusBox( $status ) {
876 if( !$status->isGood() ) {
877 $text = $status->getWikiText();
878
879 if( $status->isOk() ) {
880 $box = $this->getWarningBox( $text );
881 } else {
882 $box = $this->getErrorBox( $text );
883 }
884
885 $this->output->addHTML( $box );
886 }
887 }
888
889 /**
890 * Convenience function to set variables based on form data.
891 * Assumes that variables containing "password" in the name are (potentially
892 * fake) passwords.
893 *
894 * @param $varNames Array
895 * @param $prefix String: the prefix added to variables to obtain form names
896 */
897 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
898 $newValues = array();
899
900 foreach ( $varNames as $name ) {
901 $value = trim( $this->request->getVal( $prefix . $name ) );
902 $newValues[$name] = $value;
903
904 if ( $value === null ) {
905 // Checkbox?
906 $this->setVar( $name, false );
907 } else {
908 if ( stripos( $name, 'password' ) !== false ) {
909 $this->setPassword( $name, $value );
910 } else {
911 $this->setVar( $name, $value );
912 }
913 }
914 }
915
916 return $newValues;
917 }
918
919 /**
920 * Helper for Installer::docLink()
921 */
922 protected function getDocUrl( $page ) {
923 $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
924
925 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
926 $url .= '&lastPage=' . urlencode( $this->currentPageName );
927 }
928
929 return $url;
930 }
931
932 }