More unused....
[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 $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, $wgRequest;
447
448 $mwLanguages = Language::getLanguageNames();
449 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
450
451 foreach ( $headerLanguages as $lang ) {
452 if ( isset( $mwLanguages[$lang] ) ) {
453 return $lang;
454 }
455 }
456
457 return $wgLanguageCode;
458 }
459
460 /**
461 * Called by execute() before page output starts, to show a page list.
462 *
463 * @param $currentPageName String
464 */
465 public function startPageWrapper( $currentPageName ) {
466 $s = "<div class=\"config-page-wrapper\">\n" .
467 "<div class=\"config-page-list\"><ul>\n";
468 $lastHappy = -1;
469
470 foreach ( $this->pageSequence as $id => $pageName ) {
471 $happy = !empty( $this->happyPages[$id] );
472 $s .= $this->getPageListItem(
473 $pageName,
474 $happy || $lastHappy == $id - 1,
475 $currentPageName
476 );
477
478 if ( $happy ) {
479 $lastHappy = $id;
480 }
481 }
482
483 $s .= "</ul><br/><ul>\n";
484
485 foreach ( $this->otherPages as $pageName ) {
486 $s .= $this->getPageListItem( $pageName, true, $currentPageName );
487 }
488
489 $s .= "</ul></div>\n". // end list pane
490 "<div class=\"config-page\">\n" .
491 Xml::element( 'h2', array(),
492 wfMsg( 'config-page-' . strtolower( $currentPageName ) ) );
493
494 $this->output->addHTMLNoFlush( $s );
495 }
496
497 /**
498 * Get a list item for the page list.
499 *
500 * @param $pageName String
501 * @param $enabled Boolean
502 * @param $currentPageName String
503 *
504 * @return string
505 */
506 public function getPageListItem( $pageName, $enabled, $currentPageName ) {
507 $s = "<li class=\"config-page-list-item\">";
508 $name = wfMsg( 'config-page-' . strtolower( $pageName ) );
509
510 if ( $enabled ) {
511 $query = array( 'page' => $pageName );
512
513 if ( !in_array( $pageName, $this->pageSequence ) ) {
514 if ( in_array( $currentPageName, $this->pageSequence ) ) {
515 $query['lastPage'] = $currentPageName;
516 }
517
518 $link = Xml::element( 'a',
519 array(
520 'href' => $this->getUrl( $query )
521 ),
522 $name
523 );
524 } else {
525 $link = htmlspecialchars( $name );
526 }
527
528 if ( $pageName == $currentPageName ) {
529 $s .= "<span class=\"config-page-current\">$link</span>";
530 } else {
531 $s .= $link;
532 }
533 } else {
534 $s .= Xml::element( 'span',
535 array(
536 'class' => 'config-page-disabled'
537 ),
538 $name
539 );
540 }
541
542 $s .= "</li>\n";
543
544 return $s;
545 }
546
547 /**
548 * Output some stuff after a page is finished.
549 */
550 public function endPageWrapper() {
551 $this->output->addHTMLNoFlush(
552 "</div>\n" .
553 "<br style=\"clear:both\"/>\n" .
554 "</div>" );
555 }
556
557 /**
558 * Get HTML for an error box with an icon.
559 *
560 * @param $text String: wikitext, get this with wfMsgNoTrans()
561 */
562 public function getErrorBox( $text ) {
563 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
564 }
565
566 /**
567 * Get HTML for a warning box with an icon.
568 *
569 * @param $text String: wikitext, get this with wfMsgNoTrans()
570 */
571 public function getWarningBox( $text ) {
572 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
573 }
574
575 /**
576 * Get HTML for an info box with an icon.
577 *
578 * @param $text String: wikitext, get this with wfMsgNoTrans()
579 * @param $icon String: icon name, file in skins/common/images
580 * @param $class String: additional class name to add to the wrapper div
581 */
582 public function getInfoBox( $text, $icon = 'info-32.png', $class = false ) {
583 $s =
584 "<div class=\"config-info $class\">\n" .
585 "<div class=\"config-info-left\">\n" .
586 Xml::element( 'img',
587 array(
588 'src' => '../skins/common/images/' . $icon,
589 'alt' => wfMsg( 'config-information' ),
590 )
591 ) . "\n" .
592 "</div>\n" .
593 "<div class=\"config-info-right\">\n" .
594 $this->parse( $text ) . "\n" .
595 "</div>\n" .
596 "<div style=\"clear: left;\"></div>\n" .
597 "</div>\n";
598 return $s;
599 }
600
601 /**
602 * Get small text indented help for a preceding form field.
603 * Parameters like wfMsg().
604 */
605 public function getHelpBox( $msg /*, ... */ ) {
606 $args = func_get_args();
607 array_shift( $args );
608 $args = array_map( 'htmlspecialchars', $args );
609 $text = wfMsgReal( $msg, $args, false, false, false );
610 $html = $this->parse( $text, true );
611
612 return
613 "<div class=\"config-help-wrapper\">\n" .
614 "<div class=\"config-help-message\">\n" .
615 $html .
616 "</div>\n" .
617 "<div class=\"config-show-help\">\n" .
618 "<a href=\"#\">" .
619 wfMsgHtml( 'config-show-help' ) .
620 "</a></div>\n" .
621 "<div class=\"config-hide-help\">\n" .
622 "<a href=\"#\">" .
623 wfMsgHtml( 'config-hide-help' ) .
624 "</a></div>\n</div>\n";
625 }
626
627 /**
628 * Output a help box.
629 */
630 public function showHelpBox( $msg /*, ... */ ) {
631 $args = func_get_args();
632 $html = call_user_func_array( array( $this, 'getHelpBox' ), $args );
633 $this->output->addHTML( $html );
634 }
635
636 /**
637 * Show a short informational message.
638 * Output looks like a list.
639 *
640 * @param srting $msg
641 */
642 public function showMessage( $msg /*, ... */ ) {
643 $args = func_get_args();
644 array_shift( $args );
645 $html = '<div class="config-message">' .
646 $this->parse( wfMsgReal( $msg, $args, false, false, false ) ) .
647 "</div>\n";
648 $this->output->addHTML( $html );
649 }
650
651 /**
652 * @param Status $status
653 */
654 public function showStatusMessage( Status $status ) {
655 $text = $status->getWikiText();
656 $this->output->addWikiText(
657 "<div class=\"config-message\">\n" .
658 $text .
659 "</div>"
660 );
661 }
662
663 /**
664 * Label a control by wrapping a config-input div around it and putting a
665 * label before it.
666 */
667 public function label( $msg, $forId, $contents ) {
668 if ( strval( $msg ) == '' ) {
669 $labelText = '&#160;';
670 } else {
671 $labelText = wfMsgHtml( $msg );
672 }
673
674 $attributes = array( 'class' => 'config-label' );
675
676 if ( $forId ) {
677 $attributes['for'] = $forId;
678 }
679
680 return
681 "<div class=\"config-input\">\n" .
682 Xml::tags( 'label',
683 $attributes,
684 $labelText ) . "\n" .
685 $contents .
686 "</div>\n";
687 }
688
689 /**
690 * Get a labelled text box to configure a variable.
691 *
692 * @param $params Array
693 * Parameters are:
694 * var: The variable to be configured (required)
695 * label: The message name for the label (required)
696 * attribs: Additional attributes for the input element (optional)
697 * controlName: The name for the input element (optional)
698 * value: The current value of the variable (optional)
699 */
700 public function getTextBox( $params ) {
701 if ( !isset( $params['controlName'] ) ) {
702 $params['controlName'] = 'config_' . $params['var'];
703 }
704
705 if ( !isset( $params['value'] ) ) {
706 $params['value'] = $this->getVar( $params['var'] );
707 }
708
709 if ( !isset( $params['attribs'] ) ) {
710 $params['attribs'] = array();
711 }
712
713 return
714 $this->label(
715 $params['label'],
716 $params['controlName'],
717 Xml::input(
718 $params['controlName'],
719 30, // intended to be overridden by CSS
720 $params['value'],
721 $params['attribs'] + array(
722 'id' => $params['controlName'],
723 'class' => 'config-input-text',
724 'tabindex' => $this->nextTabIndex()
725 )
726 )
727 );
728 }
729
730 /**
731 * Get a labelled password box to configure a variable.
732 *
733 * Implements password hiding
734 * @param $params Array
735 * Parameters are:
736 * var: The variable to be configured (required)
737 * label: The message name for the label (required)
738 * attribs: Additional attributes for the input element (optional)
739 * controlName: The name for the input element (optional)
740 * value: The current value of the variable (optional)
741 */
742 public function getPasswordBox( $params ) {
743 if ( !isset( $params['value'] ) ) {
744 $params['value'] = $this->getVar( $params['var'] );
745 }
746
747 if ( !isset( $params['attribs'] ) ) {
748 $params['attribs'] = array();
749 }
750
751 $params['value'] = $this->getFakePassword( $params['value'] );
752 $params['attribs']['type'] = 'password';
753
754 return $this->getTextBox( $params );
755 }
756
757 /**
758 * Get a labelled checkbox to configure a boolean variable.
759 *
760 * @param $params Array
761 * Parameters are:
762 * var: The variable to be configured (required)
763 * label: The message name for the label (required)
764 * attribs: Additional attributes for the input element (optional)
765 * controlName: The name for the input element (optional)
766 * value: The current value of the variable (optional)
767 */
768 public function getCheckBox( $params ) {
769 if ( !isset( $params['controlName'] ) ) {
770 $params['controlName'] = 'config_' . $params['var'];
771 }
772
773 if ( !isset( $params['value'] ) ) {
774 $params['value'] = $this->getVar( $params['var'] );
775 }
776
777 if ( !isset( $params['attribs'] ) ) {
778 $params['attribs'] = array();
779 }
780
781 if( isset( $params['rawtext'] ) ) {
782 $labelText = $params['rawtext'];
783 } else {
784 $labelText = $this->parse( wfMsg( $params['label'] ) );
785 }
786
787 return
788 "<div class=\"config-input-check\">\n" .
789 "<label>\n" .
790 Xml::check(
791 $params['controlName'],
792 $params['value'],
793 $params['attribs'] + array(
794 'id' => $params['controlName'],
795 'class' => 'config-input-text',
796 'tabindex' => $this->nextTabIndex(),
797 )
798 ) .
799 $labelText . "\n" .
800 "</label>\n" .
801 "</div>\n";
802 }
803
804 /**
805 * Get a set of labelled radio buttons.
806 *
807 * @param $params Array
808 * Parameters are:
809 * var: The variable to be configured (required)
810 * label: The message name for the label (required)
811 * itemLabelPrefix: The message name prefix for the item labels (required)
812 * values: List of allowed values (required)
813 * itemAttribs Array of attribute arrays, outer key is the value name (optional)
814 * commonAttribs Attribute array applied to all items
815 * controlName: The name for the input element (optional)
816 * value: The current value of the variable (optional)
817 */
818 public function getRadioSet( $params ) {
819 if ( !isset( $params['controlName'] ) ) {
820 $params['controlName'] = 'config_' . $params['var'];
821 }
822
823 if ( !isset( $params['value'] ) ) {
824 $params['value'] = $this->getVar( $params['var'] );
825 }
826
827 if ( !isset( $params['label'] ) ) {
828 $label = '';
829 } else {
830 $label = $this->parse( wfMsgNoTrans( $params['label'] ) );
831 }
832
833 $s = "<label class=\"config-label\">\n" .
834 $label .
835 "</label>\n" .
836 "<ul class=\"config-settings-block\">\n";
837 foreach ( $params['values'] as $value ) {
838 $itemAttribs = array();
839
840 if ( isset( $params['commonAttribs'] ) ) {
841 $itemAttribs = $params['commonAttribs'];
842 }
843
844 if ( isset( $params['itemAttribs'][$value] ) ) {
845 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
846 }
847
848 $checked = $value == $params['value'];
849 $id = $params['controlName'] . '_' . $value;
850 $itemAttribs['id'] = $id;
851 $itemAttribs['tabindex'] = $this->nextTabIndex();
852
853 $s .=
854 '<li>' .
855 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
856 '&#160;' .
857 Xml::tags( 'label', array( 'for' => $id ), $this->parse(
858 wfMsgNoTrans( $params['itemLabelPrefix'] . strtolower( $value ) )
859 ) ) .
860 "</li>\n";
861 }
862
863 $s .= "</ul>\n";
864 return $s;
865 }
866
867 /**
868 * Output an error or warning box using a Status object.
869 */
870 public function showStatusBox( $status ) {
871 if( !$status->isGood() ) {
872 $text = $status->getWikiText();
873
874 if( $status->isOk() ) {
875 $box = $this->getWarningBox( $text );
876 } else {
877 $box = $this->getErrorBox( $text );
878 }
879
880 $this->output->addHTML( $box );
881 }
882 }
883
884 /**
885 * Convenience function to set variables based on form data.
886 * Assumes that variables containing "password" in the name are (potentially
887 * fake) passwords.
888 *
889 * @param $varNames Array
890 * @param $prefix String: the prefix added to variables to obtain form names
891 */
892 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
893 $newValues = array();
894
895 foreach ( $varNames as $name ) {
896 $value = trim( $this->request->getVal( $prefix . $name ) );
897 $newValues[$name] = $value;
898
899 if ( $value === null ) {
900 // Checkbox?
901 $this->setVar( $name, false );
902 } else {
903 if ( stripos( $name, 'password' ) !== false ) {
904 $this->setPassword( $name, $value );
905 } else {
906 $this->setVar( $name, $value );
907 }
908 }
909 }
910
911 return $newValues;
912 }
913
914 /**
915 * Get the starting tags of a fieldset.
916 *
917 * @param $legend String: message name
918 */
919 public function getFieldsetStart( $legend ) {
920 return "\n<fieldset><legend>" . wfMsgHtml( $legend ) . "</legend>\n";
921 }
922
923 /**
924 * Get the end tag of a fieldset.
925 */
926 public function getFieldsetEnd() {
927 return "</fieldset>\n";
928 }
929
930 /**
931 * Helper for Installer::docLink()
932 */
933 public function getDocUrl( $page ) {
934 $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
935
936 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
937 $url .= '&lastPage=' . urlencode( $this->currentPageName );
938 }
939
940 return $url;
941 }
942
943 }