MediaWiki  master
WebInstaller.php
Go to the documentation of this file.
1 <?php
25 
32 class WebInstaller extends Installer {
33 
37  public $output;
38 
44  public $request;
45 
51  protected $session;
52 
58  protected $phpErrors;
59 
70  public $pageSequence = [
71  'Language',
72  'ExistingWiki',
73  'Welcome',
74  'DBConnect',
75  'Upgrade',
76  'DBSettings',
77  'Name',
78  'Options',
79  'Install',
80  'Complete',
81  ];
82 
88  protected $otherPages = [
89  'Restart',
90  'Readme',
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 
139  protected $currentPageName;
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  $this->phpErrors = [];
334  set_error_handler( [ $this, 'errorHandler' ] );
335  try {
336  session_name( 'mw_installer_session' );
337  session_start();
338  } catch ( Exception $e ) {
339  restore_error_handler();
340  throw $e;
341  }
342  restore_error_handler();
343 
344  if ( $this->phpErrors ) {
345  return false;
346  }
347 
348  return true;
349  }
350 
359  public function getFingerprint() {
360  // Get the base URL of the installation
361  $url = $this->request->getFullRequestURL();
362  if ( preg_match( '!^(.*\?)!', $url, $m ) ) {
363  // Trim query string
364  $url = $m[1];
365  }
366  if ( preg_match( '!^(.*)/[^/]*/[^/]*$!', $url, $m ) ) {
367  // This... seems to try to get the base path from
368  // the /mw-config/index.php. Kinda scary though?
369  $url = $m[1];
370  }
371 
372  return md5( serialize( [
373  'local path' => dirname( __DIR__ ),
374  'url' => $url,
375  'version' => $GLOBALS['wgVersion']
376  ] ) );
377  }
378 
385  public function showError( $msg, ...$params ) {
386  if ( !( $msg instanceof Message ) ) {
387  $msg = wfMessage(
388  $msg,
389  array_map( 'htmlspecialchars', $params )
390  );
391  }
392  $text = $msg->useDatabase( false )->plain();
393  $box = Html::errorBox( $text, '', 'config-error-box' );
394  $this->output->addHTML( $box );
395  }
396 
403  public function errorHandler( $errno, $errstr ) {
404  $this->phpErrors[] = $errstr;
405  }
406 
412  public function finish() {
413  $this->output->output();
414 
415  $this->session['happyPages'] = $this->happyPages;
416  $this->session['skippedPages'] = $this->skippedPages;
417  $this->session['settings'] = $this->settings;
418 
419  return $this->session;
420  }
421 
425  public function reset() {
426  $this->session = [];
427  $this->happyPages = [];
428  $this->settings = [];
429  }
430 
438  public function getUrl( $query = [] ) {
439  $url = $this->request->getRequestURL();
440  # Remove existing query
441  $url = preg_replace( '/\?.*$/', '', $url );
442 
443  if ( $query ) {
444  $url .= '?' . wfArrayToCgi( $query );
445  }
446 
447  return $url;
448  }
449 
456  public function getPageByName( $pageName ) {
457  $pageClass = 'WebInstaller' . $pageName;
458 
459  return new $pageClass( $this );
460  }
461 
470  public function getSession( $name, $default = null ) {
471  return $this->session[$name] ?? $default;
472  }
473 
480  public function setSession( $name, $value ) {
481  $this->session[$name] = $value;
482  }
483 
489  public function nextTabIndex() {
490  return $this->tabIndex++;
491  }
492 
496  public function setupLanguage() {
498 
499  if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
500  $wgLanguageCode = $this->getAcceptLanguage();
501  $wgLang = Language::factory( $wgLanguageCode );
502  RequestContext::getMain()->setLanguage( $wgLang );
503  $this->setVar( 'wgLanguageCode', $wgLanguageCode );
504  $this->setVar( '_UserLang', $wgLanguageCode );
505  } else {
506  $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
507  }
508  $wgContLang = MediaWikiServices::getInstance()->getContentLanguage();
509  }
510 
516  public function getAcceptLanguage() {
517  global $wgLanguageCode, $wgRequest;
518 
519  $mwLanguages = Language::fetchLanguageNames( null, 'mwfile' );
520  $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
521 
522  foreach ( $headerLanguages as $lang ) {
523  if ( isset( $mwLanguages[$lang] ) ) {
524  return $lang;
525  }
526  }
527 
528  return $wgLanguageCode;
529  }
530 
536  private function startPageWrapper( $currentPageName ) {
537  $s = "<div class=\"config-page-wrapper\">\n";
538  $s .= "<div class=\"config-page\">\n";
539  $s .= "<div class=\"config-page-list\"><ul>\n";
540  $lastHappy = -1;
541 
542  foreach ( $this->pageSequence as $id => $pageName ) {
543  $happy = !empty( $this->happyPages[$id] );
544  $s .= $this->getPageListItem(
545  $pageName,
546  $happy || $lastHappy == $id - 1,
548  );
549 
550  if ( $happy ) {
551  $lastHappy = $id;
552  }
553  }
554 
555  $s .= "</ul><br/><ul>\n";
556  $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
557  // End list pane
558  $s .= "</ul></div>\n";
559 
560  // Messages:
561  // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
562  // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
563  // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
564  // config-page-copying, config-page-upgradedoc, config-page-existingwiki
565  $s .= Html::element( 'h2', [],
566  wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
567 
568  $this->output->addHTMLNoFlush( $s );
569  }
570 
580  private function getPageListItem( $pageName, $enabled, $currentPageName ) {
581  $s = "<li class=\"config-page-list-item\">";
582 
583  // Messages:
584  // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
585  // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
586  // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
587  // config-page-copying, config-page-upgradedoc, config-page-existingwiki
588  $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
589 
590  if ( $enabled ) {
591  $query = [ 'page' => $pageName ];
592 
593  if ( !in_array( $pageName, $this->pageSequence ) ) {
594  if ( in_array( $currentPageName, $this->pageSequence ) ) {
595  $query['lastPage'] = $currentPageName;
596  }
597 
598  $link = Html::element( 'a',
599  [
600  'href' => $this->getUrl( $query )
601  ],
602  $name
603  );
604  } else {
605  $link = htmlspecialchars( $name );
606  }
607 
608  if ( $pageName == $currentPageName ) {
609  $s .= "<span class=\"config-page-current\">$link</span>";
610  } else {
611  $s .= $link;
612  }
613  } else {
614  $s .= Html::element( 'span',
615  [
616  'class' => 'config-page-disabled'
617  ],
618  $name
619  );
620  }
621 
622  $s .= "</li>\n";
623 
624  return $s;
625  }
626 
630  private function endPageWrapper() {
631  $this->output->addHTMLNoFlush(
632  "<div class=\"visualClear\"></div>\n" .
633  "</div>\n" .
634  "<div class=\"visualClear\"></div>\n" .
635  "</div>" );
636  }
637 
646  public function getErrorBox( $text ) {
647  wfDeprecated( __METHOD__, '1.34' );
648  return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
649  }
650 
659  public function getWarningBox( $text ) {
660  wfDeprecated( __METHOD__, '1.34' );
661  return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
662  }
663 
673  public function getInfoBox( $text, $icon = false, $class = false ) {
674  wfDeprecated( __METHOD__, '1.34' );
675  $html = ( $text instanceof HtmlArmor ) ?
676  HtmlArmor::getHtml( $text ) :
677  $this->parse( $text, true );
678  $icon = ( $icon == false ) ?
679  'images/info-32.png' :
680  'images/' . $icon;
681  $alt = wfMessage( 'config-information' )->text();
682 
683  return Html::infoBox( $html, $icon, $alt, $class );
684  }
685 
693  public function getHelpBox( $msg, ...$args ) {
694  $args = array_map( 'htmlspecialchars', $args );
695  $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
696  $html = $this->parse( $text, true );
697  $id = 'helpBox-' . $this->helpBoxId++;
698 
699  return "<div class=\"config-help-field-container\">\n" .
700  "<input type=\"checkbox\" class=\"config-help-field-checkbox\" id=\"$id\" />" .
701  "<label class=\"config-help-field-hint\" for=\"$id\" title=\"" .
702  wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
703  wfMessage( 'config-help' )->escaped() . "</label>\n" .
704  "<div class=\"config-help-field-data\">" . $html . "</div>\n" .
705  "</div>\n";
706  }
707 
713  public function showHelpBox( $msg, ...$params ) {
714  $html = $this->getHelpBox( $msg, ...$params );
715  $this->output->addHTML( $html );
716  }
717 
725  public function showMessage( $msg, ...$params ) {
726  $html = '<div class="config-message">' .
727  $this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) .
728  "</div>\n";
729  $this->output->addHTML( $html );
730  }
731 
735  public function showStatusMessage( Status $status ) {
736  $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
737  foreach ( $errors as $error ) {
738  $this->showMessage( ...$error );
739  }
740  }
741 
752  public function label( $msg, $forId, $contents, $helpData = "" ) {
753  if ( strval( $msg ) == '' ) {
754  $labelText = "\u{00A0}";
755  } else {
756  $labelText = wfMessage( $msg )->escaped();
757  }
758 
759  $attributes = [ 'class' => 'config-label' ];
760 
761  if ( $forId ) {
762  $attributes['for'] = $forId;
763  }
764 
765  return "<div class=\"config-block\">\n" .
766  " <div class=\"config-block-label\">\n" .
767  Xml::tags( 'label',
768  $attributes,
769  $labelText
770  ) . "\n" .
771  $helpData .
772  " </div>\n" .
773  " <div class=\"config-block-elements\">\n" .
774  $contents .
775  " </div>\n" .
776  "</div>\n";
777  }
778 
793  public function getTextBox( $params ) {
794  if ( !isset( $params['controlName'] ) ) {
795  $params['controlName'] = 'config_' . $params['var'];
796  }
797 
798  if ( !isset( $params['value'] ) ) {
799  $params['value'] = $this->getVar( $params['var'] );
800  }
801 
802  if ( !isset( $params['attribs'] ) ) {
803  $params['attribs'] = [];
804  }
805  if ( !isset( $params['help'] ) ) {
806  $params['help'] = "";
807  }
808 
809  return $this->label(
810  $params['label'],
811  $params['controlName'],
812  Xml::input(
813  $params['controlName'],
814  30, // intended to be overridden by CSS
815  $params['value'],
816  $params['attribs'] + [
817  'id' => $params['controlName'],
818  'class' => 'config-input-text',
819  'tabindex' => $this->nextTabIndex()
820  ]
821  ),
822  $params['help']
823  );
824  }
825 
840  public function getTextArea( $params ) {
841  if ( !isset( $params['controlName'] ) ) {
842  $params['controlName'] = 'config_' . $params['var'];
843  }
844 
845  if ( !isset( $params['value'] ) ) {
846  $params['value'] = $this->getVar( $params['var'] );
847  }
848 
849  if ( !isset( $params['attribs'] ) ) {
850  $params['attribs'] = [];
851  }
852  if ( !isset( $params['help'] ) ) {
853  $params['help'] = "";
854  }
855 
856  return $this->label(
857  $params['label'],
858  $params['controlName'],
860  $params['controlName'],
861  $params['value'],
862  30,
863  5,
864  $params['attribs'] + [
865  'id' => $params['controlName'],
866  'class' => 'config-input-text',
867  'tabindex' => $this->nextTabIndex()
868  ]
869  ),
870  $params['help']
871  );
872  }
873 
889  public function getPasswordBox( $params ) {
890  if ( !isset( $params['value'] ) ) {
891  $params['value'] = $this->getVar( $params['var'] );
892  }
893 
894  if ( !isset( $params['attribs'] ) ) {
895  $params['attribs'] = [];
896  }
897 
898  $params['value'] = $this->getFakePassword( $params['value'] );
899  $params['attribs']['type'] = 'password';
900 
901  return $this->getTextBox( $params );
902  }
903 
919  public function getCheckBox( $params ) {
920  if ( !isset( $params['controlName'] ) ) {
921  $params['controlName'] = 'config_' . $params['var'];
922  }
923 
924  if ( !isset( $params['value'] ) ) {
925  $params['value'] = $this->getVar( $params['var'] );
926  }
927 
928  if ( !isset( $params['attribs'] ) ) {
929  $params['attribs'] = [];
930  }
931  if ( !isset( $params['help'] ) ) {
932  $params['help'] = "";
933  }
934  if ( !isset( $params['labelAttribs'] ) ) {
935  $params['labelAttribs'] = [];
936  }
937  $labelText = $params['rawtext'] ?? $this->parse( wfMessage( $params['label'] )->plain() );
938 
939  return "<div class=\"config-input-check\">\n" .
940  $params['help'] .
942  'label',
943  $params['labelAttribs'],
944  Xml::check(
945  $params['controlName'],
946  $params['value'],
947  $params['attribs'] + [
948  'id' => $params['controlName'],
949  'tabindex' => $this->nextTabIndex(),
950  ]
951  ) .
952  $labelText . "\n"
953  ) .
954  "</div>\n";
955  }
956 
976  public function getRadioSet( $params ) {
977  $items = $this->getRadioElements( $params );
978 
979  $label = $params['label'] ?? '';
980 
981  if ( !isset( $params['controlName'] ) ) {
982  $params['controlName'] = 'config_' . $params['var'];
983  }
984 
985  if ( !isset( $params['help'] ) ) {
986  $params['help'] = "";
987  }
988 
989  $s = "<ul>\n";
990  foreach ( $items as $value => $item ) {
991  $s .= "<li>$item</li>\n";
992  }
993  $s .= "</ul>\n";
994 
995  return $this->label( $label, $params['controlName'], $s, $params['help'] );
996  }
997 
1006  public function getRadioElements( $params ) {
1007  if ( !isset( $params['controlName'] ) ) {
1008  $params['controlName'] = 'config_' . $params['var'];
1009  }
1010 
1011  if ( !isset( $params['value'] ) ) {
1012  $params['value'] = $this->getVar( $params['var'] );
1013  }
1014 
1015  $items = [];
1016 
1017  foreach ( $params['values'] as $value ) {
1018  $itemAttribs = [];
1019 
1020  if ( isset( $params['commonAttribs'] ) ) {
1021  $itemAttribs = $params['commonAttribs'];
1022  }
1023 
1024  if ( isset( $params['itemAttribs'][$value] ) ) {
1025  $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
1026  }
1027 
1028  $checked = $value == $params['value'];
1029  $id = $params['controlName'] . '_' . $value;
1030  $itemAttribs['id'] = $id;
1031  $itemAttribs['tabindex'] = $this->nextTabIndex();
1032 
1033  $items[$value] =
1034  Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
1035  "\u{00A0}" .
1036  Xml::tags( 'label', [ 'for' => $id ], $this->parse(
1037  isset( $params['itemLabels'] ) ?
1038  wfMessage( $params['itemLabels'][$value] )->plain() :
1039  wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
1040  ) );
1041  }
1042 
1043  return $items;
1044  }
1045 
1051  public function showStatusBox( $status ) {
1052  if ( !$status->isGood() ) {
1053  $text = $status->getWikiText();
1054 
1055  if ( $status->isOK() ) {
1056  $box = Html::warningBox( $text, 'config-warning-box' );
1057  } else {
1058  $box = Html::errorBox( $text, '', 'config-error-box' );
1059  }
1060 
1061  $this->output->addHTML( $box );
1062  }
1063  }
1064 
1075  public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
1076  $newValues = [];
1077 
1078  foreach ( $varNames as $name ) {
1079  $value = $this->request->getVal( $prefix . $name );
1080  // T32524, do not trim passwords
1081  if ( stripos( $name, 'password' ) === false ) {
1082  $value = trim( $value );
1083  }
1084  $newValues[$name] = $value;
1085 
1086  if ( $value === null ) {
1087  // Checkbox?
1088  $this->setVar( $name, false );
1089  } elseif ( stripos( $name, 'password' ) !== false ) {
1090  $this->setPassword( $name, $value );
1091  } else {
1092  $this->setVar( $name, $value );
1093  }
1094  }
1095 
1096  return $newValues;
1097  }
1098 
1106  public function getDocUrl( $page ) {
1107  $query = [ 'page' => $page ];
1108 
1109  if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
1110  $query['lastPage'] = $this->currentPageName;
1111  }
1112 
1113  return $this->getUrl( $query );
1114  }
1115 
1124  public function makeLinkItem( $url, $linkText ) {
1125  return Html::rawElement( 'li', [],
1126  Html::element( 'a', [ 'href' => $url ], $linkText )
1127  );
1128  }
1129 
1136  public function makeDownloadLinkHtml() {
1137  $anchor = Html::rawElement( 'a',
1138  [ 'href' => $this->getUrl( [ 'localsettings' => 1 ] ) ],
1139  wfMessage( 'config-download-localsettings' )->parse()
1140  );
1141 
1142  return Html::rawElement( 'div', [ 'class' => 'config-download-link' ], $anchor );
1143  }
1144 
1155  public function getLocalSettingsLocation() {
1156  return false;
1157  }
1158 
1162  public function envCheckPath() {
1163  // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1164  // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1165  // to get the path to the current script... hopefully it's reliable. SIGH
1166  $path = false;
1167  if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1168  $path = $_SERVER['PHP_SELF'];
1169  } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1170  $path = $_SERVER['SCRIPT_NAME'];
1171  }
1172  if ( $path === false ) {
1173  $this->showError( 'config-no-uri' );
1174  return false;
1175  }
1176 
1177  return parent::envCheckPath();
1178  }
1179 
1180  public function envPrepPath() {
1181  parent::envPrepPath();
1182  // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1183  // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1184  // to get the path to the current script... hopefully it's reliable. SIGH
1185  $path = false;
1186  if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1187  $path = $_SERVER['PHP_SELF'];
1188  } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1189  $path = $_SERVER['SCRIPT_NAME'];
1190  }
1191  if ( $path !== false ) {
1192  $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
1193 
1194  $this->setVar( 'wgScriptPath', "$scriptPath" );
1195  // Update variables set from Setup.php that are derived from wgScriptPath
1196  $this->setVar( 'wgScript', "$scriptPath/index.php" );
1197  $this->setVar( 'wgLoadScript', "$scriptPath/load.php" );
1198  $this->setVar( 'wgStylePath', "$scriptPath/skins" );
1199  $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
1200  $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
1201  $this->setVar( 'wgUploadPath', "$scriptPath/images" );
1202  $this->setVar( 'wgResourceBasePath', "$scriptPath" );
1203  }
1204  }
1205 
1209  protected function envGetDefaultServer() {
1210  return WebRequest::detectServer();
1211  }
1212 
1218  private function outputLS() {
1219  $this->request->response()->header( 'Content-type: application/x-httpd-php' );
1220  $this->request->response()->header(
1221  'Content-Disposition: attachment; filename="LocalSettings.php"'
1222  );
1223 
1225  $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )];
1226  foreach ( $rightsProfile as $group => $rightsArr ) {
1227  $ls->setGroupRights( $group, $rightsArr );
1228  }
1229  echo $ls->getText();
1230  }
1231 
1235  public function outputCss() {
1236  $this->request->response()->header( 'Content-type: text/css' );
1237  echo $this->output->getCSS();
1238  }
1239 
1243  public function getPhpErrors() {
1244  return $this->phpErrors;
1245  }
1246 
1247 }
static fetchLanguageNames( $inLanguage=self::AS_AUTONYMS, $include='mw')
Get an array of language names, indexed by code.
Definition: Language.php:814
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
getWarningBox( $text)
Get HTML for a warning box with an icon.
int $tabIndex
Numeric index of the page we&#39;re on.
static getHtml( $input)
Provide a string or HtmlArmor object and get safe HTML back.
Definition: HtmlArmor.php:50
serialize()
getPageByName( $pageName)
Get a WebInstallerPage by name.
The Message class provides methods which fulfil two basic services:
Definition: Message.php:162
__construct(WebRequest $request)
getRadioSet( $params)
Get a set of labelled radio buttons.
bool [] $happyPages
Array of pages which have declared that they have been submitted, have validated their input...
if(!isset( $args[0])) $lang
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
getInfoBox( $text, $icon=false, $class=false)
Get HTML for an information message box with an icon.
static input( $name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
Definition: Xml.php:274
Class for the core installer web interface.
array $settings
Definition: Installer.php:59
getFingerprint()
Get a hash of data identifying this MW installation.
WebRequest $request
WebRequest object.
getRadioElements( $params)
Get a set of labelled radio buttons.
startSession()
Start the PHP session.
setPassword( $name, $value)
Set a variable which stores a password, except if the new value is a fake password in which case leav...
Definition: Installer.php:641
static getLocalSettingsGenerator(Installer $installer)
Instantiates and returns an instance of LocalSettingsGenerator or its descendant classes.
showStatusMessage(Status $status)
getWarningsArray()
Get the list of warnings (but not errors)
Definition: Status.php:354
array [] $session
Cached session array.
getCheckBox( $params)
Get a labelled checkbox to configure a boolean variable.
label( $msg, $forId, $contents, $helpData="")
Label a control by wrapping a config-input div around it and putting a label before it...
if( $line===false) $args
Definition: cdb.php:64
int $helpBoxId
Numeric index of the help box.
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e.g.
Output class modelled on OutputPage.
$wgLanguageCode
Site language code.
string [] $pageSequence
The main sequence of page names.
static detectServer()
Work out an appropriate URL prefix containing scheme and host, based on information detected from $_S...
Definition: WebRequest.php:234
static errorBox( $html, $heading='', $className='')
Return an error box.
Definition: Html.php:739
$wgLang
Definition: Setup.php:857
static getMain()
Get the RequestContext object associated with the main request.
getErrorsArray()
Get the list of errors (but not warnings)
Definition: Status.php:343
showStatusBox( $status)
Output an error or warning box using a Status object.
makeDownloadLinkHtml()
Helper for "Download LocalSettings" link.
getLowestUnhappy()
Find the next page in sequence that hasn&#39;t been completed.
setVarsFromRequest( $varNames, $prefix='config_')
Convenience function to set variables based on form data.
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
showHelpBox( $msg,... $params)
Output a help box.
getFakePassword( $realPassword)
Get a fake password for sending back to the user in HTML.
Definition: Installer.php:630
outputCss()
Output stylesheet for web installer pages.
WebInstallerOutput $output
getVar( $name, $default=null)
Get an MW configuration variable, or internal installer configuration variable.
Definition: Installer.php:539
getLocalSettingsLocation()
If the software package wants the LocalSettings.php file to be placed in a specific location...
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:212
setSession( $name, $value)
Set a session variable.
getErrorBox( $text)
Get HTML for an error box with an icon.
disableTimeLimit()
Disable the time limit for execution.
Definition: Installer.php:1841
$GLOBALS['IP']
nextTabIndex()
Get the next tabindex attribute value.
bool [] $skippedPages
List of "skipped" pages.
getHelpBox( $msg,... $args)
Get small text indented help for a preceding form field.
getTextArea( $params)
Get a labelled textarea to configure a variable.
getDocUrl( $page)
Helper for WebInstallerOutput.
static warningBox( $html, $className='')
Return a warning box.
Definition: Html.php:726
execute(array $session)
Main entry point.
errorHandler( $errno, $errstr)
Temporary error handler for session start debugging.
parse( $text, $lineStart=false)
Convert wikitext $text to HTML.
Definition: Installer.php:688
showError( $msg,... $params)
Show an error message in a box.
static textarea( $name, $content, $cols=40, $rows=5, $attribs=[])
Shortcut for creating textareas.
Definition: Xml.php:635
string [] $phpErrors
Captured PHP error text.
outputLS()
Actually output LocalSettings.php for download.
showMessage( $msg,... $params)
Show a short informational message.
getSession( $name, $default=null)
Get a session variable.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
finish()
Clean up from execute()
getPasswordBox( $params)
Get a labelled password box to configure a variable.
static infoBox( $rawHtml, $icon, $alt, $class='')
Get HTML for an information message box with an icon.
Definition: Html.php:1021
Base installer class.
Definition: Installer.php:46
string [] $otherPages
Out of sequence pages, selectable by the user at any time.
string $currentPageName
Name of the page we&#39;re on.
getUrl( $query=[])
Get a URL for submission back to the same script.
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:728
getAcceptLanguage()
Retrieves MediaWiki language from Accept-Language HTTP header.
reset()
We&#39;re restarting the installation, reset the session, happyPages, etc.
makeLinkItem( $url, $linkText)
Helper for sidebar links.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
setVar( $name, $value)
Set a MW configuration variable, or internal installer configuration variable.
Definition: Installer.php:525
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
static radio( $name, $value, $checked=false, $attribs=[])
Convenience function to build an HTML radio button.
Definition: Xml.php:341
startPageWrapper( $currentPageName)
Called by execute() before page output starts, to show a page list.
getPageListItem( $pageName, $enabled, $currentPageName)
Get a list item for the page list.
endPageWrapper()
Output some stuff after a page is finished.
bool $showSessionWarning
Flag indicating that session data may have been lost.
static check( $name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
Definition: Xml.php:323
setupLanguage()
Initializes language-related variables.
$wgContLang
Definition: Setup.php:777
getTextBox( $params)
Get a labelled text box to configure a variable.