Localisation updates for core and extension messages from translatewiki.net (2011...
[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 $pageClass = 'WebInstaller_' . $pageName;
412
413 return new $pageClass( $this );
414 }
415
416 /**
417 * Get a session variable.
418 *
419 * @param $name String
420 * @param $default
421 */
422 public function getSession( $name, $default = null ) {
423 if ( !isset( $this->session[$name] ) ) {
424 return $default;
425 } else {
426 return $this->session[$name];
427 }
428 }
429
430 /**
431 * Set a session variable.
432 * @param $name String key for the variable
433 * @param $value Mixed
434 */
435 public function setSession( $name, $value ) {
436 $this->session[$name] = $value;
437 }
438
439 /**
440 * Get the next tabindex attribute value.
441 * @return int
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 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
511 $s .= "</ul></div>\n"; // end list pane
512 $s .= Html::element( 'h2', array(),
513 wfMsg( 'config-page-' . strtolower( $currentPageName ) ) );
514
515 $this->output->addHTMLNoFlush( $s );
516 }
517
518 /**
519 * Get a list item for the page list.
520 *
521 * @param $pageName String
522 * @param $enabled Boolean
523 * @param $currentPageName String
524 *
525 * @return string
526 */
527 private function getPageListItem( $pageName, $enabled, $currentPageName ) {
528 $s = "<li class=\"config-page-list-item\">";
529 $name = wfMsg( 'config-page-' . strtolower( $pageName ) );
530
531 if ( $enabled ) {
532 $query = array( 'page' => $pageName );
533
534 if ( !in_array( $pageName, $this->pageSequence ) ) {
535 if ( in_array( $currentPageName, $this->pageSequence ) ) {
536 $query['lastPage'] = $currentPageName;
537 }
538
539 $link = Html::element( 'a',
540 array(
541 'href' => $this->getUrl( $query )
542 ),
543 $name
544 );
545 } else {
546 $link = htmlspecialchars( $name );
547 }
548
549 if ( $pageName == $currentPageName ) {
550 $s .= "<span class=\"config-page-current\">$link</span>";
551 } else {
552 $s .= $link;
553 }
554 } else {
555 $s .= Html::element( 'span',
556 array(
557 'class' => 'config-page-disabled'
558 ),
559 $name
560 );
561 }
562
563 $s .= "</li>\n";
564
565 return $s;
566 }
567
568 /**
569 * Output some stuff after a page is finished.
570 */
571 private function endPageWrapper() {
572 $this->output->addHTMLNoFlush(
573 "<div class=\"visualClear\"></div>\n" .
574 "</div>\n" .
575 "<div class=\"visualClear\"></div>\n" .
576 "</div>" );
577 }
578
579 /**
580 * Get HTML for an error box with an icon.
581 *
582 * @param $text String: wikitext, get this with wfMsgNoTrans()
583 */
584 public function getErrorBox( $text ) {
585 return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
586 }
587
588 /**
589 * Get HTML for a warning box with an icon.
590 *
591 * @param $text String: wikitext, get this with wfMsgNoTrans()
592 */
593 public function getWarningBox( $text ) {
594 return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
595 }
596
597 /**
598 * Get HTML for an info box with an icon.
599 *
600 * @param $text String: wikitext, get this with wfMsgNoTrans()
601 * @param $icon String: icon name, file in skins/common/images
602 * @param $class String: additional class name to add to the wrapper div
603 */
604 public function getInfoBox( $text, $icon = 'info-32.png', $class = false ) {
605 $s =
606 "<div class=\"config-info $class\">\n" .
607 "<div class=\"config-info-left\">\n" .
608 Html::element( 'img',
609 array(
610 'src' => '../skins/common/images/' . $icon,
611 'alt' => wfMsg( 'config-information' ),
612 )
613 ) . "\n" .
614 "</div>\n" .
615 "<div class=\"config-info-right\">\n" .
616 $this->parse( $text, true ) . "\n" .
617 "</div>\n" .
618 "<div style=\"clear: left;\"></div>\n" .
619 "</div>\n";
620 return $s;
621 }
622
623 /**
624 * Get small text indented help for a preceding form field.
625 * Parameters like wfMsg().
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 public function label( $msg, $forId, $contents, $helpData = "" ) {
683 if ( strval( $msg ) == '' ) {
684 $labelText = '&#160;';
685 } else {
686 $labelText = wfMsgHtml( $msg );
687 }
688
689 $attributes = array( 'class' => 'config-label' );
690
691 if ( $forId ) {
692 $attributes['for'] = $forId;
693 }
694
695 return
696 "<div class=\"config-block\">\n" .
697 " <div class=\"config-block-label\">\n" .
698 Xml::tags( 'label',
699 $attributes,
700 $labelText ) . "\n" .
701 $helpData .
702 " </div>\n" .
703 " <div class=\"config-block-elements\">\n" .
704 $contents .
705 " </div>\n" .
706 "</div>\n";
707 }
708
709 /**
710 * Get a labelled text box to configure a variable.
711 *
712 * @param $params Array
713 * Parameters are:
714 * var: The variable to be configured (required)
715 * label: The message name for the label (required)
716 * attribs: Additional attributes for the input element (optional)
717 * controlName: The name for the input element (optional)
718 * value: The current value of the variable (optional)
719 * help: The html for the help text (optional)
720 */
721 public function getTextBox( $params ) {
722 if ( !isset( $params['controlName'] ) ) {
723 $params['controlName'] = 'config_' . $params['var'];
724 }
725
726 if ( !isset( $params['value'] ) ) {
727 $params['value'] = $this->getVar( $params['var'] );
728 }
729
730 if ( !isset( $params['attribs'] ) ) {
731 $params['attribs'] = array();
732 }
733 if ( !isset( $params['help'] ) ) {
734 $params['help'] = "";
735 }
736 return
737 $this->label(
738 $params['label'],
739 $params['controlName'],
740 Xml::input(
741 $params['controlName'],
742 30, // intended to be overridden by CSS
743 $params['value'],
744 $params['attribs'] + array(
745 'id' => $params['controlName'],
746 'class' => 'config-input-text',
747 'tabindex' => $this->nextTabIndex()
748 )
749 ),
750 $params['help']
751 );
752 }
753
754 /**
755 * Get a labelled textarea to configure a variable
756 *
757 * @param $params Array
758 * Parameters are:
759 * var: The variable to be configured (required)
760 * label: The message name for the label (required)
761 * attribs: Additional attributes for the input element (optional)
762 * controlName: The name for the input element (optional)
763 * value: The current value of the variable (optional)
764 * help: The html for the help text (optional)
765 */
766 public function getTextArea( $params ) {
767 if ( !isset( $params['controlName'] ) ) {
768 $params['controlName'] = 'config_' . $params['var'];
769 }
770
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 if ( !isset( $params['help'] ) ) {
779 $params['help'] = "";
780 }
781 return
782 $this->label(
783 $params['label'],
784 $params['controlName'],
785 Xml::textarea(
786 $params['controlName'],
787 $params['value'],
788 30,
789 5,
790 $params['attribs'] + array(
791 'id' => $params['controlName'],
792 'class' => 'config-input-text',
793 'tabindex' => $this->nextTabIndex()
794 )
795 ),
796 $params['help']
797 );
798 }
799
800 /**
801 * Get a labelled password box to configure a variable.
802 *
803 * Implements password hiding
804 * @param $params Array
805 * Parameters are:
806 * var: The variable to be configured (required)
807 * label: The message name for the label (required)
808 * attribs: Additional attributes for the input element (optional)
809 * controlName: The name for the input element (optional)
810 * value: The current value of the variable (optional)
811 * help: The html for the help text (optional)
812 */
813 public function getPasswordBox( $params ) {
814 if ( !isset( $params['value'] ) ) {
815 $params['value'] = $this->getVar( $params['var'] );
816 }
817
818 if ( !isset( $params['attribs'] ) ) {
819 $params['attribs'] = array();
820 }
821
822 $params['value'] = $this->getFakePassword( $params['value'] );
823 $params['attribs']['type'] = 'password';
824
825 return $this->getTextBox( $params );
826 }
827
828 /**
829 * Get a labelled checkbox to configure a boolean variable.
830 *
831 * @param $params Array
832 * Parameters are:
833 * var: The variable to be configured (required)
834 * label: The message name for the label (required)
835 * attribs: Additional attributes for the input element (optional)
836 * controlName: The name for the input element (optional)
837 * value: The current value of the variable (optional)
838 * help: The html for the help text (optional)
839 */
840 public function getCheckBox( $params ) {
841 if ( !isset( $params['controlName'] ) ) {
842 $params['controlName'] = 'config_' . $params['var'];
843 }
844
845 if ( !isset( $params['value'] ) ) {
846 $params['value'] = $this->getVar( $params['var'] );
847 }
848
849 if ( !isset( $params['attribs'] ) ) {
850 $params['attribs'] = array();
851 }
852 if ( !isset( $params['help'] ) ) {
853 $params['help'] = "";
854 }
855 if( isset( $params['rawtext'] ) ) {
856 $labelText = $params['rawtext'];
857 } else {
858 $labelText = $this->parse( wfMsg( $params['label'] ) );
859 }
860
861 return
862 "<div class=\"config-input-check\">\n" .
863 $params['help'] .
864 "<label>\n" .
865 Xml::check(
866 $params['controlName'],
867 $params['value'],
868 $params['attribs'] + array(
869 'id' => $params['controlName'],
870 'tabindex' => $this->nextTabIndex(),
871 )
872 ) .
873 $labelText . "\n" .
874 "</label>\n" .
875 "</div>\n";
876 }
877
878 /**
879 * Get a set of labelled radio buttons.
880 *
881 * @param $params Array
882 * Parameters are:
883 * var: The variable to be configured (required)
884 * label: The message name for the label (required)
885 * itemLabelPrefix: The message name prefix for the item labels (required)
886 * values: List of allowed values (required)
887 * itemAttribs Array of attribute arrays, outer key is the value name (optional)
888 * commonAttribs Attribute array applied to all items
889 * controlName: The name for the input element (optional)
890 * value: The current value of the variable (optional)
891 * help: The html for the help text (optional)
892 */
893 public function getRadioSet( $params ) {
894 if ( !isset( $params['controlName'] ) ) {
895 $params['controlName'] = 'config_' . $params['var'];
896 }
897
898 if ( !isset( $params['value'] ) ) {
899 $params['value'] = $this->getVar( $params['var'] );
900 }
901
902 if ( !isset( $params['label'] ) ) {
903 $label = '';
904 } else {
905 $label = $params['label'];
906 }
907 if ( !isset( $params['help'] ) ) {
908 $params['help'] = "";
909 }
910 $s = "<ul>\n";
911 foreach ( $params['values'] as $value ) {
912 $itemAttribs = array();
913
914 if ( isset( $params['commonAttribs'] ) ) {
915 $itemAttribs = $params['commonAttribs'];
916 }
917
918 if ( isset( $params['itemAttribs'][$value] ) ) {
919 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
920 }
921
922 $checked = $value == $params['value'];
923 $id = $params['controlName'] . '_' . $value;
924 $itemAttribs['id'] = $id;
925 $itemAttribs['tabindex'] = $this->nextTabIndex();
926
927 $s .=
928 '<li>' .
929 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
930 '&#160;' .
931 Xml::tags( 'label', array( 'for' => $id ), $this->parse(
932 wfMsgNoTrans( $params['itemLabelPrefix'] . strtolower( $value ) )
933 ) ) .
934 "</li>\n";
935 }
936
937 $s .= "</ul>\n";
938
939 return $this->label( $label, $params['controlName'], $s, $params['help'] );
940 }
941
942 /**
943 * Output an error or warning box using a Status object.
944 */
945 public function showStatusBox( $status ) {
946 if( !$status->isGood() ) {
947 $text = $status->getWikiText();
948
949 if( $status->isOk() ) {
950 $box = $this->getWarningBox( $text );
951 } else {
952 $box = $this->getErrorBox( $text );
953 }
954
955 $this->output->addHTML( $box );
956 }
957 }
958
959 /**
960 * Convenience function to set variables based on form data.
961 * Assumes that variables containing "password" in the name are (potentially
962 * fake) passwords.
963 *
964 * @param $varNames Array
965 * @param $prefix String: the prefix added to variables to obtain form names
966 */
967 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
968 $newValues = array();
969
970 foreach ( $varNames as $name ) {
971 $value = trim( $this->request->getVal( $prefix . $name ) );
972 $newValues[$name] = $value;
973
974 if ( $value === null ) {
975 // Checkbox?
976 $this->setVar( $name, false );
977 } else {
978 if ( stripos( $name, 'password' ) !== false ) {
979 $this->setPassword( $name, $value );
980 } else {
981 $this->setVar( $name, $value );
982 }
983 }
984 }
985
986 return $newValues;
987 }
988
989 /**
990 * Helper for Installer::docLink()
991 */
992 protected function getDocUrl( $page ) {
993 $url = "{$_SERVER['PHP_SELF']}?page=" . urlencode( $page );
994
995 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
996 $url .= '&lastPage=' . urlencode( $this->currentPageName );
997 }
998
999 return $url;
1000 }
1001
1002 /**
1003 * Extension tag hook for a documentation link.
1004 */
1005 public function docLink( $linkText, $attribs, $parser ) {
1006 $url = $this->getDocUrl( $attribs['href'] );
1007 return '<a href="' . htmlspecialchars( $url ) . '">' .
1008 htmlspecialchars( $linkText ) .
1009 '</a>';
1010 }
1011
1012 /**
1013 * Helper for "Download LocalSettings" link on WebInstall_Complete
1014 * @return String Html for download link
1015 */
1016 public function downloadLinkHook( $text, $attribs, $parser ) {
1017 $img = Html::element( 'img', array(
1018 'src' => '../skins/common/images/download-32.png',
1019 'width' => '32',
1020 'height' => '32',
1021 ) );
1022 $anchor = Html::rawElement( 'a',
1023 array( 'href' => $this->getURL( array( 'localsettings' => 1 ) ) ),
1024 $img . ' ' . wfMsgHtml( 'config-download-localsettings' ) );
1025 return Html::rawElement( 'div', array( 'class' => 'config-download-link' ), $anchor );
1026 }
1027 }