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