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