MediaWiki  1.34.4
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  // 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' => $GLOBALS['wgVersion']
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 )->plain();
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() {
504 
505  if ( $this->getSession( 'test' ) === null && !$this->request->wasPosted() ) {
507  $wgLang = Language::factory( $wgLanguageCode );
508  RequestContext::getMain()->setLanguage( $wgLang );
509  $this->setVar( 'wgLanguageCode', $wgLanguageCode );
510  $this->setVar( '_UserLang', $wgLanguageCode );
511  } else {
512  $wgLanguageCode = $this->getVar( 'wgLanguageCode' );
513  }
514  $wgContLang = MediaWikiServices::getInstance()->getContentLanguage();
515  }
516 
522  public function getAcceptLanguage() {
523  global $wgLanguageCode, $wgRequest;
524 
525  $mwLanguages = Language::fetchLanguageNames( null, 'mwfile' );
526  $headerLanguages = array_keys( $wgRequest->getAcceptLang() );
527 
528  foreach ( $headerLanguages as $lang ) {
529  if ( isset( $mwLanguages[$lang] ) ) {
530  return $lang;
531  }
532  }
533 
534  return $wgLanguageCode;
535  }
536 
542  private function startPageWrapper( $currentPageName ) {
543  $s = "<div class=\"config-page-wrapper\">\n";
544  $s .= "<div class=\"config-page\">\n";
545  $s .= "<div class=\"config-page-list\"><ul>\n";
546  $lastHappy = -1;
547 
548  foreach ( $this->pageSequence as $id => $pageName ) {
549  $happy = !empty( $this->happyPages[$id] );
550  $s .= $this->getPageListItem(
551  $pageName,
552  $happy || $lastHappy == $id - 1,
554  );
555 
556  if ( $happy ) {
557  $lastHappy = $id;
558  }
559  }
560 
561  $s .= "</ul><br/><ul>\n";
562  $s .= $this->getPageListItem( 'Restart', true, $currentPageName );
563  // End list pane
564  $s .= "</ul></div>\n";
565 
566  // Messages:
567  // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
568  // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
569  // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
570  // config-page-copying, config-page-upgradedoc, config-page-existingwiki
571  $s .= Html::element( 'h2', [],
572  wfMessage( 'config-page-' . strtolower( $currentPageName ) )->text() );
573 
574  $this->output->addHTMLNoFlush( $s );
575  }
576 
586  private function getPageListItem( $pageName, $enabled, $currentPageName ) {
587  $s = "<li class=\"config-page-list-item\">";
588 
589  // Messages:
590  // config-page-language, config-page-welcome, config-page-dbconnect, config-page-upgrade,
591  // config-page-dbsettings, config-page-name, config-page-options, config-page-install,
592  // config-page-complete, config-page-restart, config-page-readme, config-page-releasenotes,
593  // config-page-copying, config-page-upgradedoc, config-page-existingwiki
594  $name = wfMessage( 'config-page-' . strtolower( $pageName ) )->text();
595 
596  if ( $enabled ) {
597  $query = [ 'page' => $pageName ];
598 
599  if ( !in_array( $pageName, $this->pageSequence ) ) {
600  if ( in_array( $currentPageName, $this->pageSequence ) ) {
601  $query['lastPage'] = $currentPageName;
602  }
603 
604  $link = Html::element( 'a',
605  [
606  'href' => $this->getUrl( $query )
607  ],
608  $name
609  );
610  } else {
611  $link = htmlspecialchars( $name );
612  }
613 
614  if ( $pageName == $currentPageName ) {
615  $s .= "<span class=\"config-page-current\">$link</span>";
616  } else {
617  $s .= $link;
618  }
619  } else {
620  $s .= Html::element( 'span',
621  [
622  'class' => 'config-page-disabled'
623  ],
624  $name
625  );
626  }
627 
628  $s .= "</li>\n";
629 
630  return $s;
631  }
632 
636  private function endPageWrapper() {
637  $this->output->addHTMLNoFlush(
638  "<div class=\"visualClear\"></div>\n" .
639  "</div>\n" .
640  "<div class=\"visualClear\"></div>\n" .
641  "</div>" );
642  }
643 
652  public function getErrorBox( $text ) {
653  wfDeprecated( __METHOD__, '1.34' );
654  return $this->getInfoBox( $text, 'critical-32.png', 'config-error-box' );
655  }
656 
665  public function getWarningBox( $text ) {
666  wfDeprecated( __METHOD__, '1.34' );
667  return $this->getInfoBox( $text, 'warning-32.png', 'config-warning-box' );
668  }
669 
678  public function getInfoBox( $text, $icon = false, $class = false ) {
679  $html = ( $text instanceof HtmlArmor ) ?
680  HtmlArmor::getHtml( $text ) :
681  $this->parse( $text, true );
682  $icon = ( $icon == false ) ?
683  'images/info-32.png' :
684  'images/' . $icon;
685  $alt = wfMessage( 'config-information' )->text();
686 
687  return Html::infoBox( $html, $icon, $alt, $class );
688  }
689 
697  public function getHelpBox( $msg, ...$args ) {
698  $args = array_map( 'htmlspecialchars', $args );
699  $text = wfMessage( $msg, $args )->useDatabase( false )->plain();
700  $html = $this->parse( $text, true );
701  $id = 'helpBox-' . $this->helpBoxId++;
702 
703  return "<div class=\"config-help-field-container\">\n" .
704  "<input type=\"checkbox\" class=\"config-help-field-checkbox\" id=\"$id\" />" .
705  "<label class=\"config-help-field-hint\" for=\"$id\" title=\"" .
706  wfMessage( 'config-help-tooltip' )->escaped() . "\">" .
707  wfMessage( 'config-help' )->escaped() . "</label>\n" .
708  "<div class=\"config-help-field-data\">" . $html . "</div>\n" .
709  "</div>\n";
710  }
711 
717  public function showHelpBox( $msg, ...$params ) {
718  $html = $this->getHelpBox( $msg, ...$params );
719  $this->output->addHTML( $html );
720  }
721 
729  public function showMessage( $msg, ...$params ) {
730  $html = '<div class="config-message">' .
731  $this->parse( wfMessage( $msg, $params )->useDatabase( false )->plain() ) .
732  "</div>\n";
733  $this->output->addHTML( $html );
734  }
735 
739  public function showStatusMessage( Status $status ) {
740  $errors = array_merge( $status->getErrorsArray(), $status->getWarningsArray() );
741  foreach ( $errors as $error ) {
742  $this->showMessage( ...$error );
743  }
744  }
745 
756  public function label( $msg, $forId, $contents, $helpData = "" ) {
757  if ( strval( $msg ) == '' ) {
758  $labelText = "\u{00A0}";
759  } else {
760  $labelText = wfMessage( $msg )->escaped();
761  }
762 
763  $attributes = [ 'class' => 'config-label' ];
764 
765  if ( $forId ) {
766  $attributes['for'] = $forId;
767  }
768 
769  return "<div class=\"config-block\">\n" .
770  " <div class=\"config-block-label\">\n" .
771  Xml::tags( 'label',
772  $attributes,
773  $labelText
774  ) . "\n" .
775  $helpData .
776  " </div>\n" .
777  " <div class=\"config-block-elements\">\n" .
778  $contents .
779  " </div>\n" .
780  "</div>\n";
781  }
782 
797  public function getTextBox( $params ) {
798  if ( !isset( $params['controlName'] ) ) {
799  $params['controlName'] = 'config_' . $params['var'];
800  }
801 
802  if ( !isset( $params['value'] ) ) {
803  $params['value'] = $this->getVar( $params['var'] );
804  }
805 
806  if ( !isset( $params['attribs'] ) ) {
807  $params['attribs'] = [];
808  }
809  if ( !isset( $params['help'] ) ) {
810  $params['help'] = "";
811  }
812 
813  return $this->label(
814  $params['label'],
815  $params['controlName'],
816  Xml::input(
817  $params['controlName'],
818  30, // intended to be overridden by CSS
819  $params['value'],
820  $params['attribs'] + [
821  'id' => $params['controlName'],
822  'class' => 'config-input-text',
823  'tabindex' => $this->nextTabIndex()
824  ]
825  ),
826  $params['help']
827  );
828  }
829 
844  public function getTextArea( $params ) {
845  if ( !isset( $params['controlName'] ) ) {
846  $params['controlName'] = 'config_' . $params['var'];
847  }
848 
849  if ( !isset( $params['value'] ) ) {
850  $params['value'] = $this->getVar( $params['var'] );
851  }
852 
853  if ( !isset( $params['attribs'] ) ) {
854  $params['attribs'] = [];
855  }
856  if ( !isset( $params['help'] ) ) {
857  $params['help'] = "";
858  }
859 
860  return $this->label(
861  $params['label'],
862  $params['controlName'],
864  $params['controlName'],
865  $params['value'],
866  30,
867  5,
868  $params['attribs'] + [
869  'id' => $params['controlName'],
870  'class' => 'config-input-text',
871  'tabindex' => $this->nextTabIndex()
872  ]
873  ),
874  $params['help']
875  );
876  }
877 
893  public function getPasswordBox( $params ) {
894  if ( !isset( $params['value'] ) ) {
895  $params['value'] = $this->getVar( $params['var'] );
896  }
897 
898  if ( !isset( $params['attribs'] ) ) {
899  $params['attribs'] = [];
900  }
901 
902  $params['value'] = $this->getFakePassword( $params['value'] );
903  $params['attribs']['type'] = 'password';
904 
905  return $this->getTextBox( $params );
906  }
907 
923  public function getCheckBox( $params ) {
924  if ( !isset( $params['controlName'] ) ) {
925  $params['controlName'] = 'config_' . $params['var'];
926  }
927 
928  if ( !isset( $params['value'] ) ) {
929  $params['value'] = $this->getVar( $params['var'] );
930  }
931 
932  if ( !isset( $params['attribs'] ) ) {
933  $params['attribs'] = [];
934  }
935  if ( !isset( $params['help'] ) ) {
936  $params['help'] = "";
937  }
938  if ( !isset( $params['labelAttribs'] ) ) {
939  $params['labelAttribs'] = [];
940  }
941  $labelText = $params['rawtext'] ?? $this->parse( wfMessage( $params['label'] )->plain() );
942 
943  return "<div class=\"config-input-check\">\n" .
944  $params['help'] .
946  'label',
947  $params['labelAttribs'],
948  Xml::check(
949  $params['controlName'],
950  $params['value'],
951  $params['attribs'] + [
952  'id' => $params['controlName'],
953  'tabindex' => $this->nextTabIndex(),
954  ]
955  ) .
956  $labelText . "\n"
957  ) .
958  "</div>\n";
959  }
960 
980  public function getRadioSet( $params ) {
981  $items = $this->getRadioElements( $params );
982 
983  $label = $params['label'] ?? '';
984 
985  if ( !isset( $params['controlName'] ) ) {
986  $params['controlName'] = 'config_' . $params['var'];
987  }
988 
989  if ( !isset( $params['help'] ) ) {
990  $params['help'] = "";
991  }
992 
993  $s = "<ul>\n";
994  foreach ( $items as $value => $item ) {
995  $s .= "<li>$item</li>\n";
996  }
997  $s .= "</ul>\n";
998 
999  return $this->label( $label, $params['controlName'], $s, $params['help'] );
1000  }
1001 
1010  public function getRadioElements( $params ) {
1011  if ( !isset( $params['controlName'] ) ) {
1012  $params['controlName'] = 'config_' . $params['var'];
1013  }
1014 
1015  if ( !isset( $params['value'] ) ) {
1016  $params['value'] = $this->getVar( $params['var'] );
1017  }
1018 
1019  $items = [];
1020 
1021  foreach ( $params['values'] as $value ) {
1022  $itemAttribs = [];
1023 
1024  if ( isset( $params['commonAttribs'] ) ) {
1025  $itemAttribs = $params['commonAttribs'];
1026  }
1027 
1028  if ( isset( $params['itemAttribs'][$value] ) ) {
1029  $itemAttribs = $params['itemAttribs'][$value] + $itemAttribs;
1030  }
1031 
1032  $checked = $value == $params['value'];
1033  $id = $params['controlName'] . '_' . $value;
1034  $itemAttribs['id'] = $id;
1035  $itemAttribs['tabindex'] = $this->nextTabIndex();
1036 
1037  $items[$value] =
1038  Xml::radio( $params['controlName'], $value, $checked, $itemAttribs ) .
1039  "\u{00A0}" .
1040  Xml::tags( 'label', [ 'for' => $id ], $this->parse(
1041  isset( $params['itemLabels'] ) ?
1042  wfMessage( $params['itemLabels'][$value] )->plain() :
1043  wfMessage( $params['itemLabelPrefix'] . strtolower( $value ) )->plain()
1044  ) );
1045  }
1046 
1047  return $items;
1048  }
1049 
1055  public function showStatusBox( $status ) {
1056  if ( !$status->isGood() ) {
1057  $text = $status->getWikiText();
1058 
1059  if ( $status->isOK() ) {
1060  $box = Html::warningBox( $text, 'config-warning-box' );
1061  } else {
1062  $box = Html::errorBox( $text, '', 'config-error-box' );
1063  }
1064 
1065  $this->output->addHTML( $box );
1066  }
1067  }
1068 
1079  public function setVarsFromRequest( $varNames, $prefix = 'config_' ) {
1080  $newValues = [];
1081 
1082  foreach ( $varNames as $name ) {
1083  $value = $this->request->getVal( $prefix . $name );
1084  // T32524, do not trim passwords
1085  if ( stripos( $name, 'password' ) === false ) {
1086  $value = trim( $value );
1087  }
1088  $newValues[$name] = $value;
1089 
1090  if ( $value === null ) {
1091  // Checkbox?
1092  $this->setVar( $name, false );
1093  } elseif ( stripos( $name, 'password' ) !== false ) {
1094  $this->setPassword( $name, $value );
1095  } else {
1096  $this->setVar( $name, $value );
1097  }
1098  }
1099 
1100  return $newValues;
1101  }
1102 
1110  public function getDocUrl( $page ) {
1111  $query = [ 'page' => $page ];
1112 
1113  if ( in_array( $this->currentPageName, $this->pageSequence ) ) {
1114  $query['lastPage'] = $this->currentPageName;
1115  }
1116 
1117  return $this->getUrl( $query );
1118  }
1119 
1128  public function makeLinkItem( $url, $linkText ) {
1129  return Html::rawElement( 'li', [],
1130  Html::element( 'a', [ 'href' => $url ], $linkText )
1131  );
1132  }
1133 
1140  public function makeDownloadLinkHtml() {
1141  $anchor = Html::rawElement( 'a',
1142  [ 'href' => $this->getUrl( [ 'localsettings' => 1 ] ) ],
1143  wfMessage( 'config-download-localsettings' )->parse()
1144  );
1145 
1146  return Html::rawElement( 'div', [ 'class' => 'config-download-link' ], $anchor );
1147  }
1148 
1159  public function getLocalSettingsLocation() {
1160  return false;
1161  }
1162 
1166  public function envCheckPath() {
1167  // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1168  // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1169  // to get the path to the current script... hopefully it's reliable. SIGH
1170  $path = false;
1171  if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1172  $path = $_SERVER['PHP_SELF'];
1173  } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1174  $path = $_SERVER['SCRIPT_NAME'];
1175  }
1176  if ( $path === false ) {
1177  $this->showError( 'config-no-uri' );
1178  return false;
1179  }
1180 
1181  return parent::envCheckPath();
1182  }
1183 
1184  public function envPrepPath() {
1185  parent::envPrepPath();
1186  // PHP_SELF isn't available sometimes, such as when PHP is CGI but
1187  // cgi.fix_pathinfo is disabled. In that case, fall back to SCRIPT_NAME
1188  // to get the path to the current script... hopefully it's reliable. SIGH
1189  $path = false;
1190  if ( !empty( $_SERVER['PHP_SELF'] ) ) {
1191  $path = $_SERVER['PHP_SELF'];
1192  } elseif ( !empty( $_SERVER['SCRIPT_NAME'] ) ) {
1193  $path = $_SERVER['SCRIPT_NAME'];
1194  }
1195  if ( $path !== false ) {
1196  $scriptPath = preg_replace( '{^(.*)/(mw-)?config.*$}', '$1', $path );
1197 
1198  $this->setVar( 'wgScriptPath', "$scriptPath" );
1199  // Update variables set from Setup.php that are derived from wgScriptPath
1200  $this->setVar( 'wgScript', "$scriptPath/index.php" );
1201  $this->setVar( 'wgLoadScript', "$scriptPath/load.php" );
1202  $this->setVar( 'wgStylePath', "$scriptPath/skins" );
1203  $this->setVar( 'wgLocalStylePath', "$scriptPath/skins" );
1204  $this->setVar( 'wgExtensionAssetsPath', "$scriptPath/extensions" );
1205  $this->setVar( 'wgUploadPath', "$scriptPath/images" );
1206  $this->setVar( 'wgResourceBasePath', "$scriptPath" );
1207  }
1208  }
1209 
1213  protected function envGetDefaultServer() {
1214  return WebRequest::detectServer();
1215  }
1216 
1222  private function outputLS() {
1223  $this->request->response()->header( 'Content-type: application/x-httpd-php' );
1224  $this->request->response()->header(
1225  'Content-Disposition: attachment; filename="LocalSettings.php"'
1226  );
1227 
1229  $rightsProfile = $this->rightsProfiles[$this->getVar( '_RightsProfile' )];
1230  foreach ( $rightsProfile as $group => $rightsArr ) {
1231  $ls->setGroupRights( $group, $rightsArr );
1232  }
1233  echo $ls->getText();
1234  }
1235 
1239  public function outputCss() {
1240  $this->request->response()->header( 'Content-type: text/css' );
1241  echo $this->output->getCSS();
1242  }
1243 
1247  public function getPhpErrors() {
1248  return $this->phpErrors;
1249  }
1250 
1251 }
WebInstaller\getAcceptLanguage
getAcceptLanguage()
Retrieves MediaWiki language from Accept-Language HTTP header.
Definition: WebInstaller.php:522
WebInstaller\makeLinkItem
makeLinkItem( $url, $linkText)
Helper for sidebar links.
Definition: WebInstaller.php:1128
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:691
WebInstaller\startPageWrapper
startPageWrapper( $currentPageName)
Called by execute() before page output starts, to show a page list.
Definition: WebInstaller.php:542
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:117
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
WebInstaller\getRadioElements
getRadioElements( $params)
Get a set of labelled radio buttons.
Definition: WebInstaller.php:1010
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:756
WebInstaller\getPageListItem
getPageListItem( $pageName, $enabled, $currentPageName)
Get a list item for the page list.
Definition: WebInstaller.php:586
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:739
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:502
WebInstaller\getCheckBox
getCheckBox( $params)
Get a labelled checkbox to configure a boolean variable.
Definition: WebInstaller.php:923
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:59
WebInstaller\getWarningBox
getWarningBox( $text)
Get HTML for a warning box with an icon.
Definition: WebInstaller.php:665
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:462
Html\warningBox
static warningBox( $html, $className='')
Return a warning box.
Definition: Html.php:726
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:644
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:1055
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:528
WebInstaller\getInfoBox
getInfoBox( $text, $icon=false, $class=false)
Get HTML for an information message box with an icon.
Definition: WebInstaller.php:678
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:980
Installer\getFakePassword
getFakePassword( $realPassword)
Get a fake password for sending back to the user in HTML.
Definition: Installer.php:633
WebInstaller\showHelpBox
showHelpBox( $msg,... $params)
Output a help box.
Definition: WebInstaller.php:717
WebInstaller\getTextArea
getTextArea( $params)
Get a labelled textarea to configure a variable.
Definition: WebInstaller.php:844
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:486
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:495
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:409
Xml\check
static check( $name, $checked=false, $attribs=[])
Convenience function to build an HTML checkbox.
Definition: Xml.php:323
$wgLang
$wgLang
Definition: Setup.php:880
WebInstaller\getFingerprint
getFingerprint()
Get a hash of data identifying this MW installation.
Definition: WebInstaller.php:365
WebInstaller\showError
showError( $msg,... $params)
Show an error message in a box.
Definition: WebInstaller.php:391
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:1222
Installer\getVar
getVar( $name, $default=null)
Get an MW configuration variable, or internal installer configuration variable.
Definition: Installer.php:542
WebInstaller\$phpErrors
string[] $phpErrors
Captured PHP error text.
Definition: WebInstaller.php:58
Html\errorBox
static errorBox( $html, $heading='', $className='')
Return an error box.
Definition: Html.php:739
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:1166
WebInstaller\getPasswordBox
getPasswordBox( $params)
Get a labelled password box to configure a variable.
Definition: WebInstaller.php:893
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:2969
WebInstaller\reset
reset()
We're restarting the installation, reset the session, happyPages, etc.
Definition: WebInstaller.php:431
WebInstaller\setVarsFromRequest
setVarsFromRequest( $varNames, $prefix='config_')
Convenience function to set variables based on form data.
Definition: WebInstaller.php:1079
WebInstaller\outputCss
outputCss()
Output stylesheet for web installer pages.
Definition: WebInstaller.php:1239
RequestContext\getMain
static getMain()
Get the RequestContext object associated with the main request.
Definition: RequestContext.php:431
wfIniGetBool
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
Definition: GlobalFunctions.php:2042
WebInstaller\endPageWrapper
endPageWrapper()
Output some stuff after a page is finished.
Definition: WebInstaller.php:636
WebInstaller\makeDownloadLinkHtml
makeDownloadLinkHtml()
Helper for "Download LocalSettings" link.
Definition: WebInstaller.php:1140
WebInstaller\getLocalSettingsLocation
getLocalSettingsLocation()
If the software package wants the LocalSettings.php file to be placed in a specific location,...
Definition: WebInstaller.php:1159
WebInstaller\getErrorBox
getErrorBox( $text)
Get HTML for an error box with an icon.
Definition: WebInstaller.php:652
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:1184
WebInstaller\envGetDefaultServer
envGetDefaultServer()
Definition: WebInstaller.php:1213
$args
if( $line===false) $args
Definition: cdb.php:64
WebInstaller\getHelpBox
getHelpBox( $msg,... $args)
Get small text indented help for a preceding form field.
Definition: WebInstaller.php:697
WebInstaller\getPhpErrors
getPhpErrors()
Definition: WebInstaller.php:1247
Status\getWarningsArray
getWarningsArray()
Get the list of warnings (but not errors)
Definition: Status.php:354
$path
$path
Definition: NoLocalSettings.php:25
Html\rawElement
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition: Html.php:209
WebInstaller\getDocUrl
getDocUrl( $page)
Helper for WebInstallerOutput.
Definition: WebInstaller.php:1110
WebRequest\detectServer
static detectServer()
Work out an appropriate URL prefix containing scheme and host, based on information detected from $_S...
Definition: WebRequest.php:228
Installer\disableTimeLimit
disableTimeLimit()
Disable the time limit for execution.
Definition: Installer.php:1847
Message
The Message class provides methods which fulfil two basic services:
Definition: Message.php:162
WebInstaller\getTextBox
getTextBox( $params)
Get a labelled text box to configure a variable.
Definition: WebInstaller.php:797
Installer
Base installer class.
Definition: Installer.php:46
Language\factory
static factory( $code)
Get a cached or new language object for a given language code.
Definition: Language.php:217
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:751
Html\element
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:231
Language\fetchLanguageNames
static fetchLanguageNames( $inLanguage=self::AS_AUTONYMS, $include='mw')
Get an array of language names, indexed by code.
Definition: Language.php:818
Status\getErrorsArray
getErrorsArray()
Get the list of errors (but not warnings)
Definition: Status.php:343
WebInstaller\getSession
getSession( $name, $default=null)
Get a session variable.
Definition: WebInstaller.php:476
$wgContLang
$wgContLang
Definition: Setup.php:800
WebInstaller\finish
finish()
Clean up from execute()
Definition: WebInstaller.php:418
WebInstaller\showMessage
showMessage( $msg,... $params)
Show a short informational message.
Definition: WebInstaller.php:729
Html\infoBox
static infoBox( $rawHtml, $icon, $alt, $class='')
Get HTML for an information message box with an icon.
Definition: Html.php:1021
$GLOBALS
$GLOBALS['IP']
Definition: ComposerHookHandler.php:6
WebInstaller\getUrl
getUrl( $query=[])
Get a URL for submission back to the same script.
Definition: WebInstaller.php:444
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