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