w/s cleanup
[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 hooks
119 global $wgParser;
120 $wgParser->setHook( 'downloadlink', array( $this, 'downloadLinkHook' ) );
121 $wgParser->setHook( 'doclink', array( $this, 'docLink' ) );
122 }
123
124 /**
125 * Main entry point.
126 *
127 * @param $session Array: initial session array
128 *
129 * @return Array: new session array
130 */
131 public function execute( array $session ) {
132 $this->session = $session;
133
134 if ( isset( $session['settings'] ) ) {
135 $this->settings = $session['settings'] + $this->settings;
136 }
137
138 $this->exportVars();
139 $this->setupLanguage();
140
141 if( ( $this->getVar( '_InstallDone' ) || $this->getVar( '_UpgradeDone' ) )
142 && $this->request->getVal( 'localsettings' ) )
143 {
144 $this->request->response()->header( 'Content-type: application/x-httpd-php' );
145 $this->request->response()->header(
146 'Content-Disposition: attachment; filename="LocalSettings.php"'
147 );
148
149 $ls = new LocalSettingsGenerator( $this );
150 echo $ls->getText();
151 return $this->session;
152 }
153
154 $cssDir = $this->request->getVal( 'css' );
155 if( $cssDir ) {
156 $cssDir = ( $cssDir == 'rtl' ? 'rtl' : 'ltr' );
157 $this->request->response()->header( 'Content-type: text/css' );
158 echo $this->output->getCSS( $cssDir );
159 return $this->session;
160 }
161
162 if ( isset( $session['happyPages'] ) ) {
163 $this->happyPages = $session['happyPages'];
164 } else {
165 $this->happyPages = array();
166 }
167
168 if ( isset( $session['skippedPages'] ) ) {
169 $this->skippedPages = $session['skippedPages'];
170 } else {
171 $this->skippedPages = array();
172 }
173
174 $lowestUnhappy = $this->getLowestUnhappy();
175
176 # Special case for Creative Commons partner chooser box.
177 if ( $this->request->getVal( 'SubmitCC' ) ) {
178 $page = $this->getPageByName( 'Options' );
179 $this->output->useShortHeader();
180 $this->output->allowFrames();
181 $page->submitCC();
182 return $this->finish();
183 }
184
185 if ( $this->request->getVal( 'ShowCC' ) ) {
186 $page = $this->getPageByName( 'Options' );
187 $this->output->useShortHeader();
188 $this->output->allowFrames();
189 $this->output->addHTML( $page->getCCDoneBox() );
190 return $this->finish();
191 }
192
193 # Get the page name.
194 $pageName = $this->request->getVal( 'page' );
195
196 if ( in_array( $pageName, $this->otherPages ) ) {
197 # Out of sequence
198 $pageId = false;
199 $page = $this->getPageByName( $pageName );
200 } else {
201 # Main sequence
202 if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) {
203 $pageId = $lowestUnhappy;
204 } else {
205 $pageId = array_search( $pageName, $this->pageSequence );
206 }
207
208 # If necessary, move back to the lowest-numbered unhappy page
209 if ( $pageId > $lowestUnhappy ) {
210 $pageId = $lowestUnhappy;
211 if ( $lowestUnhappy == 0 ) {
212 # Knocked back to start, possible loss of session data.
213 $this->showSessionWarning = true;
214 }
215 }
216
217 $pageName = $this->pageSequence[$pageId];
218 $page = $this->getPageByName( $pageName );
219 }
220
221 # If a back button was submitted, go back without submitting the form data.
222 if ( $this->request->wasPosted() && $this->request->getBool( 'submit-back' ) ) {
223 if ( $this->request->getVal( 'lastPage' ) ) {
224 $nextPage = $this->request->getVal( 'lastPage' );
225 } elseif ( $pageId !== false ) {
226 # Main sequence page
227 # Skip the skipped pages
228 $nextPageId = $pageId;
229
230 do {
231 $nextPageId--;
232 $nextPage = $this->pageSequence[$nextPageId];
233 } while( isset( $this->skippedPages[$nextPage] ) );
234 } else {
235 $nextPage = $this->pageSequence[$lowestUnhappy];
236 }
237
238 $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
239 return $this->finish();
240 }
241
242 # Execute the page.
243 $this->currentPageName = $page->getName();
244 $this->startPageWrapper( $pageName );
245
246 $result = $page->execute();
247
248 $this->endPageWrapper();
249
250 if ( $result == 'skip' ) {
251 # Page skipped without explicit submission.
252 # Skip it when we click "back" so that we don't just go forward again.
253 $this->skippedPages[$pageName] = true;
254 $result = 'continue';
255 } else {
256 unset( $this->skippedPages[$pageName] );
257 }
258
259 # If it was posted, the page can request a continue to the next page.
260 if ( $result === 'continue' && !$this->output->headerDone() ) {
261 if ( $pageId !== false ) {
262 $this->happyPages[$pageId] = true;
263 }
264
265 $lowestUnhappy = $this->getLowestUnhappy();
266
267 if ( $this->request->getVal( 'lastPage' ) ) {
268 $nextPage = $this->request->getVal( 'lastPage' );
269 } elseif ( $pageId !== false ) {
270 $nextPage = $this->pageSequence[$pageId + 1];
271 } else {
272 $nextPage = $this->pageSequence[$lowestUnhappy];
273 }
274
275 if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) {
276 $nextPage = $this->pageSequence[$lowestUnhappy];
277 }
278
279 $this->output->redirect( $this->getUrl( array( 'page' => $nextPage ) ) );
280 }
281
282 return $this->finish();
283 }
284
285 /**
286 * Find the next page in sequence that hasn't been completed
287 * @return int
288 */
289 public function getLowestUnhappy() {
290 if ( count( $this->happyPages ) == 0 ) {
291 return 0;
292 } else {
293 return max( array_keys( $this->happyPages ) ) + 1;
294 }
295 }
296
297 /**
298 * Start the PHP session. This may be called before execute() to start the PHP session.
299 *
300 * @return bool
301 */
302 public function startSession() {
303 if( wfIniGetBool( 'session.auto_start' ) || session_id() ) {
304 // Done already
305 return true;
306 }
307
308 $this->phpErrors = array();
309 set_error_handler( array( $this, 'errorHandler' ) );
310 session_start();
311 restore_error_handler();
312
313 if ( $this->phpErrors ) {
314 $this->showError( 'config-session-error', $this->phpErrors[0] );
315 return false;
316 }
317
318 return true;
319 }
320
321 /**
322 * Get a hash of data identifying this MW installation.
323 *
324 * This is used by mw-config/index.php to prevent multiple installations of MW
325 * on the same cookie domain from interfering with each other.
326 *
327 * @return string
328 */
329 public function getFingerprint() {
330 // Get the base URL of the installation
331 $url = $this->request->getFullRequestURL();
332 if ( preg_match( '!^(.*\?)!', $url, $m) ) {
333 // Trim query string
334 $url = $m[1];
335 }
336 if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
337 // This... seems to try to get the base path from
338 // the /mw-config/index.php. Kinda scary though?
339 $url = $m[1];
340 }
341 return md5( serialize( array(
342 'local path' => dirname( dirname( __FILE__ ) ),
343 'url' => $url,
344 'version' => $GLOBALS['wgVersion']
345 ) ) );
346 }
347
348 /**
349 * Show an error message in a box. Parameters are like wfMsg().
350 */
351 public function showError( $msg /*...*/ ) {
352 $args = func_get_args();
353 array_shift( $args );
354 $args = array_map( 'htmlspecialchars', $args );
355 $msg = wfMsgReal( $msg, $args, false, false, false );
356 $this->output->addHTML( $this->getErrorBox( $msg ) );
357 }
358
359 /**
360 * Temporary error handler for session start debugging.
361 */
362 public function errorHandler( $errno, $errstr ) {
363 $this->phpErrors[] = $errstr;
364 }
365
366 /**
367 * Clean up from execute()
368 *
369 * @return array
370 */
371 public function finish() {
372 $this->output->output();
373
374 $this->session['happyPages'] = $this->happyPages;
375 $this->session['skippedPages'] = $this->skippedPages;
376 $this->session['settings'] = $this->settings;
377
378 return $this->session;
379 }
380
381 /**
382 * We're restarting the installation, reset the session, happyPages, etc
383 */
384 public function reset() {
385 $this->session = array();
386 $this->happyPages = array();
387 $this->settings = array();
388 }
389
390 /**
391 * Get a URL for submission back to the same script.
392 *
393 * @param $query array
394 * @return string
395 */
396 public function getUrl( $query = array() ) {
397 $url = $this->request->getRequestURL();
398 # Remove existing query
399 $url = preg_replace( '/\?.*$/', '', $url );
400
401 if ( $query ) {
402 $url .= '?' . wfArrayToCGI( $query );
403 }
404
405 return $url;
406 }
407
408 /**
409 * Get a WebInstallerPage by name.
410 *
411 * @param $pageName String
412 * @return WebInstallerPage
413 */
414 public function getPageByName( $pageName ) {
415 $pageClass = 'WebInstaller_' . $pageName;
416
417 return new $pageClass( $this );
418 }
419
420 /**
421 * Get a session variable.
422 *
423 * @param $name String
424 * @param $default
425 */
426 public function getSession( $name, $default = null ) {
427 if ( !isset( $this->session[$name] ) ) {
428 return $default;
429 } else {
430 return $this->session[$name];
431 }
432 }
433
434 /**
435 * Set a session variable.
436 * @param $name String key for the variable
437 * @param $value Mixed
438 */
439 public function setSession( $name, $value ) {
440 $this->session[$name] = $value;
441 }
442
443 /**
444 * Get the next tabindex attribute value.
445 * @return int
446 */
447 public function nextTabIndex() {
448 return $this->tabIndex++;
449 }
450
451 /**
452 * Initializes language-related variables.
453 */
454 public function setupLanguage() {
455 global $wgLang, $wgContLang, $wgLanguageCode;
456
457 if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
458 $wgLanguageCode = $this->getAcceptLanguage();
459 $wgLang = $wgContLang = Language::factory( $wgLanguageCode );
460 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
461 $this->setVar( '_UserLang', $wgLanguageCode );
462 } else {
463 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
464 $wgLang = Language::factory( $this->getVar( '_UserLang' ) );
465 $wgContLang = Language::factory( $wgLanguageCode );
466 }
467 }
468
469 /**
470 * Retrieves MediaWiki language from Accept-Language HTTP header.
471 *
472 * @return string
473 */
474 public function getAcceptLanguage() {
475 global $wgLanguageCode, $wgRequest;
476
477 $mwLanguages = Language::getLanguageNames();
478 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
479
480 foreach ( $headerLanguages as $lang ) {
481 if ( isset( $mwLanguages[$lang] ) ) {
482 return $lang;
483 }
484 }
485
486 return $wgLanguageCode;
487 }
488
489 /**
490 * Called by execute() before page output starts, to show a page list.
491 *
492 * @param $currentPageName String
493 */
494 private function startPageWrapper( $currentPageName ) {
495 $s = "<div class=\"config-page-wrapper\">\n";
496 $s .= "<div class=\"config-page\">\n";
497 $s .= "<div class=\"config-page-list\"><ul>\n";
498 $lastHappy = -1;
499
500 foreach ( $this->pageSequence as $id => $pageName ) {
501 $happy = !empty( $this->happyPages[$id] );
502 $s .= $this->getPageListItem(
503 $pageName,
504 $happy || $lastHappy == $id - 1,
505 $currentPageName
506 );
507
508 if ( $happy ) {
509 $lastHappy = $id;
510 }
511 }
512
513 $s .= "</ul><br/><ul>\n";
514 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
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 class=\"visualClear\"></div>\n" .
578 "</div>\n" .
579 "<div class=\"visualClear\"></div>\n" .
580 "</div>" );
581 }
582
583 /**
584 * Get HTML for an error box with an icon.
585 *
586 * @param $text String: wikitext, get this with wfMsgNoTrans()
587 *
588 * @return string
589 */
590 public function getErrorBox( $text ) {
591 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
592 }
593
594 /**
595 * Get HTML for a warning box with an icon.
596 *
597 * @param $text String: wikitext, get this with wfMsgNoTrans()
598 *
599 * @return string
600 */
601 public function getWarningBox( $text ) {
602 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
603 }
604
605 /**
606 * Get HTML for an info box with an icon.
607 *
608 * @param $text String: wikitext, get this with wfMsgNoTrans()
609 * @param $icon String: icon name, file in skins/common/images
610 * @param $class String: additional class name to add to the wrapper div
611 *
612 * @return string
613 */
614 public function getInfoBox( $text, $icon = false, $class = false ) {
615 $text = $this->parse( $text, true );
616 $icon = ( $icon == false ) ? '../skins/common/images/info-32.png' : '../skins/common/images/'.$icon;
617 $alt = wfMsg( 'config-information' );
618 return Xml::infoBox( $text, $icon, $alt, $class, false );
619 }
620
621 /**
622 * Get small text indented help for a preceding form field.
623 * Parameters like wfMsg().
624 *
625 * @return string
626 */
627 public function getHelpBox( $msg /*, ... */ ) {
628 $args = func_get_args();
629 array_shift( $args );
630 $args = array_map( 'htmlspecialchars', $args );
631 $text = wfMsgReal( $msg, $args, false, false, false );
632 $html = htmlspecialchars( $text );
633 $html = $this->parse( $text, true );
634
635 return "<div class=\"mw-help-field-container\">\n" .
636 "<span class=\"mw-help-field-hint\">" . wfMsgHtml( 'config-help' ) . "</span>\n" .
637 "<span class=\"mw-help-field-data\">" . $html . "</span>\n" .
638 "</div>\n";
639 }
640
641 /**
642 * Output a help box.
643 * @param $msg String key for wfMsg()
644 */
645 public function showHelpBox( $msg /*, ... */ ) {
646 $args = func_get_args();
647 $html = call_user_func_array( array( $this, 'getHelpBox' ), $args );
648 $this->output->addHTML( $html );
649 }
650
651 /**
652 * Show a short informational message.
653 * Output looks like a list.
654 *
655 * @param $msg string
656 */
657 public function showMessage( $msg /*, ... */ ) {
658 $args = func_get_args();
659 array_shift( $args );
660 $html = '<div class="config-message">' .
661 $this->parse( wfMsgReal( $msg, $args, false, false, false ) ) .
662 "</div>\n";
663 $this->output->addHTML( $html );
664 }
665
666 /**
667 * @param $status Status
668 */
669 public function showStatusMessage( Status $status ) {
670 $text = $status->getWikiText();
671 $this->output->addWikiText(
672 "<div class=\"config-message\">\n" .
673 $text .
674 "</div>"
675 );
676 }
677
678 /**
679 * Label a control by wrapping a config-input div around it and putting a
680 * label before it.
681 *
682 * @return string
683 */
684 public function label( $msg, $forId, $contents, $helpData = "" ) {
685 if ( strval( $msg ) == '' ) {
686 $labelText = '&#160;';
687 } else {
688 $labelText = wfMsgHtml( $msg );
689 }
690
691 $attributes = array( 'class' => 'config-label' );
692
693 if ( $forId ) {
694 $attributes['for'] = $forId;
695 }
696
697 return
698 "<div class=\"config-block\">\n" .
699 " <div class=\"config-block-label\">\n" .
700 Xml::tags( 'label',
701 $attributes,
702 $labelText ) . "\n" .
703 $helpData .
704 " </div>\n" .
705 " <div class=\"config-block-elements\">\n" .
706 $contents .
707 " </div>\n" .
708 "</div>\n";
709 }
710
711 /**
712 * Get a labelled text box to configure a variable.
713 *
714 * @param $params Array
715 * Parameters are:
716 * var: The variable to be configured (required)
717 * label: The message name for the label (required)
718 * attribs: Additional attributes for the input element (optional)
719 * controlName: The name for the input element (optional)
720 * value: The current value of the variable (optional)
721 * help: The html for the help text (optional)
722 *
723 * @return string
724 */
725 public function getTextBox( $params ) {
726 if ( !isset( $params['controlName'] ) ) {
727 $params['controlName'] = 'config_' . $params['var'];
728 }
729
730 if ( !isset( $params['value'] ) ) {
731 $params['value'] = $this->getVar( $params['var'] );
732 }
733
734 if ( !isset( $params['attribs'] ) ) {
735 $params['attribs'] = array();
736 }
737 if ( !isset( $params['help'] ) ) {
738 $params['help'] = "";
739 }
740 return
741 $this->label(
742 $params['label'],
743 $params['controlName'],
744 Xml::input(
745 $params['controlName'],
746 30, // intended to be overridden by CSS
747 $params['value'],
748 $params['attribs'] + array(
749 'id' => $params['controlName'],
750 'class' => 'config-input-text',
751 'tabindex' => $this->nextTabIndex()
752 )
753 ),
754 $params['help']
755 );
756 }
757
758 /**
759 * Get a labelled textarea to configure a variable
760 *
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 * @return string
771 */
772 public function getTextArea( $params ) {
773 if ( !isset( $params['controlName'] ) ) {
774 $params['controlName'] = 'config_' . $params['var'];
775 }
776
777 if ( !isset( $params['value'] ) ) {
778 $params['value'] = $this->getVar( $params['var'] );
779 }
780
781 if ( !isset( $params['attribs'] ) ) {
782 $params['attribs'] = array();
783 }
784 if ( !isset( $params['help'] ) ) {
785 $params['help'] = "";
786 }
787 return
788 $this->label(
789 $params['label'],
790 $params['controlName'],
791 Xml::textarea(
792 $params['controlName'],
793 $params['value'],
794 30,
795 5,
796 $params['attribs'] + array(
797 'id' => $params['controlName'],
798 'class' => 'config-input-text',
799 'tabindex' => $this->nextTabIndex()
800 )
801 ),
802 $params['help']
803 );
804 }
805
806 /**
807 * Get a labelled password box to configure a variable.
808 *
809 * Implements password hiding
810 * @param $params Array
811 * Parameters are:
812 * var: The variable to be configured (required)
813 * label: The message name for the label (required)
814 * attribs: Additional attributes for the input element (optional)
815 * controlName: The name for the input element (optional)
816 * value: The current value of the variable (optional)
817 * help: The html for the help text (optional)
818 *
819 * @return string
820 */
821 public function getPasswordBox( $params ) {
822 if ( !isset( $params['value'] ) ) {
823 $params['value'] = $this->getVar( $params['var'] );
824 }
825
826 if ( !isset( $params['attribs'] ) ) {
827 $params['attribs'] = array();
828 }
829
830 $params['value'] = $this->getFakePassword( $params['value'] );
831 $params['attribs']['type'] = 'password';
832
833 return $this->getTextBox( $params );
834 }
835
836 /**
837 * Get a labelled checkbox to configure a boolean variable.
838 *
839 * @param $params Array
840 * Parameters are:
841 * var: The variable to be configured (required)
842 * label: The message name for the label (required)
843 * attribs: Additional attributes for the input element (optional)
844 * controlName: The name for the input element (optional)
845 * value: The current value of the variable (optional)
846 * help: The html for the help text (optional)
847 *
848 * @return string
849 */
850 public function getCheckBox( $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['attribs'] ) ) {
860 $params['attribs'] = array();
861 }
862 if ( !isset( $params['help'] ) ) {
863 $params['help'] = "";
864 }
865 if( isset( $params['rawtext'] ) ) {
866 $labelText = $params['rawtext'];
867 } else {
868 $labelText = $this->parse( wfMsg( $params['label'] ) );
869 }
870
871 return
872 "<div class=\"config-input-check\">\n" .
873 $params['help'] .
874 "<label>\n" .
875 Xml::check(
876 $params['controlName'],
877 $params['value'],
878 $params['attribs'] + array(
879 'id' => $params['controlName'],
880 'tabindex' => $this->nextTabIndex(),
881 )
882 ) .
883 $labelText . "\n" .
884 "</label>\n" .
885 "</div>\n";
886 }
887
888 /**
889 * Get a set of labelled radio buttons.
890 *
891 * @param $params Array
892 * Parameters are:
893 * var: The variable to be configured (required)
894 * label: The message name for the label (required)
895 * itemLabelPrefix: The message name prefix for the item labels (required)
896 * values: List of allowed values (required)
897 * itemAttribs Array of attribute arrays, outer key is the value name (optional)
898 * commonAttribs Attribute array applied to all items
899 * controlName: The name for the input element (optional)
900 * value: The current value of the variable (optional)
901 * help: The html for the help text (optional)
902 *
903 * @return string
904 */
905 public function getRadioSet( $params ) {
906 if ( !isset( $params['controlName'] ) ) {
907 $params['controlName'] = 'config_' . $params['var'];
908 }
909
910 if ( !isset( $params['value'] ) ) {
911 $params['value'] = $this->getVar( $params['var'] );
912 }
913
914 if ( !isset( $params['label'] ) ) {
915 $label = '';
916 } else {
917 $label = $params['label'];
918 }
919 if ( !isset( $params['help'] ) ) {
920 $params['help'] = "";
921 }
922 $s = "<ul>\n";
923 foreach ( $params['values'] as $value ) {
924 $itemAttribs = array();
925
926 if ( isset( $params['commonAttribs'] ) ) {
927 $itemAttribs = $params['commonAttribs'];
928 }
929
930 if ( isset( $params['itemAttribs'][$value] ) ) {
931 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
932 }
933
934 $checked = $value == $params['value'];
935 $id = $params['controlName'] . '_' . $value;
936 $itemAttribs['id'] = $id;
937 $itemAttribs['tabindex'] = $this->nextTabIndex();
938
939 $s .=
940 '<li>' .
941 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
942 '&#160;' .
943 Xml::tags( 'label', array( 'for' => $id ), $this->parse(
944 wfMsgNoTrans( $params['itemLabelPrefix'] . strtolower( $value ) )
945 ) ) .
946 "</li>\n";
947 }
948
949 $s .= "</ul>\n";
950
951 return $this->label( $label, $params['controlName'], $s, $params['help'] );
952 }
953
954 /**
955 * Output an error or warning box using a Status object.
956 */
957 public function showStatusBox( $status ) {
958 if( !$status->isGood() ) {
959 $text = $status->getWikiText();
960
961 if( $status->isOk() ) {
962 $box = $this->getWarningBox( $text );
963 } else {
964 $box = $this->getErrorBox( $text );
965 }
966
967 $this->output->addHTML( $box );
968 }
969 }
970
971 /**
972 * Convenience function to set variables based on form data.
973 * Assumes that variables containing "password" in the name are (potentially
974 * fake) passwords.
975 *
976 * @param $varNames Array
977 * @param $prefix String: the prefix added to variables to obtain form names
978 *
979 * @return array
980 */
981 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
982 $newValues = array();
983
984 foreach ( $varNames as $name ) {
985 $value = trim( $this->request->getVal( $prefix . $name ) );
986 $newValues[$name] = $value;
987
988 if ( $value === null ) {
989 // Checkbox?
990 $this->setVar( $name, false );
991 } else {
992 if ( stripos( $name, 'password' ) !== false ) {
993 $this->setPassword( $name, $value );
994 } else {
995 $this->setVar( $name, $value );
996 }
997 }
998 }
999
1000 return $newValues;
1001 }
1002
1003 /**
1004 * Helper for Installer::docLink()
1005 *
1006 * @return string
1007 */
1008 protected function getDocUrl( $page ) {
1009 $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
1010
1011 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
1012 $url .= '&lastPage=' . urlencode( $this->currentPageName );
1013 }
1014
1015 return $url;
1016 }
1017
1018 /**
1019 * Extension tag hook for a documentation link.
1020 *
1021 * @return string
1022 */
1023 public function docLink( $linkText, $attribs, $parser ) {
1024 $url = $this->getDocUrl( $attribs['href'] );
1025 return '<a href="' . htmlspecialchars( $url ) . '">' .
1026 htmlspecialchars( $linkText ) .
1027 '</a>';
1028 }
1029
1030 /**
1031 * Helper for "Download LocalSettings" link on WebInstall_Complete
1032 *
1033 * @return String Html for download link
1034 */
1035 public function downloadLinkHook( $text, $attribs, $parser ) {
1036 $img = Html::element( 'img', array(
1037 'src' => '../skins/common/images/download-32.png',
1038 'width' => '32',
1039 'height' => '32',
1040 ) );
1041 $anchor = Html::rawElement( 'a',
1042 array( 'href' => $this->getURL( array( 'localsettings' => 1 ) ) ),
1043 $img . ' ' . wfMsgHtml( 'config-download-localsettings' ) );
1044 return Html::rawElement( 'div', array( 'class' => 'config-download-link' ), $anchor );
1045 }
1046 }