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() ) {
501  $wgLang = MediaWikiServices::getInstance()->getLanguageFactory()
502  ->getLanguage( $wgLanguageCode );
503  RequestContext::getMain()->setLanguage( $wgLang );
504  $this->setVar( 'wgLanguageCode', $wgLanguageCode );
505  $this->setVar( '_UserLang', $wgLanguageCode );
506  } else {
507  $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
508  }
509  $wgContLang = MediaWikiServices::getInstance()->getContentLanguage();
510  }
511 
517  public function getAcceptLanguage() {
518  global $wgLanguageCode, $wgRequest;
519 
520  $mwLanguages = Language::fetchLanguageNames( null, 'mwfile' );
521  $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
522 
523  foreach ( $headerLanguages as $lang ) {
524  if ( isset( $mwLanguages[$lang] ) ) {
525  return $lang;
526  }
527  }
528 
529  return $wgLanguageCode;
530  }
531 
537  private function startPageWrapper( $currentPageName ) {
538  $s = "<div class=\"config-page-wrapper\">\n";
539  $s .= "<div class=\"config-page\">\n";
540  $s .= "<div class=\"config-page-list\"><ul>\n";
541  $lastHappy = -1;
542 
543  foreach ( $this->pageSequence as $id => $pageName ) {
544  $happy = !empty( $this->happyPages[$id] );
545  $s .= $this->getPageListItem(
546  $pageName,
547  $happy || $lastHappy == $id - 1,
549  );
550 
551  if ( $happy ) {
552  $lastHappy = $id;
553  }
554  }
555 
556  $s .= "</ul><br/><ul>\n";
557  $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
558  // End list pane
559  $s .= "</ul></div>\n";
560 
561  // Messages:
562  // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
563  // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
564  // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
565  // config-page-copying, config-page-upgradedoc, config-page-existingwiki
566  $s .= Html::element( 'h2', [],
567  wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
568 
569  $this->output->addHTMLNoFlush( $s );
570  }
571 
581  private function getPageListItem( $pageName, $enabled, $currentPageName ) {
582  $s = "<li class=\"config-page-list-item\">";
583 
584  // Messages:
585  // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
586  // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
587  // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
588  // config-page-copying, config-page-upgradedoc, config-page-existingwiki
589  $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
590 
591  if ( $enabled ) {
592  $query = [ 'page' => $pageName ];
593 
594  if ( !in_array( $pageName, $this->pageSequence ) ) {
595  if ( in_array( $currentPageName, $this->pageSequence ) ) {
596  $query['lastPage'] = $currentPageName;
597  }
598 
599  $link = Html::element( 'a',
600  [
601  'href' => $this->getUrl( $query )
602  ],
603  $name
604  );
605  } else {
606  $link = htmlspecialchars( $name );
607  }
608 
609  if ( $pageName == $currentPageName ) {
610  $s .= "<span class=\"config-page-current\">$link</span>";
611  } else {
612  $s .= $link;
613  }
614  } else {
615  $s .= Html::element( 'span',
616  [
617  'class' => 'config-page-disabled'
618  ],
619  $name
620  );
621  }
622 
623  $s .= "</li>\n";
624 
625  return $s;
626  }
627 
631  private function endPageWrapper() {
632  $this->output->addHTMLNoFlush(
633  "<div class=\"visualClear\"></div>\n" .
634  "</div>\n" .
635  "<div class=\"visualClear\"></div>\n" .
636  "</div>" );
637  }
638 
647  public function getErrorBox( $text ) {
648  wfDeprecated( __METHOD__, '1.34' );
649  return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
650  }
651 
660  public function getWarningBox( $text ) {
661  wfDeprecated( __METHOD__, '1.34' );
662  return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
663  }
664 
674  public function getInfoBox( $text, $icon = false, $class = false ) {
675  wfDeprecated( __METHOD__, '1.34' );
676  $html = ( $text instanceof HtmlArmor ) ?
677  HtmlArmor::getHtml( $text ) :
678  $this->parse( $text, true );
679  $icon = ( $icon == false ) ?
680  'images/info-32.png' :
681  'images/' . $icon;
682  $alt = wfMessage( 'config-information' )->text();
683 
684  return Html::infoBox( $html, $icon, $alt, $class );
685  }
686 
695  public function getHelpBox( $msg, ...$args ) {
696  $args = array_map( 'htmlspecialchars', $args );
697  $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
698  $html = $this->parse( $text, true );
699  $id = 'helpBox-' . $this->helpBoxId++;
700 
701  return "<div class=\"config-help-field-container\">\n" .
702  "<input type=\"checkbox\" class=\"config-help-field-checkbox\" id=\"$id\" />" .
703  "<label class=\"config-help-field-hint\" for=\"$id\" title=\"" .
704  wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
705  wfMessage( 'config-help' )->escaped() . "</label>\n" .
706  "<div class=\"config-help-field-data\">" . $html . "</div>\n" .
707  "</div>\n";
708  }
709 
715  public function showHelpBox( $msg, ...$params ) {
716  $html = $this->getHelpBox( $msg, ...$params );
717  $this->output->addHTML( $html );
718  }
719 
727  public function showMessage( $msg, ...$params ) {
728  $html = '<div class="config-message">' .
729  $this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) .
730  "</div>\n";
731  $this->output->addHTML( $html );
732  }
733 
737  public function showStatusMessage( Status $status ) {
738  $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
739  foreach ( $errors as $error ) {
740  $this->showMessage( ...$error );
741  }
742  }
743 
754  public function label( $msg, $forId, $contents, $helpData = "" ) {
755  if ( strval( $msg ) == '' ) {
756  $labelText = "\u{00A0}";
757  } else {
758  $labelText = wfMessage( $msg )->escaped();
759  }
760 
761  $attributes = [ 'class' => 'config-label' ];
762 
763  if ( $forId ) {
764  $attributes['for'] = $forId;
765  }
766 
767  return "<div class=\"config-block\">\n" .
768  " <div class=\"config-block-label\">\n" .
769  Xml::tags( 'label',
770  $attributes,
771  $labelText
772  ) . "\n" .
773  $helpData .
774  " </div>\n" .
775  " <div class=\"config-block-elements\">\n" .
776  $contents .
777  " </div>\n" .
778  "</div>\n";
779  }
780 
795  public function getTextBox( $params ) {
796  if ( !isset( $params['controlName'] ) ) {
797  $params['controlName'] = 'config_' . $params['var'];
798  }
799 
800  if ( !isset( $params['value'] ) ) {
801  $params['value'] = $this->getVar( $params['var'] );
802  }
803 
804  if ( !isset( $params['attribs'] ) ) {
805  $params['attribs'] = [];
806  }
807  if ( !isset( $params['help'] ) ) {
808  $params['help'] = "";
809  }
810 
811  return $this->label(
812  $params['label'],
813  $params['controlName'],
814  Xml::input(
815  $params['controlName'],
816  30, // intended to be overridden by CSS
817  $params['value'],
818  $params['attribs'] + [
819  'id' => $params['controlName'],
820  'class' => 'config-input-text',
821  'tabindex' => $this->nextTabIndex()
822  ]
823  ),
824  $params['help']
825  );
826  }
827 
842  public function getTextArea( $params ) {
843  if ( !isset( $params['controlName'] ) ) {
844  $params['controlName'] = 'config_' . $params['var'];
845  }
846 
847  if ( !isset( $params['value'] ) ) {
848  $params['value'] = $this->getVar( $params['var'] );
849  }
850 
851  if ( !isset( $params['attribs'] ) ) {
852  $params['attribs'] = [];
853  }
854  if ( !isset( $params['help'] ) ) {
855  $params['help'] = "";
856  }
857 
858  return $this->label(
859  $params['label'],
860  $params['controlName'],
862  $params['controlName'],
863  $params['value'],
864  30,
865  5,
866  $params['attribs'] + [
867  'id' => $params['controlName'],
868  'class' => 'config-input-text',
869  'tabindex' => $this->nextTabIndex()
870  ]
871  ),
872  $params['help']
873  );
874  }
875 
891  public function getPasswordBox( $params ) {
892  if ( !isset( $params['value'] ) ) {
893  $params['value'] = $this->getVar( $params['var'] );
894  }
895 
896  if ( !isset( $params['attribs'] ) ) {
897  $params['attribs'] = [];
898  }
899 
900  $params['value'] = $this->getFakePassword( $params['value'] );
901  $params['attribs']['type'] = 'password';
902 
903  return $this->getTextBox( $params );
904  }
905 
921  public function getCheckBox( $params ) {
922  if ( !isset( $params['controlName'] ) ) {
923  $params['controlName'] = 'config_' . $params['var'];
924  }
925 
926  if ( !isset( $params['value'] ) ) {
927  $params['value'] = $this->getVar( $params['var'] );
928  }
929 
930  if ( !isset( $params['attribs'] ) ) {
931  $params['attribs'] = [];
932  }
933  if ( !isset( $params['help'] ) ) {
934  $params['help'] = "";
935  }
936  if ( !isset( $params['labelAttribs'] ) ) {
937  $params['labelAttribs'] = [];
938  }
939  $labelText = $params['rawtext'] ?? $this->parse( wfMessage( $params['label'] )->plain() );
940 
941  return "<div class=\"config-input-check\">\n" .
942  $params['help'] .
943  Html::rawElement(
944  'label',
945  $params['labelAttribs'],
946  Xml::check(
947  $params['controlName'],
948  $params['value'],
949  $params['attribs'] + [
950  'id' => $params['controlName'],
951  'tabindex' => $this->nextTabIndex(),
952  ]
953  ) .
954  $labelText . "\n"
955  ) .
956  "</div>\n";
957  }
958 
978  public function getRadioSet( $params ) {
979  $items = $this->getRadioElements( $params );
980 
981  $label = $params['label'] ?? '';
982 
983  if ( !isset( $params['controlName'] ) ) {
984  $params['controlName'] = 'config_' . $params['var'];
985  }
986 
987  if ( !isset( $params['help'] ) ) {
988  $params['help'] = "";
989  }
990 
991  $s = "<ul>\n";
992  foreach ( $items as $value => $item ) {
993  $s .= "<li>$item</li>\n";
994  }
995  $s .= "</ul>\n";
996 
997  return $this->label( $label, $params['controlName'], $s, $params['help'] );
998  }
999 
1008  public function getRadioElements( $params ) {
1009  if ( !isset( $params['controlName'] ) ) {
1010  $params['controlName'] = 'config_' . $params['var'];
1011  }
1012 
1013  if ( !isset( $params['value'] ) ) {
1014  $params['value'] = $this->getVar( $params['var'] );
1015  }
1016 
1017  $items = [];
1018 
1019  foreach ( $params['values'] as $value ) {
1020  $itemAttribs = [];
1021 
1022  if ( isset( $params['commonAttribs'] ) ) {
1023  $itemAttribs = $params['commonAttribs'];
1024  }
1025 
1026  if ( isset( $params['itemAttribs'][$value] ) ) {
1027  $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
1028  }
1029 
1030  $checked = $value == $params['value'];
1031  $id = $params['controlName'] . '_' . $value;
1032  $itemAttribs['id'] = $id;
1033  $itemAttribs['tabindex'] = $this->nextTabIndex();
1034 
1035  $items[$value] =
1036  Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
1037  "\u{00A0}" .
1038  Xml::tags( 'label', [ 'for' => $id ], $this->parse(
1039  isset( $params['itemLabels'] ) ?
1040  wfMessage( $params['itemLabels'][$value] )->plain() :
1041  wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
1042  ) );
1043  }
1044 
1045  return $items;
1046  }
1047 
1053  public function showStatusBox( $status ) {
1054  if ( !$status->isGood() ) {
1055  $text = $status->getWikiText();
1056 
1057  if ( $status->isOK() ) {
1058  $box = Html::warningBox( $text, 'config-warning-box' );
1059  } else {
1060  $box = Html::errorBox( $text, '', 'config-error-box' );
1061  }
1062 
1063  $this->output->addHTML( $box );
1064  }
1065  }
1066 
1077  public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
1078  $newValues = [];
1079 
1080  foreach ( $varNames as $name ) {
1081  $value = $this->request->getVal( $prefix . $name );
1082  // T32524, do not trim passwords
1083  if ( stripos( $name, 'password' ) === false ) {
1084  $value = trim( $value );
1085  }
1086  $newValues[$name] = $value;
1087 
1088  if ( $value === null ) {
1089  // Checkbox?
1090  $this->setVar( $name, false );
1091  } elseif ( stripos( $name, 'password' ) !== false ) {
1092  $this->setPassword( $name, $value );
1093  } else {
1094  $this->setVar( $name, $value );
1095  }
1096  }
1097 
1098  return $newValues;
1099  }
1100 
1108  public function getDocUrl( $page ) {
1109  $query = [ 'page' => $page ];
1110 
1111  if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
1112  $query['lastPage'] = $this->currentPageName;
1113  }
1114 
1115  return $this->getUrl( $query );
1116  }
1117 
1126  public function makeLinkItem( $url, $linkText ) {
1127  return Html::rawElement( 'li', [],
1128  Html::element( 'a', [ 'href' => $url ], $linkText )
1129  );
1130  }
1131 
1138  public function makeDownloadLinkHtml() {
1139  $anchor = Html::rawElement( 'a',
1140  [ 'href' => $this->getUrl( [ 'localsettings' => 1 ] ) ],
1141  wfMessage( 'config-download-localsettings' )->parse()
1142  );
1143 
1144  return Html::rawElement( 'div', [ 'class' => 'config-download-link' ], $anchor );
1145  }
1146 
1157  public function getLocalSettingsLocation() {
1158  return false;
1159  }
1160 
1164  public function envCheckPath() {
1165  // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1166  // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1167  // to get the path to the current script... hopefully it's reliable. SIGH
1168  $path = false;
1169  if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1170  $path = $_SERVER['PHP_SELF'];
1171  } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1172  $path = $_SERVER['SCRIPT_NAME'];
1173  }
1174  if ( $path === false ) {
1175  $this->showError( 'config-no-uri' );
1176  return false;
1177  }
1178 
1179  return parent::envCheckPath();
1180  }
1181 
1182  public function envPrepPath() {
1183  parent::envPrepPath();
1184  // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1185  // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1186  // to get the path to the current script... hopefully it's reliable. SIGH
1187  $path = false;
1188  if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1189  $path = $_SERVER['PHP_SELF'];
1190  } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1191  $path = $_SERVER['SCRIPT_NAME'];
1192  }
1193  if ( $path !== false ) {
1194  $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
1195 
1196  $this->setVar( 'wgScriptPath', "$scriptPath" );
1197  // Update variables set from Setup.php that are derived from wgScriptPath
1198  $this->setVar( 'wgScript', "$scriptPath/index.php" );
1199  $this->setVar( 'wgLoadScript', "$scriptPath/load.php" );
1200  $this->setVar( 'wgStylePath', "$scriptPath/skins" );
1201  $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
1202  $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
1203  $this->setVar( 'wgUploadPath', "$scriptPath/images" );
1204  $this->setVar( 'wgResourceBasePath', "$scriptPath" );
1205  }
1206  }
1207 
1211  protected function envGetDefaultServer() {
1212  return WebRequest::detectServer();
1213  }
1214 
1220  private function outputLS() {
1221  $this->request->response()->header( 'Content-type: application/x-httpd-php' );
1222  $this->request->response()->header(
1223  'Content-Disposition: attachment; filename="LocalSettings.php"'
1224  );
1225 
1227  $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )];
1228  foreach ( $rightsProfile as $group => $rightsArr ) {
1229  $ls->setGroupRights( $group, $rightsArr );
1230  }
1231  echo $ls->getText();
1232  }
1233 
1237  public function outputCss() {
1238  $this->request->response()->header( 'Content-type: text/css' );
1239  echo $this->output->getCSS();
1240  }
1241 
1245  public function getPhpErrors() {
1246  return $this->phpErrors;
1247  }
1248 
1249 }
WebInstaller\getAcceptLanguage
getAcceptLanguage()
Retrieves MediaWiki language from Accept-Language HTTP header.
Definition: WebInstaller.php:517
WebInstaller\makeLinkItem
makeLinkItem( $url, $linkText)
Helper for sidebar links.
Definition: WebInstaller.php:1126
HtmlArmor
Marks HTML that shouldn't be escaped.
Definition: HtmlArmor.php:28
Installer\parse
parse( $text, $lineStart=false)
Convert wikitext $text to HTML.
Definition: Installer.php:693
WebInstaller\startPageWrapper
startPageWrapper( $currentPageName)
Called by execute() before page output starts, to show a page list.
Definition: WebInstaller.php:537
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:129
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:35
WebInstaller\getRadioElements
getRadioElements( $params)
Get a set of labelled radio buttons.
Definition: WebInstaller.php:1008
WebInstaller\label
label( $msg, $forId, $contents, $helpData="")
Label a control by wrapping a config-input div around it and putting a label before it.
Definition: WebInstaller.php:754
WebInstaller\getPageListItem
getPageListItem( $pageName, $enabled, $currentPageName)
Get a list item for the page list.
Definition: WebInstaller.php:581
WebInstaller\startSession
startSession()
Start the PHP session.
Definition: WebInstaller.php:327
WebInstaller\$showSessionWarning
bool $showSessionWarning
Flag indicating that session data may have been lost.
Definition: WebInstaller.php:118
WebInstaller\showStatusMessage
showStatusMessage(Status $status)
Definition: WebInstaller.php:737
WebInstaller\$pageSequence
string[] $pageSequence
The main sequence of page names.
Definition: WebInstaller.php:70
WebInstaller\$session
array[] $session
Cached session array.
Definition: WebInstaller.php:51
WebInstaller\setupLanguage
setupLanguage()
Initializes language-related variables.
Definition: WebInstaller.php:496
WebInstaller\getCheckBox
getCheckBox( $params)
Get a labelled checkbox to configure a boolean variable.
Definition: WebInstaller.php:921
WebInstaller
Class for the core installer web interface.
Definition: WebInstaller.php:32
WebInstaller\$helpBoxId
int $helpBoxId
Numeric index of the help box.
Definition: WebInstaller.php:132
Xml\textarea
static textarea( $name, $content, $cols=40, $rows=5, $attribs=[])
Shortcut for creating textareas.
Definition: Xml.php:635
Xml\radio
static radio( $name, $value, $checked=false, $attribs=[])
Convenience function to build an HTML radio button.
Definition: Xml.php:341
Installer\$settings
array $settings
Definition: Installer.php:65
WebInstaller\getWarningBox
getWarningBox( $text)
Get HTML for a warning box with an icon.
Definition: WebInstaller.php:660
WebInstaller\$tabIndex
int $tabIndex
Numeric index of the page we're on.
Definition: WebInstaller.php:125
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1263
$s
$s
Definition: mergeMessageFileList.php:185
WebInstaller\getPageByName
getPageByName( $pageName)
Get a WebInstallerPage by name.
Definition: WebInstaller.php:456
Message
Installer\setPassword
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:646
serialize
serialize()
Definition: ApiMessageTrait.php:138
WebInstaller\__construct
__construct(WebRequest $request)
Definition: WebInstaller.php:144
WebInstaller\$happyPages
bool[] $happyPages
Array of pages which have declared that they have been submitted, have validated their input,...
Definition: WebInstaller.php:102
WebInstaller\showStatusBox
showStatusBox( $status)
Output an error or warning box using a Status object.
Definition: WebInstaller.php:1053
WebInstaller\getLowestUnhappy
getLowestUnhappy()
Find the next page in sequence that hasn't been completed.
Definition: WebInstaller.php:313
Installer\setVar
setVar( $name, $value)
Set a MW configuration variable, or internal installer configuration variable.
Definition: Installer.php:530
WebInstaller\getInfoBox
getInfoBox( $text, $icon=false, $class=false)
Get HTML for an information message box with an icon.
Definition: WebInstaller.php:674
WebInstallerOutput
Output class modelled on OutputPage.
Definition: WebInstallerOutput.php:38
WebInstaller\$output
WebInstallerOutput $output
Definition: WebInstaller.php:37
Status
Generic operation result class Has warning/error list, boolean status and arbitrary value.
Definition: Status.php:40
WebInstaller\getRadioSet
getRadioSet( $params)
Get a set of labelled radio buttons.
Definition: WebInstaller.php:978
Installer\getFakePassword
getFakePassword( $realPassword)
Get a fake password for sending back to the user in HTML.
Definition: Installer.php:635
WebInstaller\showHelpBox
showHelpBox( $msg,... $params)
Output a help box.
Definition: WebInstaller.php:715
WebInstaller\getTextArea
getTextArea( $params)
Get a labelled textarea to configure a variable.
Definition: WebInstaller.php:842
wfDeprecated
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
Definition: GlobalFunctions.php:1044
WebInstaller\setSession
setSession( $name, $value)
Set a session variable.
Definition: WebInstaller.php:480
WebInstaller\$request
WebRequest $request
WebRequest object.
Definition: WebInstaller.php:44
WebInstaller\execute
execute(array $session)
Main entry point.
Definition: WebInstaller.php:157
HtmlArmor\getHtml
static getHtml( $input)
Provide a string or HtmlArmor object and get safe HTML back.
Definition: HtmlArmor.php:50
WebInstaller\nextTabIndex
nextTabIndex()
Get the next tabindex attribute value.
Definition: WebInstaller.php:489
WebInstaller\$skippedPages
bool[] $skippedPages
List of "skipped" pages.
Definition: WebInstaller.php:111
WebInstaller\errorHandler
errorHandler( $errno, $errstr)
Temporary error handler for session start debugging.
Definition: WebInstaller.php:403
Xml\check
static check( $name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
Definition: Xml.php:323
$wgLang
$wgLang
Definition: Setup.php:858
WebInstaller\getFingerprint
getFingerprint()
Get a hash of data identifying this MW installation.
Definition: WebInstaller.php:359
$args
if( $line===false) $args
Definition: mcc.php:124
WebInstaller\showError
showError( $msg,... $params)
Show an error message in a box.
Definition: WebInstaller.php:385
InstallerOverrides\getLocalSettingsGenerator
static getLocalSettingsGenerator(Installer $installer)
Instantiates and returns an instance of LocalSettingsGenerator or its descendant classes.
Definition: InstallerOverrides.php:50
WebInstaller\outputLS
outputLS()
Actually output LocalSettings.php for download.
Definition: WebInstaller.php:1220
Installer\getVar
getVar( $name, $default=null)
Get an MW configuration variable, or internal installer configuration variable.
Definition: Installer.php:544
WebInstaller\$phpErrors
string[] $phpErrors
Captured PHP error text.
Definition: WebInstaller.php:58
WebInstaller\$otherPages
string[] $otherPages
Out of sequence pages, selectable by the user at any time.
Definition: WebInstaller.php:88
WebInstaller\$currentPageName
string $currentPageName
Name of the page we're on.
Definition: WebInstaller.php:139
WebInstaller\envCheckPath
envCheckPath()
Definition: WebInstaller.php:1164
WebInstaller\getPasswordBox
getPasswordBox( $params)
Get a labelled password box to configure a variable.
Definition: WebInstaller.php:891
Xml\tags
static tags( $element, $attribs, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:130
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:2949
WebInstaller\reset
reset()
We're restarting the installation, reset the session, happyPages, etc.
Definition: WebInstaller.php:425
WebInstaller\setVarsFromRequest
setVarsFromRequest( $varNames, $prefix='config_')
Convenience function to set variables based on form data.
Definition: WebInstaller.php:1077
WebInstaller\outputCss
outputCss()
Output stylesheet for web installer pages.
Definition: WebInstaller.php:1237
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:445
wfIniGetBool
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
Definition: GlobalFunctions.php:2064
WebInstaller\endPageWrapper
endPageWrapper()
Output some stuff after a page is finished.
Definition: WebInstaller.php:631
WebInstaller\makeDownloadLinkHtml
makeDownloadLinkHtml()
Helper for "Download LocalSettings" link.
Definition: WebInstaller.php:1138
WebInstaller\getLocalSettingsLocation
getLocalSettingsLocation()
If the software package wants the LocalSettings.php file to be placed in a specific location,...
Definition: WebInstaller.php:1157
WebInstaller\getErrorBox
getErrorBox( $text)
Get HTML for an error box with an icon.
Definition: WebInstaller.php:647
WebRequest
The WebRequest class encapsulates getting at data passed in the URL or via a POSTed form stripping il...
Definition: WebRequest.php:42
WebInstaller\envPrepPath
envPrepPath()
Environment prep for setting $IP and $wgScriptPath.
Definition: WebInstaller.php:1182
WebInstaller\envGetDefaultServer
envGetDefaultServer()
Definition: WebInstaller.php:1211
WebInstaller\getHelpBox
getHelpBox( $msg,... $args)
Get small text indented help for a preceding form field.
Definition: WebInstaller.php:695
WebInstaller\getPhpErrors
getPhpErrors()
Definition: WebInstaller.php:1245
Status\getWarningsArray
getWarningsArray()
Get the list of warnings (but not errors)
Definition: Status.php:361
$path
$path
Definition: NoLocalSettings.php:25
WebInstaller\getDocUrl
getDocUrl( $page)
Helper for WebInstallerOutput.
Definition: WebInstaller.php:1108
WebRequest\detectServer
static detectServer()
Work out an appropriate URL prefix containing scheme and host, based on information detected from $_S...
Definition: WebRequest.php:234
Installer\disableTimeLimit
disableTimeLimit()
Disable the time limit for execution.
Definition: Installer.php:1835
WebInstaller\getTextBox
getTextBox( $params)
Get a labelled text box to configure a variable.
Definition: WebInstaller.php:795
Installer
Base installer class.
Definition: Installer.php:52
Xml\input
static input( $name, $size=false, $value=false, $attribs=[])
Convenience function to build an HTML text input field.
Definition: Xml.php:274
$wgRequest
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:729
Language\fetchLanguageNames
static fetchLanguageNames( $inLanguage=self::AS_AUTONYMS, $include='mw')
Get an array of language names, indexed by code.
Definition: Language.php:854
Status\getErrorsArray
getErrorsArray()
Get the list of errors (but not warnings)
Definition: Status.php:350
WebInstaller\getSession
getSession( $name, $default=null)
Get a session variable.
Definition: WebInstaller.php:470
$wgContLang
$wgContLang
Definition: Setup.php:778
WebInstaller\finish
finish()
Clean up from execute()
Definition: WebInstaller.php:412
WebInstaller\showMessage
showMessage( $msg,... $params)
Show a short informational message.
Definition: WebInstaller.php:727
$GLOBALS
$GLOBALS['IP']
Definition: ComposerHookHandler.php:6
WebInstaller\getUrl
getUrl( $query=[])
Get a URL for submission back to the same script.
Definition: WebInstaller.php:438
wfArrayToCgi
wfArrayToCgi( $array1, $array2=null, $prefix='')
This function takes one or two arrays as input, and returns a CGI-style string, e....
Definition: GlobalFunctions.php:347