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