MediaWiki  1.27.1
Setup.php
Go to the documentation of this file.
1 <?php
31 if ( !defined( 'MEDIAWIKI' ) ) {
32  exit( 1 );
33 }
34 
35 $fname = 'Setup.php';
36 $ps_setup = Profiler::instance()->scopedProfileIn( $fname );
37 
38 // If any extensions are still queued, force load them
39 ExtensionRegistry::getInstance()->loadFromQueue();
40 
41 // Check to see if we are at the file scope
42 if ( !isset( $wgVersion ) ) {
43  echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
44  die( 1 );
45 }
46 
47 mb_internal_encoding( 'UTF-8' );
48 
49 // Set various default paths sensibly...
50 $ps_default = Profiler::instance()->scopedProfileIn( $fname . '-defaults' );
51 
52 if ( $wgScript === false ) {
53  $wgScript = "$wgScriptPath/index.php";
54 }
55 if ( $wgLoadScript === false ) {
56  $wgLoadScript = "$wgScriptPath/load.php";
57 }
58 
59 if ( $wgArticlePath === false ) {
60  if ( $wgUsePathInfo ) {
61  $wgArticlePath = "$wgScript/$1";
62  } else {
63  $wgArticlePath = "$wgScript?title=$1";
64  }
65 }
66 
67 if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
68  // 'view' is assumed the default action path everywhere in the code
69  // but is rarely filled in $wgActionPaths
71 }
72 
73 if ( $wgResourceBasePath === null ) {
75 }
76 if ( $wgStylePath === false ) {
77  $wgStylePath = "$wgResourceBasePath/skins";
78 }
79 if ( $wgLocalStylePath === false ) {
80  // Avoid wgResourceBasePath here since that may point to a different domain (e.g. CDN)
81  $wgLocalStylePath = "$wgScriptPath/skins";
82 }
83 if ( $wgExtensionAssetsPath === false ) {
84  $wgExtensionAssetsPath = "$wgResourceBasePath/extensions";
85 }
86 
87 if ( $wgLogo === false ) {
88  $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
89 }
90 
91 if ( $wgUploadPath === false ) {
92  $wgUploadPath = "$wgScriptPath/images";
93 }
94 if ( $wgUploadDirectory === false ) {
95  $wgUploadDirectory = "$IP/images";
96 }
97 if ( $wgReadOnlyFile === false ) {
98  $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
99 }
100 if ( $wgFileCacheDirectory === false ) {
101  $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
102 }
103 if ( $wgDeletedDirectory === false ) {
104  $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
105 }
106 
107 if ( $wgGitInfoCacheDirectory === false && $wgCacheDirectory !== false ) {
108  $wgGitInfoCacheDirectory = "{$wgCacheDirectory}/gitinfo";
109 }
110 
111 if ( $wgEnableParserCache === false ) {
113 }
114 
115 // Fix path to icon images after they were moved in 1.24
116 if ( $wgRightsIcon ) {
117  $wgRightsIcon = str_replace(
118  "{$wgStylePath}/common/images/",
119  "{$wgResourceBasePath}/resources/assets/licenses/",
120  $wgRightsIcon
121  );
122 }
123 
124 if ( isset( $wgFooterIcons['copyright']['copyright'] )
125  && $wgFooterIcons['copyright']['copyright'] === []
126 ) {
127  if ( $wgRightsIcon || $wgRightsText ) {
128  $wgFooterIcons['copyright']['copyright'] = [
129  'url' => $wgRightsUrl,
130  'src' => $wgRightsIcon,
131  'alt' => $wgRightsText,
132  ];
133  }
134 }
135 
136 if ( isset( $wgFooterIcons['poweredby'] )
137  && isset( $wgFooterIcons['poweredby']['mediawiki'] )
138  && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
139 ) {
140  $wgFooterIcons['poweredby']['mediawiki']['src'] =
141  "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png";
142  $wgFooterIcons['poweredby']['mediawiki']['srcset'] =
143  "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png 1.5x, " .
144  "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png 2x";
145 }
146 
155 
163 
168  'name' => 'fsLockManager',
169  'class' => 'FSLockManager',
170  'lockDirectory' => "{$wgUploadDirectory}/lockdir",
171 ];
172 $wgLockManagers[] = [
173  'name' => 'nullLockManager',
174  'class' => 'NullLockManager',
175 ];
176 
180 if ( !$wgLocalFileRepo ) {
181  $wgLocalFileRepo = [
182  'class' => 'LocalRepo',
183  'name' => 'local',
184  'directory' => $wgUploadDirectory,
185  'scriptDirUrl' => $wgScriptPath,
186  'scriptExtension' => '.php',
188  'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
189  'thumbScriptUrl' => $wgThumbnailScriptPath,
190  'transformVia404' => !$wgGenerateThumbnailOnParse,
191  'deletedDir' => $wgDeletedDirectory,
192  'deletedHashLevels' => $wgHashedUploadDirectory ? 3 : 0
193  ];
194 }
198 if ( $wgUseSharedUploads ) {
199  if ( $wgSharedUploadDBname ) {
200  $wgForeignFileRepos[] = [
201  'class' => 'ForeignDBRepo',
202  'name' => 'shared',
203  'directory' => $wgSharedUploadDirectory,
204  'url' => $wgSharedUploadPath,
205  'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
206  'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
207  'transformVia404' => !$wgGenerateThumbnailOnParse,
208  'dbType' => $wgDBtype,
209  'dbServer' => $wgDBserver,
210  'dbUser' => $wgDBuser,
211  'dbPassword' => $wgDBpassword,
212  'dbName' => $wgSharedUploadDBname,
213  'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
214  'tablePrefix' => $wgSharedUploadDBprefix,
215  'hasSharedCache' => $wgCacheSharedUploads,
216  'descBaseUrl' => $wgRepositoryBaseUrl,
217  'fetchDescription' => $wgFetchCommonsDescriptions,
218  ];
219  } else {
220  $wgForeignFileRepos[] = [
221  'class' => 'FileRepo',
222  'name' => 'shared',
223  'directory' => $wgSharedUploadDirectory,
224  'url' => $wgSharedUploadPath,
225  'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
226  'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
227  'transformVia404' => !$wgGenerateThumbnailOnParse,
228  'descBaseUrl' => $wgRepositoryBaseUrl,
229  'fetchDescription' => $wgFetchCommonsDescriptions,
230  ];
231  }
232 }
233 if ( $wgUseInstantCommons ) {
234  $wgForeignFileRepos[] = [
235  'class' => 'ForeignAPIRepo',
236  'name' => 'wikimediacommons',
237  'apibase' => 'https://commons.wikimedia.org/w/api.php',
238  'url' => 'https://upload.wikimedia.org/wikipedia/commons',
239  'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
240  'hashLevels' => 2,
241  'transformVia404' => true,
242  'fetchDescription' => true,
243  'descriptionCacheExpiry' => 43200,
244  'apiThumbCacheExpiry' => 86400,
245  ];
246 }
247 /*
248  * Add on default file backend config for file repos.
249  * FileBackendGroup will handle initializing the backends.
250  */
251 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
252  $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
253 }
254 foreach ( $wgForeignFileRepos as &$repo ) {
255  if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
256  $repo['directory'] = $wgUploadDirectory; // b/c
257  }
258  if ( !isset( $repo['backend'] ) ) {
259  $repo['backend'] = $repo['name'] . '-backend';
260  }
261 }
262 unset( $repo ); // no global pollution; destroy reference
263 
264 $rcMaxAgeDays = $wgRCMaxAge / ( 3600 * 24 );
265 if ( $wgRCFilterByAge ) {
266  // Trim down $wgRCLinkDays so that it only lists links which are valid
267  // as determined by $wgRCMaxAge.
268  // Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
269  sort( $wgRCLinkDays );
270 
271  // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
272  for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
273  // @codingStandardsIgnoreEnd
274  if ( $wgRCLinkDays[$i] >= $rcMaxAgeDays ) {
275  $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
276  break;
277  }
278  }
279 }
280 // Ensure that default user options are not invalid, since that breaks Special:Preferences
281 $wgDefaultUserOptions['rcdays'] = min(
282  $wgDefaultUserOptions['rcdays'],
283  ceil( $rcMaxAgeDays )
284 );
285 $wgDefaultUserOptions['watchlistdays'] = min(
286  $wgDefaultUserOptions['watchlistdays'],
287  ceil( $rcMaxAgeDays )
288 );
289 unset( $rcMaxAgeDays );
290 
291 if ( $wgSkipSkin ) {
293 }
294 
295 // Register skins
296 // Use a closure to avoid leaking into global state
297 call_user_func( function () use ( $wgValidSkinNames ) {
299  foreach ( $wgValidSkinNames as $name => $skin ) {
300  $factory->register( $name, $skin, function () use ( $name, $skin ) {
301  $class = "Skin$skin";
302  return new $class( $name );
303  } );
304  }
305  // Register a hidden "fallback" skin
306  $factory->register( 'fallback', 'Fallback', function () {
307  return new SkinFallback;
308  } );
309  // Register a hidden skin for api output
310  $factory->register( 'apioutput', 'ApiOutput', function () {
311  return new SkinApi;
312  } );
313 } );
314 $wgSkipSkins[] = 'fallback';
315 $wgSkipSkins[] = 'apioutput';
316 
317 if ( $wgLocalInterwiki ) {
318  array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
319 }
320 
321 // Set default shared prefix
322 if ( $wgSharedPrefix === false ) {
324 }
325 
326 // Set default shared schema
327 if ( $wgSharedSchema === false ) {
329 }
330 
331 if ( !$wgCookiePrefix ) {
332  if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
334  } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
336  } elseif ( $wgDBprefix ) {
338  } else {
340  }
341 }
342 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
343 
344 if ( $wgEnableEmail ) {
346 } else {
347  // Disable all other email settings automatically if $wgEnableEmail
348  // is set to false. - bug 63678
349  $wgAllowHTMLEmail = false;
350  $wgEmailAuthentication = false; // do not require auth if you're not sending email anyway
360  unset( $wgGroupPermissions['user']['sendemail'] );
361  $wgUseEnotif = false;
364 }
365 
366 if ( $wgMetaNamespace === false ) {
367  $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
368 }
369 
370 // Default value is 2000 or the suhosin limit if it is between 1 and 2000
371 if ( $wgResourceLoaderMaxQueryLength === false ) {
372  $suhosinMaxValueLength = (int)ini_get( 'suhosin.get.max_value_length' );
373  if ( $suhosinMaxValueLength > 0 && $suhosinMaxValueLength < 2000 ) {
374  $wgResourceLoaderMaxQueryLength = $suhosinMaxValueLength;
375  } else {
377  }
378  unset( $suhosinMaxValueLength );
379 }
380 
381 // Ensure the minimum chunk size is less than PHP upload limits or the maximum
382 // upload size.
388  ini_get( 'post_max_size' ) ?: ini_get( 'hhvm.server.max_post_size' ),
389  PHP_INT_MAX
390  ) ?: PHP_INT_MAX ) - 1024 // Leave some room for other POST parameters
391 );
392 
398  NS_MEDIA => 'Media',
399  NS_SPECIAL => 'Special',
400  NS_TALK => 'Talk',
401  NS_USER => 'User',
402  NS_USER_TALK => 'User_talk',
403  NS_PROJECT => 'Project',
404  NS_PROJECT_TALK => 'Project_talk',
405  NS_FILE => 'File',
406  NS_FILE_TALK => 'File_talk',
407  NS_MEDIAWIKI => 'MediaWiki',
408  NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
409  NS_TEMPLATE => 'Template',
410  NS_TEMPLATE_TALK => 'Template_talk',
411  NS_HELP => 'Help',
412  NS_HELP_TALK => 'Help_talk',
413  NS_CATEGORY => 'Category',
414  NS_CATEGORY_TALK => 'Category_talk',
415 ];
416 
418 if ( is_array( $wgExtraNamespaces ) ) {
420 }
421 
422 // These are now the same, always
423 // To determine the user language, use $wgLang->getCode()
425 
426 // Easy to forget to falsify $wgDebugToolbar for static caches.
427 // If file cache or CDN cache is on, just disable this (DWIMD).
428 if ( $wgUseFileCache || $wgUseSquid ) {
429  $wgDebugToolbar = false;
430 }
431 
432 // We always output HTML5 since 1.22, overriding these is no longer supported
433 // we set them here for extensions that depend on its value.
434 $wgHtml5 = true;
435 $wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
436 $wgJsMimeType = 'text/javascript';
437 
438 // Blacklisted file extensions shouldn't appear on the "allowed" list
439 $wgFileExtensions = array_values( array_diff( $wgFileExtensions, $wgFileBlacklist ) );
440 
442  MediaWiki\suppressWarnings();
443  $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', filemtime( "$IP/LocalSettings.php" ) ) );
444  MediaWiki\restoreWarnings();
445 }
446 
447 if ( $wgNewUserLog ) {
448  // Add a new log type
449  $wgLogTypes[] = 'newusers';
450  $wgLogNames['newusers'] = 'newuserlogpage';
451  $wgLogHeaders['newusers'] = 'newuserlogpagetext';
452  $wgLogActionsHandlers['newusers/newusers'] = 'NewUsersLogFormatter';
453  $wgLogActionsHandlers['newusers/create'] = 'NewUsersLogFormatter';
454  $wgLogActionsHandlers['newusers/create2'] = 'NewUsersLogFormatter';
455  $wgLogActionsHandlers['newusers/byemail'] = 'NewUsersLogFormatter';
456  $wgLogActionsHandlers['newusers/autocreate'] = 'NewUsersLogFormatter';
457 }
458 
459 if ( $wgPageLanguageUseDB ) {
460  $wgLogTypes[] = 'pagelang';
461  $wgLogActionsHandlers['pagelang/pagelang'] = 'PageLangLogFormatter';
462 }
463 
464 if ( $wgCookieSecure === 'detect' ) {
465  $wgCookieSecure = ( WebRequest::detectProtocol() === 'https' );
466 }
467 
468 if ( $wgProfileOnly ) {
469  $wgDebugLogGroups['profileoutput'] = $wgDebugLogFile;
470  $wgDebugLogFile = '';
471 }
472 
473 // Backwards compatibility with old password limits
474 if ( $wgMinimalPasswordLength !== false ) {
475  $wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = $wgMinimalPasswordLength;
476 }
477 
478 if ( $wgMaximalPasswordLength !== false ) {
479  $wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] = $wgMaximalPasswordLength;
480 }
481 
482 // Backwards compatibility warning
484  wfDeprecated( '$wgSessionsInObjectCache = false', '1.27' );
485  if ( $wgSessionHandler ) {
486  wfDeprecated( '$wgSessionsHandler', '1.27' );
487  }
488  $cacheType = get_class( ObjectCache::getInstance( $wgSessionCacheType ) );
489  wfDebugLog(
490  'caches',
491  "Session data will be stored in \"$cacheType\" cache with " .
492  "expiry $wgObjectCacheSessionExpiry seconds"
493  );
494 }
496 
497 if ( $wgPHPSessionHandling !== 'enable' &&
498  $wgPHPSessionHandling !== 'warn' &&
499  $wgPHPSessionHandling !== 'disable'
500 ) {
501  $wgPHPSessionHandling = 'warn';
502 }
503 if ( defined( 'MW_NO_SESSION' ) ) {
504  // If the entry point wants no session, force 'disable' here unless they
505  // specifically set it to the (undocumented) 'warn'.
506  $wgPHPSessionHandling = MW_NO_SESSION === 'warn' ? 'warn' : 'disable';
507 }
508 
509 Profiler::instance()->scopedProfileOut( $ps_default );
510 
511 // Disable MWDebug for command line mode, this prevents MWDebug from eating up
512 // all the memory from logging SQL queries on maintenance scripts
514 if ( $wgDebugToolbar && !$wgCommandLineMode ) {
515  MWDebug::init();
516 }
517 
518 if ( !class_exists( 'AutoLoader' ) ) {
519  require_once "$IP/includes/AutoLoader.php";
520 }
521 
522 // Install a header callback to prevent caching of responses with cookies (T127993)
523 if ( !$wgCommandLineMode ) {
524  header_register_callback( function () {
525  $headers = [];
526  foreach ( headers_list() as $header ) {
527  list( $name, $value ) = explode( ':', $header, 2 );
528  $headers[strtolower( trim( $name ) )][] = trim( $value );
529  }
530 
531  if ( isset( $headers['set-cookie'] ) ) {
532  $cacheControl = isset( $headers['cache-control'] )
533  ? implode( ', ', $headers['cache-control'] )
534  : '';
535 
536  if ( !preg_match( '/(?:^|,)\s*(?:private|no-cache|no-store)\s*(?:$|,)/i', $cacheControl ) ) {
537  header( 'Expires: Thu, 01 Jan 1970 00:00:00 GMT' );
538  header( 'Cache-Control: private, max-age=0, s-maxage=0' );
539  MediaWiki\Logger\LoggerFactory::getInstance( 'cache-cookies' )->warning(
540  'Cookies set on {url} with Cache-Control "{cache-control}"', [
542  'cookies' => $headers['set-cookie'],
543  'cache-control' => $cacheControl ?: '<not set>',
544  ]
545  );
546  }
547  }
548  } );
549 }
550 
552 
553 require_once "$IP/includes/compat/normal/UtfNormalUtil.php";
554 
555 $ps_validation = Profiler::instance()->scopedProfileIn( $fname . '-validation' );
556 
557 // T48998: Bail out early if $wgArticlePath is non-absolute
558 foreach ( [ 'wgArticlePath', 'wgVariantArticlePath' ] as $varName ) {
559  if ( $$varName && !preg_match( '/^(https?:\/\/|\/)/', $$varName ) ) {
560  throw new FatalError(
561  "If you use a relative URL for \$$varName, it must start " .
562  'with a slash (<code>/</code>).<br><br>See ' .
563  "<a href=\"https://www.mediawiki.org/wiki/Manual:\$$varName\">" .
564  "https://www.mediawiki.org/wiki/Manual:\$$varName</a>."
565  );
566  }
567 }
568 
569 Profiler::instance()->scopedProfileOut( $ps_validation );
570 
571 $ps_default2 = Profiler::instance()->scopedProfileIn( $fname . '-defaults2' );
572 
573 if ( $wgCanonicalServer === false ) {
575 }
576 
577 // Set server name
579 if ( $wgServerName !== false ) {
580  wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
581  . 'not customized. Overwriting $wgServerName.' );
582 }
584 unset( $serverParts );
585 
586 // Set defaults for configuration variables
587 // that are derived from the server name by default
588 // Note: $wgEmergencyContact and $wgPasswordSender may be false or empty string (T104142)
589 if ( !$wgEmergencyContact ) {
590  $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
591 }
592 if ( !$wgPasswordSender ) {
593  $wgPasswordSender = 'apache@' . $wgServerName;
594 }
595 if ( !$wgNoReplyAddress ) {
597 }
598 
599 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
600  $wgSecureLogin = false;
601  wfWarn( 'Secure login was enabled on a server that only supports '
602  . 'HTTP or HTTPS. Disabling secure login.' );
603 }
604 
606 
607 // Now that GlobalFunctions is loaded, set defaults that depend on it.
608 if ( $wgTmpDirectory === false ) {
610 }
611 
612 // We don't use counters anymore. Left here for extensions still
613 // expecting this to exist. Should be removed sometime 1.26 or later.
614 if ( !isset( $wgDisableCounters ) ) {
615  $wgDisableCounters = true;
616 }
617 
618 if ( $wgMainWANCache === false ) {
619  // Setup a WAN cache from $wgMainCacheType with no relayer.
620  // Sites using multiple datacenters can configure a relayer.
621  $wgMainWANCache = 'mediawiki-main-default';
623  'class' => 'WANObjectCache',
624  'cacheId' => $wgMainCacheType,
625  'channels' => [ 'purge' => 'wancache-main-default-purge' ]
626  ];
627 }
628 
629 Profiler::instance()->scopedProfileOut( $ps_default2 );
630 
631 $ps_misc = Profiler::instance()->scopedProfileIn( $fname . '-misc1' );
632 
633 // Raise the memory limit if it's too low
634 wfMemoryLimit();
635 
641 if ( is_null( $wgLocaltimezone ) ) {
642  MediaWiki\suppressWarnings();
643  $wgLocaltimezone = date_default_timezone_get();
644  MediaWiki\restoreWarnings();
645 }
646 
647 date_default_timezone_set( $wgLocaltimezone );
648 if ( is_null( $wgLocalTZoffset ) ) {
649  $wgLocalTZoffset = date( 'Z' ) / 60;
650 }
651 
652 if ( !$wgDBerrorLogTZ ) {
654 }
655 
656 // initialize the request object in $wgRequest
657 $wgRequest = RequestContext::getMain()->getRequest(); // BackCompat
658 
659 // Useful debug output
660 if ( $wgCommandLineMode ) {
661  wfDebug( "\n\nStart command line script $self\n" );
662 } else {
663  $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
664 
665  if ( $wgDebugPrintHttpHeaders ) {
666  $debug .= "HTTP HEADERS:\n";
667 
668  foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
669  $debug .= "$name: $value\n";
670  }
671  }
672  wfDebug( $debug );
673 }
674 
675 Profiler::instance()->scopedProfileOut( $ps_misc );
676 $ps_memcached = Profiler::instance()->scopedProfileIn( $fname . '-memcached' );
677 
681 
682 wfDebugLog( 'caches',
683  'cluster: ' . get_class( $wgMemc ) .
684  ', WAN: ' . $wgMainWANCache .
685  ', stash: ' . $wgMainStash .
686  ', message: ' . get_class( $messageMemc ) .
687  ', parser: ' . get_class( $parserMemc ) .
688  ', session: ' . get_class( ObjectCache::getInstance( $wgSessionCacheType ) )
689 );
690 
691 Profiler::instance()->scopedProfileOut( $ps_memcached );
692 
693 // Most of the config is out, some might want to run hooks here.
694 Hooks::run( 'SetupAfterCache' );
695 
696 $ps_globals = Profiler::instance()->scopedProfileIn( $fname . '-globals' );
697 
702 $wgContLang->initEncoding();
703 $wgContLang->initContLang();
704 
705 // Now that variant lists may be available...
706 $wgRequest->interpolateTitle();
707 
708 if ( !is_object( $wgAuth ) ) {
710  Hooks::run( 'AuthPluginSetup', [ &$wgAuth ] );
711 }
712 if ( $wgAuth && !$wgAuth instanceof MediaWiki\Auth\AuthManagerAuthPlugin ) {
713  MediaWiki\Auth\AuthManager::singleton()->forcePrimaryAuthenticationProviders( [
714  new MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider( [
715  'authoritative' => false,
716  ] ),
717  new MediaWiki\Auth\AuthPluginPrimaryAuthenticationProvider( $wgAuth ),
718  new MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider( [
719  'authoritative' => true,
720  ] ),
721  ], '$wgAuth is ' . get_class( $wgAuth ) );
722 }
723 
724 // Set up the session
725 $ps_session = Profiler::instance()->scopedProfileIn( $fname . '-session' );
731 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
732  // If session.auto_start is there, we can't touch session name
733  if ( $wgPHPSessionHandling !== 'disable' && !wfIniGetBool( 'session.auto_start' ) ) {
734  session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
735  }
736 
737  // Create the SessionManager singleton and set up our session handler,
738  // unless we're specifically asked not to.
739  if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
741  MediaWiki\Session\SessionManager::singleton()
742  );
743  }
744 
745  // Initialize the session
746  try {
748  } catch ( OverflowException $ex ) {
749  if ( isset( $ex->sessionInfos ) && count( $ex->sessionInfos ) >= 2 ) {
750  // The exception is because the request had multiple possible
751  // sessions tied for top priority. Report this to the user.
752  $list = [];
753  foreach ( $ex->sessionInfos as $info ) {
754  $list[] = $info->getProvider()->describe( $wgContLang );
755  }
756  $list = $wgContLang->listToText( $list );
757  throw new HttpError( 400,
758  Message::newFromKey( 'sessionmanager-tie', $list )->inLanguage( $wgContLang )->plain()
759  );
760  }
761 
762  // Not the one we want, rethrow
763  throw $ex;
764  }
765 
766  if ( $session->isPersistent() ) {
767  $wgInitialSessionId = $session->getSessionId();
768  }
769 
770  $session->renew();
771  if ( MediaWiki\Session\PHPSessionHandler::isEnabled() &&
772  ( $session->isPersistent() || $session->shouldRememberUser() )
773  ) {
774  // Start the PHP-session for backwards compatibility
775  session_id( $session->getId() );
776  MediaWiki\quietCall( 'session_start' );
777  }
778 
779  unset( $session );
780 } else {
781  // Even if we didn't set up a global Session, still install our session
782  // handler unless specifically requested not to.
783  if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
785  MediaWiki\Session\SessionManager::singleton()
786  );
787  }
788 }
789 Profiler::instance()->scopedProfileOut( $ps_session );
790 
794 $wgUser = RequestContext::getMain()->getUser(); // BackCompat
795 
800 
804 $wgOut = RequestContext::getMain()->getOutput(); // BackCompat
805 
809 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] );
810 
814 $wgTitle = null;
815 
816 Profiler::instance()->scopedProfileOut( $ps_globals );
817 $ps_extensions = Profiler::instance()->scopedProfileIn( $fname . '-extensions' );
818 
819 // Extension setup functions
820 // Entries should be added to this variable during the inclusion
821 // of the extension file. This allows the extension to perform
822 // any necessary initialisation in the fully initialised environment
823 foreach ( $wgExtensionFunctions as $func ) {
824  // Allow closures in PHP 5.3+
825  if ( is_object( $func ) && $func instanceof Closure ) {
826  $profName = $fname . '-extensions-closure';
827  } elseif ( is_array( $func ) ) {
828  if ( is_object( $func[0] ) ) {
829  $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
830  } else {
831  $profName = $fname . '-extensions-' . implode( '::', $func );
832  }
833  } else {
834  $profName = $fname . '-extensions-' . strval( $func );
835  }
836 
837  $ps_ext_func = Profiler::instance()->scopedProfileIn( $profName );
838  call_user_func( $func );
839  Profiler::instance()->scopedProfileOut( $ps_ext_func );
840 }
841 
842 // If the session user has a 0 id but a valid name, that means we need to
843 // autocreate it.
844 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
845  $sessionUser = MediaWiki\Session\SessionManager::getGlobalSession()->getUser();
846  if ( $sessionUser->getId() === 0 && User::isValidUserName( $sessionUser->getName() ) ) {
847  $ps_autocreate = Profiler::instance()->scopedProfileIn( $fname . '-autocreate' );
848  $res = MediaWiki\Auth\AuthManager::singleton()->autoCreateUser(
849  $sessionUser,
850  MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_SESSION,
851  true
852  );
853  Profiler::instance()->scopedProfileOut( $ps_autocreate );
854  \MediaWiki\Logger\LoggerFactory::getInstance( 'authmanager' )->info( 'Autocreation attempt', [
855  'event' => 'autocreate',
856  'status' => $res,
857  ] );
858  unset( $res );
859  }
860  unset( $sessionUser );
861 }
862 
863 wfDebug( "Fully initialised\n" );
865 
866 Profiler::instance()->scopedProfileOut( $ps_extensions );
867 Profiler::instance()->scopedProfileOut( $ps_setup );
$wgInitialSessionId
Definition: Setup.php:730
$wgForeignFileRepos
$wgUseInstantCommons
Use Commons as a remote file repository.
$wgFooterIcons
Abstract list of footer icons for skins in place of old copyrightico and poweredbyico code You can ad...
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
$wgMainStash
Main object stash type.
$wgHashedSharedUploadDirectory
Set the following to false especially if you have a set of files that need to be accessible by all wi...
$wgCanonicalNamespaceNames
Definitions of the NS_ constants are in Defines.php.
Definition: Setup.php:397
$wgEnotifWatchlist
Definition: Setup.php:359
$wgScript
The URL path to index.php.
$wgDBerrorLogTZ
Timezone to use in the error log.
$wgVersion
MediaWiki version number.
$wgSitename
Name of the site.
$wgUserEmailUseReplyTo
Definition: Setup.php:362
$ps_misc
Definition: Setup.php:631
$wgUsersNotifiedOnAllChanges
Definition: Setup.php:363
$wgLang
Definition: Setup.php:799
SkinTemplate class for API output.
Definition: SkinApi.php:33
$ps_memcached
Definition: Setup.php:676
wfShorthandToInteger($string= '', $default=-1)
Converts shorthand byte notation to integer form.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$wgEnotifFromEditor
Definition: Setup.php:352
if($wgMetaNamespace===false) if($wgResourceLoaderMaxQueryLength===false) $wgMinUploadChunkSize
Definition: Setup.php:383
$wgParser
Definition: Setup.php:809
static instance()
Singleton.
Definition: Profiler.php:60
$wgDBpassword
Database user's password.
$wgSharedUploadDBname
DB name with metadata about shared directory.
$wgActionPaths
Definition: img_auth.php:46
$wgThumbnailScriptPath
Give a path here to use thumb.php for thumbnail generation on client request, instead of generating t...
$wgRepositoryBaseUrl
Base URL for a repository wiki.
$wgDBtype
Database type.
static getInstance($channel)
Get a named logger instance from the currently configured logger factory.
$wgFileExtensions
Definition: Setup.php:439
static getInstance($id)
Get a cached instance of the specified type of cache object.
Definition: ObjectCache.php:92
$wgLocalFileRepo
File repository structures.
$wgDBmwschema
Mediawiki schema.
$value
$wgMetaNamespace
Name of the project namespace.
$wgSharedTables
$wgDBserver
Database host name or IP address.
if($wgUseFileCache||$wgUseSquid) $wgHtml5
Definition: Setup.php:434
$wgDBuser
Database username.
if(!is_object($wgAuth)) if($wgAuth &&!$wgAuth instanceof MediaWiki\Auth\AuthManagerAuthPlugin) $ps_session
Definition: Setup.php:725
$wgMainWANCache
Main Wide-Area-Network cache type.
$wgSharedUploadDirectory
Path on the file system where shared uploads can be found.
const DBO_DEBUG
Definition: Defines.php:30
A helper class for throttling authentication attempts.
$wgTmpDirectory
The local filesystem path to a temporary directory.
$wgEnableUserEmail
Definition: Setup.php:351
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
wfExpandUrl($url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
$wgArticlePath
Definition: img_auth.php:45
$wgWANObjectCaches
Advanced WAN object cache configuration.
const NS_TEMPLATE
Definition: Defines.php:79
$wgMemc
Definition: Setup.php:678
wfGetMessageCacheStorage()
Get the cache object used by the message cache.
$wgGenerateThumbnailOnParse
Allow thumbnail rendering on page view.
$wgEnableEmail
Set to true to enable the e-mail basic features: Password reminders, etc.
const MW_NO_SESSION
Definition: load.php:30
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfGetParserCacheStorage()
Get the cache object used by the parser cache.
static getMaxUploadSize($forType=null)
Get the MediaWiki maximum uploaded file size for given type of upload, based on $wgMaxUploadSize.
$wgCacheDirectory
Directory for caching data in the local filesystem.
$wgInvalidateCacheOnLocalSettingsChange
Invalidate various caches when LocalSettings.php changes.
$wgUseSquid
Enable/disable CDN.
NS_SPECIAL
Definition: Setup.php:399
$factory
Show an error that looks like an HTTP server error.
Definition: HttpError.php:30
static isValidUserName($name)
Is the input a valid username?
Definition: User.php:846
if(is_array($wgExtraNamespaces)) $wgContLanguageCode
Definition: Setup.php:424
$wgLanguageCode
Site language code.
wfDebugLog($logGroup, $text, $dest= 'all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
global $wgCommandLineMode
Definition: Setup.php:513
if($wgScript===false) if($wgLoadScript===false) if($wgArticlePath===false) if(!empty($wgActionPaths)&&!isset($wgActionPaths['view'])) if($wgResourceBasePath===null) if($wgStylePath===false) if($wgLocalStylePath===false) if($wgExtensionAssetsPath===false) if($wgLogo===false) if($wgUploadPath===false) if($wgUploadDirectory===false) if($wgReadOnlyFile===false) if($wgFileCacheDirectory===false) if($wgDeletedDirectory===false) if($wgGitInfoCacheDirectory===false &&$wgCacheDirectory!==false) if($wgEnableParserCache===false) if($wgRightsIcon) if(isset($wgFooterIcons['copyright']['copyright'])&&$wgFooterIcons['copyright']['copyright']===[]) if(isset($wgFooterIcons['poweredby'])&&isset($wgFooterIcons['poweredby']['mediawiki'])&&$wgFooterIcons['poweredby']['mediawiki']['src']===null) $wgNamespaceProtection[NS_MEDIAWIKI]
Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a sysadmin to set $wgName...
Definition: Setup.php:154
$rcMaxAgeDays
Definition: Setup.php:264
$wgStylePath
The URL path of the skins directory.
const NS_PROJECT
Definition: Defines.php:73
Backwards-compatibility wrapper for AuthManager via $wgAuth.
$wgParserCacheType
The cache type for storing article HTML.
wfTempDir()
Tries to get the system directory for temporary files.
static getMain()
Static methods.
$wgUseFileCache
This will cache static pages for non-logged-in users to reduce database traffic on public sites...
$wgDeletedDirectory
What directory to place deleted uploads in.
$wgEnotifMaxRecips
Definition: Setup.php:354
static install(SessionManager $manager)
Install a session handler for the current web request.
wfWarn($msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfIniGetBool($setting)
Safety wrapper around ini_get() for boolean settings.
const NS_MEDIAWIKI_TALK
Definition: Defines.php:78
$wgEnotifUseRealName
Definition: Setup.php:357
$wgLocalInterwikis
Array for multiple $wgLocalInterwiki values, in case there are several interwiki prefixes that point ...
$wgSharedUploadPath
Full path on the web server where shared uploads can be found.
$ps_default
Definition: Setup.php:50
const NS_PROJECT_TALK
Definition: Defines.php:74
static singleton()
Get the global AuthManager.
const NS_MEDIA
Definition: Defines.php:57
$res
Definition: database.txt:21
$wgFullyInitialised
Definition: Setup.php:864
$ps_validation
Definition: Setup.php:555
$parserMemc
Definition: Setup.php:680
$wgEnotifRevealEditorAddress
Definition: Setup.php:356
$wgEnotifUserTalk
Definition: Setup.php:358
$wgUsePathInfo
Whether to support URLs like index.php/Page_title These often break when PHP is set up in CGI mode...
const NS_CATEGORY
Definition: Defines.php:83
$wgResourceBasePath
The default 'remoteBasePath' value for instances of ResourceLoaderFileModule.
CACHE_MEMCACHED $wgMainCacheType
Definition: memcached.txt:63
wfDeprecated($function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
$ps_default2
Definition: Setup.php:571
$wgEnotifMinorEdits
Definition: Setup.php:355
$wgSharedDB
Shared database for multiple wikis.
$wgEnableParserCache
Kept for extension compatibility; see $wgParserCacheType.
$wgTitle
Definition: Setup.php:814
Class to implement stub globals, which are globals that delay loading the their associated module cod...
Definition: StubObject.php:44
$messageMemc
Definition: Setup.php:679
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
const NS_FILE
Definition: Defines.php:75
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned $skin
Definition: hooks.txt:1798
const NS_FILE_TALK
Definition: Defines.php:76
static detectProtocol()
Detect the protocol from $_SERVER.
Definition: WebRequest.php:236
$wgLocaltimezone
Fake out the timezone that the server thinks it's in.
$wgLockManagers[]
Initialise $wgLockManagers to include basic FS version.
Definition: Setup.php:167
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
$wgSessionsInMemcached
Deprecated alias for $wgSessionsInObjectCache.
const NS_MEDIAWIKI
Definition: Defines.php:77
const PROTO_HTTP
Definition: Defines.php:261
$wgJsMimeType
Definition: Setup.php:436
$wgPasswordSender
Sender email address for e-mail notifications.
if($wgServerName!==false) $wgServerName
Definition: Setup.php:583
$wgEmailAuthentication
Definition: Setup.php:350
Exception class which takes an HTML error message, and does not produce a backtrace.
Definition: FatalError.php:28
$wgSharedUploadDBprefix
Optional table prefix used in database.
SkinTemplate class for the fallback skin.
static newFromKey($key)
Factory function that is just wrapper for the real constructor.
Definition: Message.php:379
$wgSessionCacheType
The cache type for storing session data.
$wgUploadPath
The URL path for the images directory.
$wgEmergencyContact
Site admin email address.
$wgExtraNamespaces
Additional namespaces.
static getGlobalSession()
Get the "global" session.
static getGlobalRequestURL()
Return the path and query string portion of the main request URI.
Definition: WebRequest.php:764
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
if($wgCanonicalServer===false) $serverParts
Definition: Setup.php:578
$ps_setup
Definition: Setup.php:36
if($wgLocalInterwiki) if($wgSharedPrefix===false) if($wgSharedSchema===false) if(!$wgCookiePrefix) $wgCookiePrefix
Definition: Setup.php:342
$wgLocalStylePath
The URL path of the skins directory.
$wgUseEnotif
Definition: Setup.php:361
const NS_CATEGORY_TALK
Definition: Defines.php:84
$wgSharedThumbnailScriptPath
const NS_HELP
Definition: Defines.php:81
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined...
Definition: Setup.php:35
static installHandler()
Install handlers with PHP.
$wgSkipSkins[]
Definition: Setup.php:314
const NS_HELP_TALK
Definition: Defines.php:82
$wgNamespaceAliases['Image']
The canonical names of namespaces 6 and 7 are, as of v1.14, "File" and "File_talk".
Definition: Setup.php:161
$wgScriptPath
The path we should point to.
$wgLocalInterwiki
The interwiki prefix of the current wiki, or false if it doesn't have one.
$wgCacheSharedUploads
Cache shared metadata in memcached.
Stub object for the user language.
Definition: StubObject.php:169
wfGetMainCache()
Get the main cache object.
$wgExtensionAssetsPath
The URL path of the extensions directory.
if(!$wgEmergencyContact) if(!$wgPasswordSender) if(!$wgNoReplyAddress) if($wgSecureLogin &&substr($wgServer, 0, 2)!== '//') $wgVirtualRestConfig['global']['domain']
Definition: Setup.php:605
$ps_globals
Definition: Setup.php:696
$wgDBprefix
Table name prefix.
$wgAllowHTMLEmail
For parts of the system that have been updated to provide HTML email content, send both text and HTML...
wfMemoryLimit()
Set PHP's memory limit to the larger of php.ini or $wgMemoryLimit.
$ps_extensions
Definition: Setup.php:817
$wgCanonicalServer
Canonical URL of the server, to use in IRC feeds and notification e-mails.
const DBO_DEFAULT
Definition: Defines.php:34
$wgHashedUploadDirectory
Set this to false if you do not want MediaWiki to divide your images directory into many subdirectori...
$wgSessionHandler
if($wgInvalidateCacheOnLocalSettingsChange) if($wgNewUserLog) if($wgPageLanguageUseDB) if($wgCookieSecure=== 'detect') if($wgProfileOnly) if($wgMinimalPasswordLength!==false) if($wgMaximalPasswordLength!==false) if(!$wgSessionsInObjectCache &&!$wgSessionsInMemcached) $wgSessionsInObjectCache
Definition: Setup.php:495
$wgLogo
The URL path of the wiki logo.
$wgXhtmlDefaultNamespace
Definition: Setup.php:435
$wgLocalTZoffset
Set an offset from UTC in minutes to use for the default timezone setting for anonymous users and new...
static getMaxPhpUploadSize()
Get the PHP maximum uploaded file size, based on ini settings.
$wgServer
URL of the server.
$wgGitInfoCacheDirectory
Directory where GitInfo will look for pre-computed cache files.
$wgFetchCommonsDescriptions
Fetch commons image description pages and display them on the local wiki?
const NS_TALK
Definition: Defines.php:70
$wgOut
Definition: Setup.php:804
$wgContLang
Definition: Setup.php:701
$wgSharedPrefix
$wgEnotifImpersonal
Definition: Setup.php:353
$wgUploadBaseUrl
If set, this URL is added to the start of $wgUploadPath to form a complete upload URL...
controlled by $wgMainCacheType controlled by $wgParserCacheType controlled by $wgMessageCacheType If you set CACHE_NONE to one of the three control default value for MediaWiki still create a but requests to it are no ops and we always fall through to the database If the cache daemon can t be it should also disable itself fairly smoothly By $wgMemc is used but when it is $parserMemc or $messageMemc this is mentioned $wgDBname
Definition: memcached.txt:96
const CACHE_NONE
Definition: Defines.php:102
$wgResourceLoaderMaxQueryLength
If set to a positive number, ResourceLoader will not generate URLs whose query string is more than th...
string $wgPHPSessionHandling
Whether to use PHP session handling ($_SESSION and session_*() functions)
$debug
Definition: mcc.php:31
wfParseUrl($url)
parse_url() work-alike, but non-broken.
static factory($code)
Get a cached or new language object for a given language code.
Definition: Language.php:179
$wgFileBlacklist
Files with these extensions will never be allowed as uploads.
const NS_USER_TALK
Definition: Defines.php:72
$wgSharedSchema
$wgLoadScript
The URL path to load.php.
$wgNoReplyAddress
Reply-To address for e-mail notifications.
static getDefaultInstance()
Definition: SkinFactory.php:50
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.
$wgFileCacheDirectory
Directory where the cached page will be saved.
static init()
Enabled the debugger and load resource module.
Definition: MWDebug.php:74
$wgUseSharedUploads
If you operate multiple wikis, you can define a shared upload path here.
if(is_null($wgLocalTZoffset)) if(!$wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:657
if($wgRCFilterByAge) $wgDefaultUserOptions['rcdays']
Definition: Setup.php:281
$wgUploadDirectory
The filesystem path of the images directory.
const NS_TEMPLATE_TALK
Definition: Defines.php:80
$wgUser
Definition: Setup.php:794
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:310