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