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