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