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