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