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