* (bug 27170) [Installer] Install now completes when choosing a CC license with the...
[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 public function startSession() {
301 if( wfIniGetBool( 'session.auto_start' ) || session_id() ) {
302 // Done already
303 return true;
304 }
305
306 $this->phpErrors = array();
307 set_error_handler( array( $this, 'errorHandler' ) );
308 session_start();
309 restore_error_handler();
310
311 if ( $this->phpErrors ) {
312 $this->showError( 'config-session-error', $this->phpErrors[0] );
313 return false;
314 }
315
316 return true;
317 }
318
319 /**
320 * Get a hash of data identifying this MW installation.
321 *
322 * This is used by mw-config/index.php to prevent multiple installations of MW
323 * on the same cookie domain from interfering with each other.
324 */
325 public function getFingerprint() {
326 // Get the base URL of the installation
327 $url = $this->request->getFullRequestURL();
328 if ( preg_match( '!^(.*\?)!', $url, $m) ) {
329 // Trim query string
330 $url = $m[1];
331 }
332 if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
333 // This... seems to try to get the base path from
334 // the /mw-config/index.php. Kinda scary though?
335 $url = $m[1];
336 }
337 return md5( serialize( array(
338 'local path' => dirname( dirname( __FILE__ ) ),
339 'url' => $url,
340 'version' => $GLOBALS['wgVersion']
341 ) ) );
342 }
343
344 /**
345 * Show an error message in a box. Parameters are like wfMsg().
346 */
347 public function showError( $msg /*...*/ ) {
348 $args = func_get_args();
349 array_shift( $args );
350 $args = array_map( 'htmlspecialchars', $args );
351 $msg = wfMsgReal( $msg, $args, false, false, false );
352 $this->output->addHTML( $this->getErrorBox( $msg ) );
353 }
354
355 /**
356 * Temporary error handler for session start debugging.
357 */
358 public function errorHandler( $errno, $errstr ) {
359 $this->phpErrors[] = $errstr;
360 }
361
362 /**
363 * Clean up from execute()
364 *
365 * @return array
366 */
367 public function finish() {
368 $this->output->output();
369
370 $this->session['happyPages'] = $this->happyPages;
371 $this->session['skippedPages'] = $this->skippedPages;
372 $this->session['settings'] = $this->settings;
373
374 return $this->session;
375 }
376
377 /**
378 * We're restarting the installation, reset the session, happyPages, etc
379 */
380 public function reset() {
381 $this->session = array();
382 $this->happyPages = array();
383 $this->settings = array();
384 }
385
386 /**
387 * Get a URL for submission back to the same script.
388 *
389 * @param $query: Array
390 * @return string
391 */
392 public function getUrl( $query = array() ) {
393 $url = $this->request->getRequestURL();
394 # Remove existing query
395 $url = preg_replace( '/\?.*$/', '', $url );
396
397 if ( $query ) {
398 $url .= '?' . wfArrayToCGI( $query );
399 }
400
401 return $url;
402 }
403
404 /**
405 * Get a WebInstallerPage by name.
406 *
407 * @param $pageName String
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 * @param $name String key for the variable
436 * @param $value Mixed
437 */
438 public function setSession( $name, $value ) {
439 $this->session[$name] = $value;
440 }
441
442 /**
443 * Get the next tabindex attribute value.
444 * @return int
445 */
446 public function nextTabIndex() {
447 return $this->tabIndex++;
448 }
449
450 /**
451 * Initializes language-related variables.
452 */
453 public function setupLanguage() {
454 global $wgLang, $wgContLang, $wgLanguageCode;
455
456 if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
457 $wgLanguageCode = $this->getAcceptLanguage();
458 $wgLang = $wgContLang = Language::factory( $wgLanguageCode );
459 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
460 $this->setVar( '_UserLang', $wgLanguageCode );
461 } else {
462 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
463 $wgLang = Language::factory( $this->getVar( '_UserLang' ) );
464 $wgContLang = Language::factory( $wgLanguageCode );
465 }
466 }
467
468 /**
469 * Retrieves MediaWiki language from Accept-Language HTTP header.
470 *
471 * @return string
472 */
473 public function getAcceptLanguage() {
474 global $wgLanguageCode, $wgRequest;
475
476 $mwLanguages = Language::getLanguageNames();
477 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
478
479 foreach ( $headerLanguages as $lang ) {
480 if ( isset( $mwLanguages[$lang] ) ) {
481 return $lang;
482 }
483 }
484
485 return $wgLanguageCode;
486 }
487
488 /**
489 * Called by execute() before page output starts, to show a page list.
490 *
491 * @param $currentPageName String
492 */
493 private function startPageWrapper( $currentPageName ) {
494 $s = "<div class=\"config-page-wrapper\">\n";
495 $s .= "<div class=\"config-page\">\n";
496 $s .= "<div class=\"config-page-list\"><ul>\n";
497 $lastHappy = -1;
498
499 foreach ( $this->pageSequence as $id => $pageName ) {
500 $happy = !empty( $this->happyPages[$id] );
501 $s .= $this->getPageListItem(
502 $pageName,
503 $happy || $lastHappy == $id - 1,
504 $currentPageName
505 );
506
507 if ( $happy ) {
508 $lastHappy = $id;
509 }
510 }
511
512 $s .= "</ul><br/><ul>\n";
513 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
514 $s .= "</ul></div>\n"; // end list pane
515 $s .= Html::element( 'h2', array(),
516 wfMsg( 'config-page-' . strtolower( $currentPageName ) ) );
517
518 $this->output->addHTMLNoFlush( $s );
519 }
520
521 /**
522 * Get a list item for the page list.
523 *
524 * @param $pageName String
525 * @param $enabled Boolean
526 * @param $currentPageName String
527 *
528 * @return string
529 */
530 private function getPageListItem( $pageName, $enabled, $currentPageName ) {
531 $s = "<li class=\"config-page-list-item\">";
532 $name = wfMsg( 'config-page-' . strtolower( $pageName ) );
533
534 if ( $enabled ) {
535 $query = array( 'page' => $pageName );
536
537 if ( !in_array( $pageName, $this->pageSequence ) ) {
538 if ( in_array( $currentPageName, $this->pageSequence ) ) {
539 $query['lastPage'] = $currentPageName;
540 }
541
542 $link = Html::element( 'a',
543 array(
544 'href' => $this->getUrl( $query )
545 ),
546 $name
547 );
548 } else {
549 $link = htmlspecialchars( $name );
550 }
551
552 if ( $pageName == $currentPageName ) {
553 $s .= "<span class=\"config-page-current\">$link</span>";
554 } else {
555 $s .= $link;
556 }
557 } else {
558 $s .= Html::element( 'span',
559 array(
560 'class' => 'config-page-disabled'
561 ),
562 $name
563 );
564 }
565
566 $s .= "</li>\n";
567
568 return $s;
569 }
570
571 /**
572 * Output some stuff after a page is finished.
573 */
574 private function endPageWrapper() {
575 $this->output->addHTMLNoFlush(
576 "<div class=\"visualClear\"></div>\n" .
577 "</div>\n" .
578 "<div class=\"visualClear\"></div>\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, true ) . "\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 return "<div class=\"mw-help-field-container\">\n" .
639 "<span class=\"mw-help-field-hint\">" . wfMsgHtml( 'config-help' ) . "</span>\n" .
640 "<span class=\"mw-help-field-data\">" . $html . "</span>\n" .
641 "</div>\n";
642 }
643
644 /**
645 * Output a help box.
646 * @param $msg String key for wfMsg()
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 textarea to configure a variable
759 *
760 * @param $params Array
761 * Parameters are:
762 * var: The variable to be configured (required)
763 * label: The message name for the label (required)
764 * attribs: Additional attributes for the input element (optional)
765 * controlName: The name for the input element (optional)
766 * value: The current value of the variable (optional)
767 * help: The html for the help text (optional)
768 */
769 public function getTextArea( $params ) {
770 if ( !isset( $params['controlName'] ) ) {
771 $params['controlName'] = 'config_' . $params['var'];
772 }
773
774 if ( !isset( $params['value'] ) ) {
775 $params['value'] = $this->getVar( $params['var'] );
776 }
777
778 if ( !isset( $params['attribs'] ) ) {
779 $params['attribs'] = array();
780 }
781 if ( !isset( $params['help'] ) ) {
782 $params['help'] = "";
783 }
784 return
785 $this->label(
786 $params['label'],
787 $params['controlName'],
788 Xml::textarea(
789 $params['controlName'],
790 $params['value'],
791 30,
792 5,
793 $params['attribs'] + array(
794 'id' => $params['controlName'],
795 'class' => 'config-input-text',
796 'tabindex' => $this->nextTabIndex()
797 )
798 ),
799 $params['help']
800 );
801 }
802
803 /**
804 * Get a labelled password box to configure a variable.
805 *
806 * Implements password hiding
807 * @param $params Array
808 * Parameters are:
809 * var: The variable to be configured (required)
810 * label: The message name for the label (required)
811 * attribs: Additional attributes for the input element (optional)
812 * controlName: The name for the input element (optional)
813 * value: The current value of the variable (optional)
814 * help: The html for the help text (optional)
815 */
816 public function getPasswordBox( $params ) {
817 if ( !isset( $params['value'] ) ) {
818 $params['value'] = $this->getVar( $params['var'] );
819 }
820
821 if ( !isset( $params['attribs'] ) ) {
822 $params['attribs'] = array();
823 }
824
825 $params['value'] = $this->getFakePassword( $params['value'] );
826 $params['attribs']['type'] = 'password';
827
828 return $this->getTextBox( $params );
829 }
830
831 /**
832 * Get a labelled checkbox to configure a boolean variable.
833 *
834 * @param $params Array
835 * Parameters are:
836 * var: The variable to be configured (required)
837 * label: The message name for the label (required)
838 * attribs: Additional attributes for the input element (optional)
839 * controlName: The name for the input element (optional)
840 * value: The current value of the variable (optional)
841 * help: The html for the help text (optional)
842 */
843 public function getCheckBox( $params ) {
844 if ( !isset( $params['controlName'] ) ) {
845 $params['controlName'] = 'config_' . $params['var'];
846 }
847
848 if ( !isset( $params['value'] ) ) {
849 $params['value'] = $this->getVar( $params['var'] );
850 }
851
852 if ( !isset( $params['attribs'] ) ) {
853 $params['attribs'] = array();
854 }
855 if ( !isset( $params['help'] ) ) {
856 $params['help'] = "";
857 }
858 if( isset( $params['rawtext'] ) ) {
859 $labelText = $params['rawtext'];
860 } else {
861 $labelText = $this->parse( wfMsg( $params['label'] ) );
862 }
863
864 return
865 "<div class=\"config-input-check\">\n" .
866 $params['help'] .
867 "<label>\n" .
868 Xml::check(
869 $params['controlName'],
870 $params['value'],
871 $params['attribs'] + array(
872 'id' => $params['controlName'],
873 'tabindex' => $this->nextTabIndex(),
874 )
875 ) .
876 $labelText . "\n" .
877 "</label>\n" .
878 "</div>\n";
879 }
880
881 /**
882 * Get a set of labelled radio buttons.
883 *
884 * @param $params Array
885 * Parameters are:
886 * var: The variable to be configured (required)
887 * label: The message name for the label (required)
888 * itemLabelPrefix: The message name prefix for the item labels (required)
889 * values: List of allowed values (required)
890 * itemAttribs Array of attribute arrays, outer key is the value name (optional)
891 * commonAttribs Attribute array applied to all items
892 * controlName: The name for the input element (optional)
893 * value: The current value of the variable (optional)
894 * help: The html for the help text (optional)
895 */
896 public function getRadioSet( $params ) {
897 if ( !isset( $params['controlName'] ) ) {
898 $params['controlName'] = 'config_' . $params['var'];
899 }
900
901 if ( !isset( $params['value'] ) ) {
902 $params['value'] = $this->getVar( $params['var'] );
903 }
904
905 if ( !isset( $params['label'] ) ) {
906 $label = '';
907 } else {
908 $label = $params['label'];
909 }
910 if ( !isset( $params['help'] ) ) {
911 $params['help'] = "";
912 }
913 $s = "<ul>\n";
914 foreach ( $params['values'] as $value ) {
915 $itemAttribs = array();
916
917 if ( isset( $params['commonAttribs'] ) ) {
918 $itemAttribs = $params['commonAttribs'];
919 }
920
921 if ( isset( $params['itemAttribs'][$value] ) ) {
922 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
923 }
924
925 $checked = $value == $params['value'];
926 $id = $params['controlName'] . '_' . $value;
927 $itemAttribs['id'] = $id;
928 $itemAttribs['tabindex'] = $this->nextTabIndex();
929
930 $s .=
931 '<li>' .
932 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
933 '&#160;' .
934 Xml::tags( 'label', array( 'for' => $id ), $this->parse(
935 wfMsgNoTrans( $params['itemLabelPrefix'] . strtolower( $value ) )
936 ) ) .
937 "</li>\n";
938 }
939
940 $s .= "</ul>\n";
941
942 return $this->label( $label, $params['controlName'], $s, $params['help'] );
943 }
944
945 /**
946 * Output an error or warning box using a Status object.
947 */
948 public function showStatusBox( $status ) {
949 if( !$status->isGood() ) {
950 $text = $status->getWikiText();
951
952 if( $status->isOk() ) {
953 $box = $this->getWarningBox( $text );
954 } else {
955 $box = $this->getErrorBox( $text );
956 }
957
958 $this->output->addHTML( $box );
959 }
960 }
961
962 /**
963 * Convenience function to set variables based on form data.
964 * Assumes that variables containing "password" in the name are (potentially
965 * fake) passwords.
966 *
967 * @param $varNames Array
968 * @param $prefix String: the prefix added to variables to obtain form names
969 */
970 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
971 $newValues = array();
972
973 foreach ( $varNames as $name ) {
974 $value = trim( $this->request->getVal( $prefix . $name ) );
975 $newValues[$name] = $value;
976
977 if ( $value === null ) {
978 // Checkbox?
979 $this->setVar( $name, false );
980 } else {
981 if ( stripos( $name, 'password' ) !== false ) {
982 $this->setPassword( $name, $value );
983 } else {
984 $this->setVar( $name, $value );
985 }
986 }
987 }
988
989 return $newValues;
990 }
991
992 /**
993 * Helper for Installer::docLink()
994 */
995 protected function getDocUrl( $page ) {
996 $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
997
998 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
999 $url .= '&lastPage=' . urlencode( $this->currentPageName );
1000 }
1001
1002 return $url;
1003 }
1004
1005 /**
1006 * Extension tag hook for a documentation link.
1007 */
1008 public function docLink( $linkText, $attribs, $parser ) {
1009 $url = $this->getDocUrl( $attribs['href'] );
1010 return '<a href="' . htmlspecialchars( $url ) . '">' .
1011 htmlspecialchars( $linkText ) .
1012 '</a>';
1013 }
1014
1015 /**
1016 * Helper for "Download LocalSettings" link on WebInstall_Complete
1017 * @return String Html for download link
1018 */
1019 public function downloadLinkHook( $text, $attribs, $parser ) {
1020 $img = Html::element( 'img', array(
1021 'src' => '../skins/common/images/download-32.png',
1022 'width' => '32',
1023 'height' => '32',
1024 ) );
1025 $anchor = Html::rawElement( 'a',
1026 array( 'href' => $this->getURL( array( 'localsettings' => 1 ) ) ),
1027 $img . ' ' . wfMsgHtml( 'config-download-localsettings' ) );
1028 return Html::rawElement( 'div', array( 'class' => 'config-download-link' ), $anchor );
1029 }
1030 }