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