MediaWiki REL1_39
WebInstaller.php
Go to the documentation of this file.
1<?php
26
33class WebInstaller extends Installer {
34
38 public $output;
39
45 public $request;
46
52 protected $session;
53
59 protected $phpErrors;
60
71 public $pageSequence = [
72 'Language',
73 'ExistingWiki',
74 'Welcome',
75 'DBConnect',
76 'Upgrade',
77 'DBSettings',
78 'Name',
79 'Options',
80 'Install',
81 'Complete',
82 ];
83
89 protected $otherPages = [
90 'Restart',
91 'ReleaseNotes',
92 'Copying',
93 'UpgradeDoc', // Can't use Upgrade due to Upgrade step
94 ];
95
102 protected $happyPages;
103
111 protected $skippedPages;
112
118 public $showSessionWarning = false;
119
125 protected $tabIndex = 1;
126
132 protected $helpBoxId = 1;
133
140
144 public function __construct( WebRequest $request ) {
145 parent::__construct();
146 $this->output = new WebInstallerOutput( $this );
147 $this->request = $request;
148 }
149
157 public function execute( array $session ) {
158 $this->session = $session;
159
160 if ( isset( $session['settings'] ) ) {
161 $this->settings = $session['settings'] + $this->settings;
162 // T187586 MediaWikiServices works with globals
163 foreach ( $this->settings as $key => $val ) {
164 $GLOBALS[$key] = $val;
165 }
166 }
167
168 $this->setupLanguage();
169
170 if ( ( $this->getVar( '_InstallDone' ) || $this->getVar( '_UpgradeDone' ) )
171 && $this->request->getVal( 'localsettings' )
172 ) {
173 $this->outputLS();
174 return $this->session;
175 }
176
177 $isCSS = $this->request->getVal( 'css' );
178 if ( $isCSS ) {
179 $this->outputCss();
180 return $this->session;
181 }
182
183 $this->happyPages = $session['happyPages'] ?? [];
184
185 $this->skippedPages = $session['skippedPages'] ?? [];
186
187 $lowestUnhappy = $this->getLowestUnhappy();
188
189 # Special case for Creative Commons partner chooser box.
190 if ( $this->request->getVal( 'SubmitCC' ) ) {
192 $page = $this->getPageByName( 'Options' );
193 '@phan-var WebInstallerOptions $page';
194 $this->output->useShortHeader();
195 $this->output->allowFrames();
196 $page->submitCC();
197
198 return $this->finish();
199 }
200
201 if ( $this->request->getVal( 'ShowCC' ) ) {
203 $page = $this->getPageByName( 'Options' );
204 '@phan-var WebInstallerOptions $page';
205 $this->output->useShortHeader();
206 $this->output->allowFrames();
207 $this->output->addHTML( $page->getCCDoneBox() );
208
209 return $this->finish();
210 }
211
212 # Get the page name.
213 $pageName = $this->request->getVal( 'page', '' );
214
215 if ( in_array( $pageName, $this->otherPages ) ) {
216 # Out of sequence
217 $pageId = false;
218 $page = $this->getPageByName( $pageName );
219 } else {
220 # Main sequence
221 if ( !$pageName || !in_array( $pageName, $this->pageSequence ) ) {
222 $pageId = $lowestUnhappy;
223 } else {
224 $pageId = array_search( $pageName, $this->pageSequence );
225 }
226
227 # If necessary, move back to the lowest-numbered unhappy page
228 if ( $pageId > $lowestUnhappy ) {
229 $pageId = $lowestUnhappy;
230 if ( $lowestUnhappy == 0 ) {
231 # Knocked back to start, possible loss of session data.
232 $this->showSessionWarning = true;
233 }
234 }
235
236 $pageName = $this->pageSequence[$pageId];
237 $page = $this->getPageByName( $pageName );
238 }
239
240 # If a back button was submitted, go back without submitting the form data.
241 if ( $this->request->wasPosted() && $this->request->getBool( 'submit-back' ) ) {
242 if ( $this->request->getVal( 'lastPage' ) ) {
243 $nextPage = $this->request->getVal( 'lastPage' );
244 } elseif ( $pageId !== false ) {
245 # Main sequence page
246 # Skip the skipped pages
247 $nextPageId = $pageId;
248
249 do {
250 $nextPageId--;
251 $nextPage = $this->pageSequence[$nextPageId];
252 } while ( isset( $this->skippedPages[$nextPage] ) );
253 } else {
254 $nextPage = $this->pageSequence[$lowestUnhappy];
255 }
256
257 $this->output->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
258
259 return $this->finish();
260 }
261
262 # Execute the page.
263 $this->currentPageName = $page->getName();
264 $this->startPageWrapper( $pageName );
265
266 if ( $page->isSlow() ) {
267 $this->disableTimeLimit();
268 }
269
270 $result = $page->execute();
271
272 $this->endPageWrapper();
273
274 if ( $result == 'skip' ) {
275 # Page skipped without explicit submission.
276 # Skip it when we click "back" so that we don't just go forward again.
277 $this->skippedPages[$pageName] = true;
278 $result = 'continue';
279 } else {
280 unset( $this->skippedPages[$pageName] );
281 }
282
283 # If it was posted, the page can request a continue to the next page.
284 if ( $result === 'continue' && !$this->output->headerDone() ) {
285 if ( $pageId !== false ) {
286 $this->happyPages[$pageId] = true;
287 }
288
289 $lowestUnhappy = $this->getLowestUnhappy();
290
291 if ( $this->request->getVal( 'lastPage' ) ) {
292 $nextPage = $this->request->getVal( 'lastPage' );
293 } elseif ( $pageId !== false ) {
294 $nextPage = $this->pageSequence[$pageId + 1];
295 } else {
296 $nextPage = $this->pageSequence[$lowestUnhappy];
297 }
298
299 if ( array_search( $nextPage, $this->pageSequence ) > $lowestUnhappy ) {
300 $nextPage = $this->pageSequence[$lowestUnhappy];
301 }
302
303 $this->output->redirect( $this->getUrl( [ 'page' => $nextPage ] ) );
304 }
305
306 return $this->finish();
307 }
308
313 public function getLowestUnhappy() {
314 if ( count( $this->happyPages ) == 0 ) {
315 return 0;
316 } else {
317 return max( array_keys( $this->happyPages ) ) + 1;
318 }
319 }
320
327 public function startSession() {
328 if ( wfIniGetBool( 'session.auto_start' ) || session_id() ) {
329 // Done already
330 return true;
331 }
332
333 // Use secure cookies if we are on HTTPS
334 $options = [];
335 if ( $this->request->getProtocol() === 'https' ) {
336 $options['cookie_secure'] = '1';
337 }
338
339 $this->phpErrors = [];
340 set_error_handler( [ $this, 'errorHandler' ] );
341 try {
342 session_name( 'mw_installer_session' );
343 session_start( $options );
344 } catch ( Exception $e ) {
345 restore_error_handler();
346 throw $e;
347 }
348 restore_error_handler();
349
350 if ( $this->phpErrors ) {
351 return false;
352 }
353
354 return true;
355 }
356
365 public function getFingerprint() {
366 // Get the base URL of the installation
367 $url = $this->request->getFullRequestURL();
368 if ( preg_match( '!^(.*\?)!', $url, $m ) ) {
369 // Trim query string
370 $url = $m[1];
371 }
372 if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
373 // This... seems to try to get the base path from
374 // the /mw-config/index.php. Kinda scary though?
375 $url = $m[1];
376 }
377
378 return md5( serialize( [
379 'local path' => dirname( __DIR__ ),
380 'url' => $url,
381 'version' => MW_VERSION
382 ] ) );
383 }
384
391 public function showError( $msg, ...$params ) {
392 if ( !( $msg instanceof Message ) ) {
393 $msg = wfMessage(
394 $msg,
395 array_map( 'htmlspecialchars', $params )
396 );
397 }
398 $text = $msg->useDatabase( false )->parse();
399 $box = Html::errorBox( $text, '', 'config-error-box' );
400 $this->output->addHTML( $box );
401 }
402
409 public function errorHandler( $errno, $errstr ) {
410 $this->phpErrors[] = $errstr;
411 }
412
418 public function finish() {
419 $this->output->output();
420
421 $this->session['happyPages'] = $this->happyPages;
422 $this->session['skippedPages'] = $this->skippedPages;
423 $this->session['settings'] = $this->settings;
424
425 return $this->session;
426 }
427
431 public function reset() {
432 $this->session = [];
433 $this->happyPages = [];
434 $this->settings = [];
435 }
436
444 public function getUrl( $query = [] ) {
445 $url = $this->request->getRequestURL();
446 # Remove existing query
447 $url = preg_replace( '/\?.*$/', '', $url );
448
449 if ( $query ) {
450 $url .= '?' . wfArrayToCgi( $query );
451 }
452
453 return $url;
454 }
455
462 public function getPageByName( $pageName ) {
463 $pageClass = 'WebInstaller' . $pageName;
464
465 return new $pageClass( $this );
466 }
467
476 public function getSession( $name, $default = null ) {
477 return $this->session[$name] ?? $default;
478 }
479
486 public function setSession( $name, $value ) {
487 $this->session[$name] = $value;
488 }
489
495 public function nextTabIndex() {
496 return $this->tabIndex++;
497 }
498
502 public function setupLanguage() {
503 global $wgLang, $wgLanguageCode;
504
505 if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
507 $wgLang = MediaWikiServices::getInstance()->getLanguageFactory()
508 ->getLanguage( $wgLanguageCode );
509 RequestContext::getMain()->setLanguage( $wgLang );
510 $this->setVar( 'wgLanguageCode', $wgLanguageCode );
511 $this->setVar( '_UserLang', $wgLanguageCode );
512 } else {
513 $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
514 }
515 }
516
523 public function getAcceptLanguage() {
525
526 $mwLanguages = MediaWikiServices::getInstance()
527 ->getLanguageNameUtils()
528 ->getLanguageNames( LanguageNameUtils::AUTONYMS, LanguageNameUtils::SUPPORTED );
529 $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
530
531 foreach ( $headerLanguages as $lang ) {
532 if ( isset( $mwLanguages[$lang] ) ) {
533 return $lang;
534 }
535 }
536
537 return $wgLanguageCode;
538 }
539
545 private function startPageWrapper( $currentPageName ) {
546 $s = "<div class=\"config-page-wrapper\">\n";
547 $s .= "<div class=\"config-page\">\n";
548 $s .= "<div class=\"config-page-list\"><ul>\n";
549 $lastHappy = -1;
550
551 foreach ( $this->pageSequence as $id => $pageName ) {
552 $happy = !empty( $this->happyPages[$id] );
553 $s .= $this->getPageListItem(
554 $pageName,
555 $happy || $lastHappy == $id - 1,
557 );
558
559 if ( $happy ) {
560 $lastHappy = $id;
561 }
562 }
563
564 $s .= "</ul><br/><ul>\n";
565 $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
566 // End list pane
567 $s .= "</ul></div>\n";
568
569 // Messages:
570 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
571 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
572 // config-page-complete, config-page-restart, config-page-releasenotes,
573 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
574 $s .= Html::element( 'h2', [],
575 wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
576
577 $this->output->addHTMLNoFlush( $s );
578 }
579
589 private function getPageListItem( $pageName, $enabled, $currentPageName ) {
590 $s = "<li class=\"config-page-list-item\">";
591
592 // Messages:
593 // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
594 // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
595 // config-page-complete, config-page-restart, config-page-releasenotes,
596 // config-page-copying, config-page-upgradedoc, config-page-existingwiki
597 $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
598
599 if ( $enabled ) {
600 $query = [ 'page' => $pageName ];
601
602 if ( !in_array( $pageName, $this->pageSequence ) ) {
603 if ( in_array( $currentPageName, $this->pageSequence ) ) {
604 $query['lastPage'] = $currentPageName;
605 }
606
607 $link = Html::element( 'a',
608 [
609 'href' => $this->getUrl( $query )
610 ],
611 $name
612 );
613 } else {
614 $link = htmlspecialchars( $name );
615 }
616
617 if ( $pageName == $currentPageName ) {
618 $s .= "<span class=\"config-page-current\">$link</span>";
619 } else {
620 $s .= $link;
621 }
622 } else {
623 $s .= Html::element( 'span',
624 [
625 'class' => 'config-page-disabled'
626 ],
627 $name
628 );
629 }
630
631 $s .= "</li>\n";
632
633 return $s;
634 }
635
639 private function endPageWrapper() {
640 $this->output->addHTMLNoFlush(
641 "<div class=\"visualClear\"></div>\n" .
642 "</div>\n" .
643 "<div class=\"visualClear\"></div>\n" .
644 "</div>" );
645 }
646
655 public function getInfoBox( $text, $icon = false, $class = '' ) {
656 $html = ( $text instanceof HtmlArmor ) ?
657 HtmlArmor::getHtml( $text ) :
658 $this->parse( $text, true );
659 $icon = ( !$icon ) ?
660 'images/info-32.png' :
661 'images/' . $icon;
662 $alt = wfMessage( 'config-information' )->text();
663
664 return self::infoBox( $html, $icon, $alt, $class );
665 }
666
676 public function getHelpBox( $msg, ...$args ) {
677 $args = array_map( 'htmlspecialchars', $args );
678 $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
679 $html = $this->parse( $text, true );
680 $id = 'helpBox-' . $this->helpBoxId++;
681
682 return "<div class=\"config-help-field-container\">\n" .
683 "<input type=\"checkbox\" class=\"config-help-field-checkbox\" id=\"$id\" />" .
684 "<label class=\"config-help-field-hint\" for=\"$id\" title=\"" .
685 wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
686 wfMessage( 'config-help' )->escaped() . "</label>\n" .
687 "<div class=\"config-help-field-data\">" . $html . "</div>\n" .
688 "</div>\n";
689 }
690
696 public function showHelpBox( $msg, ...$params ) {
697 $html = $this->getHelpBox( $msg, ...$params );
698 $this->output->addHTML( $html );
699 }
700
708 public function showMessage( $msg, ...$params ) {
709 $html = '<div class="config-message">' .
710 $this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) .
711 "</div>\n";
712 $this->output->addHTML( $html );
713 }
714
718 public function showStatusMessage( Status $status ) {
719 $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
720 foreach ( $errors as $error ) {
721 $this->showMessage( ...$error );
722 }
723 }
724
736 public function label( $msg, $forId, $contents, $helpData = "" ) {
737 if ( strval( $msg ) == '' ) {
738 $labelText = "\u{00A0}";
739 } else {
740 $labelText = wfMessage( $msg )->escaped();
741 }
742
743 $attributes = [ 'class' => 'config-label' ];
744
745 if ( $forId ) {
746 $attributes['for'] = $forId;
747 }
748
749 return "<div class=\"config-block\">\n" .
750 " <div class=\"config-block-label\">\n" .
751 Xml::tags( 'label',
752 $attributes,
753 $labelText
754 ) . "\n" .
755 $helpData .
756 " </div>\n" .
757 " <div class=\"config-block-elements\">\n" .
758 $contents .
759 " </div>\n" .
760 "</div>\n";
761 }
762
778 public function getTextBox( $params ) {
779 if ( !isset( $params['controlName'] ) ) {
780 $params['controlName'] = 'config_' . $params['var'];
781 }
782
783 if ( !isset( $params['value'] ) ) {
784 $params['value'] = $this->getVar( $params['var'] );
785 }
786
787 if ( !isset( $params['attribs'] ) ) {
788 $params['attribs'] = [];
789 }
790 if ( !isset( $params['help'] ) ) {
791 $params['help'] = "";
792 }
793
794 return $this->label(
795 $params['label'],
796 $params['controlName'],
797 Xml::input(
798 $params['controlName'],
799 30, // intended to be overridden by CSS
800 $params['value'],
801 $params['attribs'] + [
802 'id' => $params['controlName'],
803 'class' => 'config-input-text',
804 'tabindex' => $this->nextTabIndex()
805 ]
806 ),
807 $params['help']
808 );
809 }
810
825 public function getTextArea( $params ) {
826 if ( !isset( $params['controlName'] ) ) {
827 $params['controlName'] = 'config_' . $params['var'];
828 }
829
830 if ( !isset( $params['value'] ) ) {
831 $params['value'] = $this->getVar( $params['var'] );
832 }
833
834 if ( !isset( $params['attribs'] ) ) {
835 $params['attribs'] = [];
836 }
837 if ( !isset( $params['help'] ) ) {
838 $params['help'] = "";
839 }
840
841 return $this->label(
842 $params['label'],
843 $params['controlName'],
844 Xml::textarea(
845 $params['controlName'],
846 $params['value'],
847 30,
848 5,
849 $params['attribs'] + [
850 'id' => $params['controlName'],
851 'class' => 'config-input-text',
852 'tabindex' => $this->nextTabIndex()
853 ]
854 ),
855 $params['help']
856 );
857 }
858
875 public function getPasswordBox( $params ) {
876 if ( !isset( $params['value'] ) ) {
877 $params['value'] = $this->getVar( $params['var'] );
878 }
879
880 if ( !isset( $params['attribs'] ) ) {
881 $params['attribs'] = [];
882 }
883
884 $params['value'] = $this->getFakePassword( $params['value'] );
885 $params['attribs']['type'] = 'password';
886
887 return $this->getTextBox( $params );
888 }
889
906 public function getCheckBox( $params ) {
907 if ( !isset( $params['controlName'] ) ) {
908 $params['controlName'] = 'config_' . $params['var'];
909 }
910
911 if ( !isset( $params['value'] ) ) {
912 $params['value'] = $this->getVar( $params['var'] );
913 }
914
915 if ( !isset( $params['attribs'] ) ) {
916 $params['attribs'] = [];
917 }
918 if ( !isset( $params['help'] ) ) {
919 $params['help'] = "";
920 }
921 if ( !isset( $params['labelAttribs'] ) ) {
922 $params['labelAttribs'] = [];
923 }
924 $labelText = $params['rawtext'] ?? $this->parse( wfMessage( $params['label'] )->plain() );
925
926 return "<div class=\"config-input-check\">\n" .
927 $params['help'] .
928 Html::rawElement(
929 'label',
930 $params['labelAttribs'],
931 Xml::check(
932 $params['controlName'],
933 $params['value'],
934 $params['attribs'] + [
935 'id' => $params['controlName'],
936 'tabindex' => $this->nextTabIndex(),
937 ]
938 ) .
939 $labelText . "\n"
940 ) .
941 "</div>\n";
942 }
943
964 public function getRadioSet( $params ) {
965 $items = $this->getRadioElements( $params );
966
967 $label = $params['label'] ?? '';
968
969 if ( !isset( $params['controlName'] ) ) {
970 $params['controlName'] = 'config_' . $params['var'];
971 }
972
973 if ( !isset( $params['help'] ) ) {
974 $params['help'] = "";
975 }
976
977 $s = "<ul>\n";
978 foreach ( $items as $value => $item ) {
979 $s .= "<li>$item</li>\n";
980 }
981 $s .= "</ul>\n";
982
983 return $this->label( $label, $params['controlName'], $s, $params['help'] );
984 }
985
995 public function getRadioElements( $params ) {
996 if ( !isset( $params['controlName'] ) ) {
997 $params['controlName'] = 'config_' . $params['var'];
998 }
999
1000 if ( !isset( $params['value'] ) ) {
1001 $params['value'] = $this->getVar( $params['var'] );
1002 }
1003
1004 $items = [];
1005
1006 foreach ( $params['values'] as $value ) {
1007 $itemAttribs = [];
1008
1009 if ( isset( $params['commonAttribs'] ) ) {
1010 $itemAttribs = $params['commonAttribs'];
1011 }
1012
1013 if ( isset( $params['itemAttribs'][$value] ) ) {
1014 $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
1015 }
1016
1017 $checked = $value == $params['value'];
1018 $id = $params['controlName'] . '_' . $value;
1019 $itemAttribs['id'] = $id;
1020 $itemAttribs['tabindex'] = $this->nextTabIndex();
1021
1022 $items[$value] =
1023 Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
1024 "\u{00A0}" .
1025 Xml::tags( 'label', [ 'for' => $id ], $this->parse(
1026 isset( $params['itemLabels'] ) ?
1027 wfMessage( $params['itemLabels'][$value] )->plain() :
1028 wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
1029 ) );
1030 }
1031
1032 return $items;
1033 }
1034
1040 public function showStatusBox( $status ) {
1041 if ( !$status->isGood() ) {
1042 $html = $status->getHTML();
1043
1044 if ( $status->isOK() ) {
1045 $box = Html::warningBox( $html, 'config-warning-box' );
1046 } else {
1047 $box = Html::errorBox( $html, '', 'config-error-box' );
1048 }
1049
1050 $this->output->addHTML( $box );
1051 }
1052 }
1053
1064 public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
1065 $newValues = [];
1066
1067 foreach ( $varNames as $name ) {
1068 $value = $this->request->getVal( $prefix . $name );
1069 // T32524, do not trim passwords
1070 if ( $value !== null && stripos( $name, 'password' ) === false ) {
1071 $value = trim( $value );
1072 }
1073 $newValues[$name] = $value;
1074
1075 if ( $value === null ) {
1076 // Checkbox?
1077 $this->setVar( $name, false );
1078 } elseif ( stripos( $name, 'password' ) !== false ) {
1079 $this->setPassword( $name, $value );
1080 } else {
1081 $this->setVar( $name, $value );
1082 }
1083 }
1084
1085 return $newValues;
1086 }
1087
1095 public function getDocUrl( $page ) {
1096 $query = [ 'page' => $page ];
1097
1098 if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
1099 $query['lastPage'] = $this->currentPageName;
1100 }
1101
1102 return $this->getUrl( $query );
1103 }
1104
1113 public function makeLinkItem( $url, $linkText ) {
1114 return Html::rawElement( 'li', [],
1115 Html::element( 'a', [ 'href' => $url ], $linkText )
1116 );
1117 }
1118
1125 public function makeDownloadLinkHtml() {
1126 $anchor = Html::rawElement( 'a',
1127 [ 'href' => $this->getUrl( [ 'localsettings' => 1 ] ) ],
1128 wfMessage( 'config-download-localsettings' )->parse()
1129 );
1130
1131 return Html::rawElement( 'div', [ 'class' => 'config-download-link' ], $anchor );
1132 }
1133
1144 public function getLocalSettingsLocation() {
1145 return false;
1146 }
1147
1151 public function envCheckPath() {
1152 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1153 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1154 // to get the path to the current script... hopefully it's reliable. SIGH
1155 $path = false;
1156 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1157 $path = $_SERVER['PHP_SELF'];
1158 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1159 $path = $_SERVER['SCRIPT_NAME'];
1160 }
1161 if ( $path === false ) {
1162 $this->showError( 'config-no-uri' );
1163 return false;
1164 }
1165
1166 return parent::envCheckPath();
1167 }
1168
1169 public function envPrepPath() {
1170 parent::envPrepPath();
1171 // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1172 // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1173 // to get the path to the current script... hopefully it's reliable. SIGH
1174 $path = false;
1175 if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1176 $path = $_SERVER['PHP_SELF'];
1177 } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1178 $path = $_SERVER['SCRIPT_NAME'];
1179 }
1180 if ( $path !== false ) {
1181 $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
1182
1183 $this->setVar( 'wgScriptPath', "$scriptPath" );
1184 // Update variables set from Setup.php that are derived from wgScriptPath
1185 $this->setVar( 'wgScript', "$scriptPath/index.php" );
1186 $this->setVar( 'wgLoadScript', "$scriptPath/load.php" );
1187 $this->setVar( 'wgStylePath', "$scriptPath/skins" );
1188 $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
1189 $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
1190 $this->setVar( 'wgUploadPath', "$scriptPath/images" );
1191 $this->setVar( 'wgResourceBasePath', "$scriptPath" );
1192 }
1193 }
1194
1198 protected function envGetDefaultServer() {
1199 $assumeProxiesUseDefaultProtocolPorts =
1200 $this->getVar( 'wgAssumeProxiesUseDefaultProtocolPorts' );
1201
1202 return WebRequest::detectServer( $assumeProxiesUseDefaultProtocolPorts );
1203 }
1204
1208 private function outputLS() {
1209 $this->request->response()->header( 'Content-type: application/x-httpd-php' );
1210 $this->request->response()->header(
1211 'Content-Disposition: attachment; filename="LocalSettings.php"'
1212 );
1213
1215 $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )];
1216 foreach ( $rightsProfile as $group => $rightsArr ) {
1217 $ls->setGroupRights( $group, $rightsArr );
1218 }
1219 echo $ls->getText();
1220 }
1221
1225 public function outputCss() {
1226 $this->request->response()->header( 'Content-type: text/css' );
1227 echo $this->output->getCSS();
1228 }
1229
1233 public function getPhpErrors() {
1234 return $this->phpErrors;
1235 }
1236
1247 protected static function infoBox( $rawHtml, $icon, $alt, $class = '' ) {
1248 $s = Html::openElement( 'div', [ 'class' => 'mw-installer-box-left' ] ) .
1249 Html::element( 'img',
1250 [
1251 'src' => $icon,
1252 'alt' => $alt,
1253 ]
1254 ) .
1255 Html::closeElement( 'div' );
1256
1257 $s .= Html::openElement( 'div', [ 'class' => 'mw-installer-box-right' ] ) .
1258 $rawHtml .
1259 Html::closeElement( 'div' );
1260 $s .= Html::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
1261
1262 return Html::warningBox( $s, $class )
1263 . Html::element( 'div', [ 'style' => 'clear: left;' ], ' ' );
1264 }
1265
1266}
serialize()
const MW_VERSION
The running version of MediaWiki.
Definition Defines.php:36
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
global $wgRequest
Definition Setup.php:377
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgLang
Definition Setup.php:497
Marks HTML that shouldn't be escaped.
Definition HtmlArmor.php:30
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition Html.php:236
static getLocalSettingsGenerator(Installer $installer)
Instantiates and returns an instance of LocalSettingsGenerator or its descendant classes.
Base installer class.
Definition Installer.php:57
parse( $text, $lineStart=false)
Convert wikitext $text to HTML.
setVar( $name, $value)
Set a MW configuration variable, or internal installer configuration variable.
getFakePassword( $realPassword)
Get a fake password for sending back to the user in HTML.
disableTimeLimit()
Disable the time limit for execution.
array $settings
Definition Installer.php:76
setPassword( $name, $value)
Set a variable which stores a password, except if the new value is a fake password in which case leav...
getVar( $name, $default=null)
Get an MW configuration variable, or internal installer configuration variable.
A service that provides utilities to do with language names and codes.
Service locator for MediaWiki core services.
The Message class deals with fetching and processing of interface message into a variety of formats.
Definition Message.php:140
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition Status.php:44
getErrorsArray()
Get the list of errors (but not warnings)
Definition Status.php:357
getWarningsArray()
Get the list of warnings (but not errors)
Definition Status.php:369
Output class modelled on OutputPage.
Class for the core installer web interface.
makeDownloadLinkHtml()
Helper for "Download LocalSettings" link.
setupLanguage()
Initializes language-related variables.
WebInstallerOutput $output
finish()
Clean up from execute()
getTextBox( $params)
Get a labelled text box to configure a variable.
getAcceptLanguage()
Retrieves MediaWiki language from Accept-Language HTTP header.
nextTabIndex()
Get the next tabindex attribute value.
showStatusBox( $status)
Output an error or warning box using a Status object.
setVarsFromRequest( $varNames, $prefix='config_')
Convenience function to set variables based on form data.
getPageByName( $pageName)
Get a WebInstallerPage by name.
errorHandler( $errno, $errstr)
Temporary error handler for session start debugging.
bool[] $happyPages
Array of pages which have declared that they have been submitted, have validated their input,...
getSession( $name, $default=null)
Get a session variable.
outputCss()
Output stylesheet for web installer pages.
getLowestUnhappy()
Find the next page in sequence that hasn't been completed.
showHelpBox( $msg,... $params)
Output a help box.
label( $msg, $forId, $contents, $helpData="")
Label a control by wrapping a config-input div around it and putting a label before it.
execute(array $session)
Main entry point.
getLocalSettingsLocation()
If the software package wants the LocalSettings.php file to be placed in a specific location,...
getDocUrl( $page)
Helper for WebInstallerOutput.
bool[] $skippedPages
List of "skipped" pages.
getRadioElements( $params)
Get a set of labelled radio buttons.
showMessage( $msg,... $params)
Show a short informational message.
showError( $msg,... $params)
Show an error message in a box.
setSession( $name, $value)
Set a session variable.
reset()
We're restarting the installation, reset the session, happyPages, etc.
string $currentPageName
Name of the page we're on.
getHelpBox( $msg,... $args)
Get small text indented help for a preceding form field.
getRadioSet( $params)
Get a set of labelled radio buttons.
getPasswordBox( $params)
Get a labelled password box to configure a variable.
getInfoBox( $text, $icon=false, $class='')
Get HTML for an information message box with an icon.
WebRequest $request
WebRequest object.
__construct(WebRequest $request)
getTextArea( $params)
Get a labelled textarea to configure a variable.
getFingerprint()
Get a hash of data identifying this MW installation.
string[] $otherPages
Out of sequence pages, selectable by the user at any time.
string[] $pageSequence
The main sequence of page names.
string[] $phpErrors
Captured PHP error text.
static infoBox( $rawHtml, $icon, $alt, $class='')
Get HTML for an information message box with an icon.
bool $showSessionWarning
Flag indicating that session data may have been lost.
showStatusMessage(Status $status)
getCheckBox( $params)
Get a labelled checkbox to configure a boolean variable.
makeLinkItem( $url, $linkText)
Helper for sidebar links.
startSession()
Start the PHP session.
int $tabIndex
Numeric index of the page we're on.
array[] $session
Cached session array.
getUrl( $query=[])
Get a URL for submission back to the same script.
envPrepPath()
Environment prep for setting $IP and $wgScriptPath.
int $helpBoxId
Numeric index of the help box.
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
$wgLanguageCode
Config variable stub for the LanguageCode setting, for use by phpdoc and IDEs.
if( $line===false) $args
Definition mcc.php:124
foreach( $mmfl['setupFiles'] as $fileName) if($queue) if(empty( $mmfl['quiet'])) $s
if(!isset( $args[0])) $lang