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