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