MediaWiki  master
Setup.php
Go to the documentation of this file.
1 <?php
30 
35 if ( !defined( 'MEDIAWIKI' ) ) {
36  exit( 1 );
37 }
38 
39 // Check to see if we are at the file scope
40 $wgScopeTest = 'MediaWiki Setup.php scope test';
41 if ( !isset( $GLOBALS['wgScopeTest'] ) || $GLOBALS['wgScopeTest'] !== $wgScopeTest ) {
42  echo "Error, Setup.php must be included from the file scope.\n";
43  die( 1 );
44 }
45 unset( $wgScopeTest );
46 
51 // Sanity check (T5782, T122807)
52 if ( ini_get( 'mbstring.func_overload' ) ) {
53  die( 'MediaWiki does not support installations where mbstring.func_overload is non-zero.' );
54 }
55 
56 // Define MW_ENTRY_POINT if it's not already, so that config code can check the
57 // value without using defined()
58 if ( !defined( 'MW_ENTRY_POINT' ) ) {
64  define( 'MW_ENTRY_POINT', 'unknown' );
65 }
66 
67 // Start the autoloader, so that extensions can derive classes from core files
68 require_once "$IP/includes/AutoLoader.php";
69 
70 // Load global constants
71 require_once "$IP/includes/Defines.php";
72 
73 // Load default settings
74 require_once "$IP/includes/DefaultSettings.php";
75 
76 // Load global functions
77 require_once "$IP/includes/GlobalFunctions.php";
78 
79 // Load composer's autoloader if present
80 if ( is_readable( "$IP/vendor/autoload.php" ) ) {
81  require_once "$IP/vendor/autoload.php";
82 } elseif ( file_exists( "$IP/vendor/autoload.php" ) ) {
83  die( "$IP/vendor/autoload.php exists but is not readable" );
84 }
85 
86 // Assert that composer dependencies were successfully loaded
87 if ( !interface_exists( LoggerInterface::class ) ) {
88  $message = (
89  'MediaWiki requires the <a href="https://github.com/php-fig/log">PSR-3 logging ' .
90  "library</a> to be present. This library is not embedded directly in MediaWiki's " .
91  "git repository and must be installed separately by the end user.\n\n" .
92  'Please see <a href="https://www.mediawiki.org/wiki/Download_from_Git' .
93  '#Fetch_external_libraries">mediawiki.org</a> for help on installing ' .
94  'the required components.'
95  );
96  echo $message;
97  trigger_error( $message, E_USER_ERROR );
98  die( 1 );
99 }
100 
105 // Install a header callback
107 
108 // Set the encoding used by PHP for reading HTTP input, and writing output.
109 // This is also the default for mbstring functions.
110 mb_internal_encoding( 'UTF-8' );
111 
116 if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
117  call_user_func( MW_CONFIG_CALLBACK );
118 } else {
119  if ( !defined( 'MW_CONFIG_FILE' ) ) {
120  define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" );
121  }
122  require_once MW_CONFIG_FILE;
123 }
124 
132 if ( defined( 'MW_SETUP_CALLBACK' ) ) {
133  call_user_func( MW_SETUP_CALLBACK );
134 }
135 
140 // Load queued extensions
141 ExtensionRegistry::getInstance()->loadFromQueue();
142 // Don't let any other extensions load
144 
145 // Set the configured locale on all requests for consisteny
146 putenv( "LC_ALL=$wgShellLocale" );
147 setlocale( LC_ALL, $wgShellLocale );
148 
149 // Set various default paths sensibly...
150 if ( $wgScript === false ) {
151  $wgScript = "$wgScriptPath/index.php";
152 }
153 if ( $wgLoadScript === false ) {
154  $wgLoadScript = "$wgScriptPath/load.php";
155 }
156 if ( $wgRestPath === false ) {
157  $wgRestPath = "$wgScriptPath/rest.php";
158 }
159 
160 if ( $wgArticlePath === false ) {
161  if ( $wgUsePathInfo ) {
162  $wgArticlePath = "$wgScript/$1";
163  } else {
164  $wgArticlePath = "$wgScript?title=$1";
165  }
166 }
167 
168 if ( $wgResourceBasePath === null ) {
170 }
171 if ( $wgStylePath === false ) {
172  $wgStylePath = "$wgResourceBasePath/skins";
173 }
174 if ( $wgLocalStylePath === false ) {
175  // Avoid wgResourceBasePath here since that may point to a different domain (e.g. CDN)
176  $wgLocalStylePath = "$wgScriptPath/skins";
177 }
178 if ( $wgExtensionAssetsPath === false ) {
179  $wgExtensionAssetsPath = "$wgResourceBasePath/extensions";
180 }
181 
182 if ( $wgLogo === false ) {
183  $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
184 }
185 
186 if ( $wgUploadPath === false ) {
187  $wgUploadPath = "$wgScriptPath/images";
188 }
189 if ( $wgUploadDirectory === false ) {
190  $wgUploadDirectory = "$IP/images";
191 }
192 if ( $wgReadOnlyFile === false ) {
193  $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
194 }
195 if ( $wgFileCacheDirectory === false ) {
196  $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
197 }
198 if ( $wgDeletedDirectory === false ) {
199  $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
200 }
201 
202 if ( $wgGitInfoCacheDirectory === false && $wgCacheDirectory !== false ) {
203  $wgGitInfoCacheDirectory = "{$wgCacheDirectory}/gitinfo";
204 }
205 
206 // Fix path to icon images after they were moved in 1.24
207 if ( $wgRightsIcon ) {
208  $wgRightsIcon = str_replace(
209  "{$wgStylePath}/common/images/",
210  "{$wgResourceBasePath}/resources/assets/licenses/",
212  );
213 }
214 
215 if ( isset( $wgFooterIcons['copyright']['copyright'] )
216  && $wgFooterIcons['copyright']['copyright'] === []
217 ) {
218  if ( $wgRightsIcon || $wgRightsText ) {
219  $wgFooterIcons['copyright']['copyright'] = [
220  'url' => $wgRightsUrl,
221  'src' => $wgRightsIcon,
222  'alt' => $wgRightsText,
223  ];
224  }
225 }
226 
227 if ( isset( $wgFooterIcons['poweredby'] )
228  && isset( $wgFooterIcons['poweredby']['mediawiki'] )
229  && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
230 ) {
231  $wgFooterIcons['poweredby']['mediawiki']['src'] =
232  "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png";
233  $wgFooterIcons['poweredby']['mediawiki']['srcset'] =
234  "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png 1.5x, " .
235  "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png 2x";
236 }
237 
246 
254 
259  'name' => 'fsLockManager',
260  'class' => FSLockManager::class,
261  'lockDirectory' => "{$wgUploadDirectory}/lockdir",
262 ];
263 $wgLockManagers[] = [
264  'name' => 'nullLockManager',
265  'class' => NullLockManager::class,
266 ];
267 
273  'imagesPerRow' => 0,
274  'imageWidth' => 120,
275  'imageHeight' => 120,
276  'captionLength' => true,
277  'showBytes' => true,
278  'showDimensions' => true,
279  'mode' => 'traditional',
280 ];
281 
285 if ( !$wgLocalFileRepo ) {
286  $wgLocalFileRepo = [
287  'class' => LocalRepo::class,
288  'name' => 'local',
289  'directory' => $wgUploadDirectory,
290  'scriptDirUrl' => $wgScriptPath,
292  'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
293  'thumbScriptUrl' => $wgThumbnailScriptPath,
294  'transformVia404' => !$wgGenerateThumbnailOnParse,
295  'deletedDir' => $wgDeletedDirectory,
296  'deletedHashLevels' => $wgHashedUploadDirectory ? 3 : 0
297  ];
298 }
299 
300 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
301  // Create a default FileBackend name.
302  // FileBackendGroup will register a default, if absent from $wgFileBackends.
303  $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
304 }
305 
309 if ( $wgUseSharedUploads ) {
310  if ( $wgSharedUploadDBname ) {
311  $wgForeignFileRepos[] = [
312  'class' => ForeignDBRepo::class,
313  'name' => 'shared',
314  'directory' => $wgSharedUploadDirectory,
315  'url' => $wgSharedUploadPath,
316  'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
317  'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
318  'transformVia404' => !$wgGenerateThumbnailOnParse,
319  'dbType' => $wgDBtype,
320  'dbServer' => $wgDBserver,
321  'dbUser' => $wgDBuser,
322  'dbPassword' => $wgDBpassword,
323  'dbName' => $wgSharedUploadDBname,
324  'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
325  'tablePrefix' => $wgSharedUploadDBprefix,
326  'hasSharedCache' => $wgCacheSharedUploads,
327  'descBaseUrl' => $wgRepositoryBaseUrl,
328  'fetchDescription' => $wgFetchCommonsDescriptions,
329  ];
330  } else {
331  $wgForeignFileRepos[] = [
332  'class' => FileRepo::class,
333  'name' => 'shared',
334  'directory' => $wgSharedUploadDirectory,
335  'url' => $wgSharedUploadPath,
336  'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
337  'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
338  'transformVia404' => !$wgGenerateThumbnailOnParse,
339  'descBaseUrl' => $wgRepositoryBaseUrl,
340  'fetchDescription' => $wgFetchCommonsDescriptions,
341  ];
342  }
343 }
344 if ( $wgUseInstantCommons ) {
345  $wgForeignFileRepos[] = [
346  'class' => ForeignAPIRepo::class,
347  'name' => 'wikimediacommons',
348  'apibase' => 'https://commons.wikimedia.org/w/api.php',
349  'url' => 'https://upload.wikimedia.org/wikipedia/commons',
350  'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
351  'hashLevels' => 2,
352  'transformVia404' => true,
353  'fetchDescription' => true,
354  'descriptionCacheExpiry' => 43200,
355  'apiThumbCacheExpiry' => 0,
356  ];
357 }
358 foreach ( $wgForeignFileRepos as &$repo ) {
359  if ( !isset( $repo['directory'] ) && $repo['class'] === ForeignAPIRepo::class ) {
360  $repo['directory'] = $wgUploadDirectory; // b/c
361  }
362  if ( !isset( $repo['backend'] ) ) {
363  $repo['backend'] = $repo['name'] . '-backend';
364  }
365 }
366 unset( $repo ); // no global pollution; destroy reference
367 
368 $rcMaxAgeDays = $wgRCMaxAge / ( 3600 * 24 );
369 // Ensure that default user options are not invalid, since that breaks Special:Preferences
370 $wgDefaultUserOptions['rcdays'] = min(
371  $wgDefaultUserOptions['rcdays'],
372  ceil( $rcMaxAgeDays )
373 );
374 $wgDefaultUserOptions['watchlistdays'] = min(
375  $wgDefaultUserOptions['watchlistdays'],
376  ceil( $rcMaxAgeDays )
377 );
378 unset( $rcMaxAgeDays );
379 
380 if ( $wgSkipSkin ) {
381  // Hard deprecated in 1.34.
382  wfDeprecated( '$wgSkipSkin – use $wgSkipSkins instead', '1.23' );
384 }
385 
386 $wgSkipSkins[] = 'fallback';
387 $wgSkipSkins[] = 'apioutput';
388 
389 if ( $wgLocalInterwiki ) {
390  // Hard deprecated in 1.34.
391  wfDeprecated( '$wgLocalInterwiki – use $wgLocalInterwikis instead', '1.23' );
392  array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
393 }
394 
395 // Set default shared prefix
396 if ( $wgSharedPrefix === false ) {
398 }
399 
400 // Set default shared schema
401 if ( $wgSharedSchema === false ) {
403 }
404 
405 if ( !$wgCookiePrefix ) {
406  if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
408  } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
410  } elseif ( $wgDBprefix ) {
412  } else {
414  }
415 }
416 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
417 
418 if ( $wgEnableEmail ) {
420 } else {
421  // Disable all other email settings automatically if $wgEnableEmail
422  // is set to false. - T65678
423  $wgAllowHTMLEmail = false;
424  $wgEmailAuthentication = false; // do not require auth if you're not sending email anyway
434  unset( $wgGroupPermissions['user']['sendemail'] );
435  $wgUseEnotif = false;
438 }
439 
440 if ( $wgMetaNamespace === false ) {
441  $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
442 }
443 
444 // Ensure the minimum chunk size is less than PHP upload limits or the maximum
445 // upload size.
451  ini_get( 'post_max_size' ),
452  PHP_INT_MAX
453  ) ?: PHP_INT_MAX ) - 1024 // Leave some room for other POST parameters
454 );
455 
461 
463 if ( is_array( $wgExtraNamespaces ) ) {
465 }
466 
467 // Hard-deprecate setting $wgDummyLanguageCodes in LocalSettings.php
468 if ( count( $wgDummyLanguageCodes ) !== 0 ) {
469  wfDeprecated( '$wgDummyLanguageCodes', '1.29' );
470 }
471 // Merge in the legacy language codes, incorporating overrides from the config
473  // Internal language codes of the private-use area which get mapped to
474  // themselves.
475  'qqq' => 'qqq', // Used for message documentation
476  'qqx' => 'qqx', // Used for viewing message keys
478 // Merge in (inverted) BCP 47 mappings
479 foreach ( LanguageCode::getNonstandardLanguageCodeMapping() as $code => $bcp47 ) {
480  $bcp47 = strtolower( $bcp47 ); // force case-insensitivity
481  if ( !isset( $wgDummyLanguageCodes[$bcp47] ) ) {
482  $wgDummyLanguageCodes[$bcp47] = $wgDummyLanguageCodes[$code] ?? $code;
483  }
484 }
485 
486 // These are now the same, always
487 // To determine the user language, use $wgLang->getCode()
489 
490 // Temporary backwards-compatibility reading of old Squid-named CDN settings as of MediaWiki 1.34,
491 // to support sysadmins who fail to update their settings immediately:
492 
493 if ( isset( $wgUseSquid ) ) {
494  // If the sysadmin is still setting a value of $wgUseSquid to true but $wgUseCdn is the default of
495  // false, to be safe, assume they do want this still, so enable it.
496  if ( !$wgUseCdn && $wgUseSquid ) {
497  $wgUseCdn = $wgUseSquid;
498  wfDeprecated( '$wgUseSquid enabled but $wgUseCdn disabled; enabling CDN functions', '1.34' );
499  }
500 } else {
501  // Backwards-compatibility for extensions that read this value.
502  $wgUseSquid = $wgUseCdn;
503 }
504 
505 if ( isset( $wgSquidServers ) ) {
506  // If the sysadmin is still setting a value of $wgSquidServers but $wgCdnServers is the default of
507  // empty, to be safe, assume they do want these servers to be still used, so use them.
508  if ( !empty( $wgSquidServers ) && empty( $wgCdnServers ) ) {
509  $wgCdnServers = $wgSquidServers;
510  wfDeprecated( '$wgSquidServers set, $wgCdnServers empty; using them', '1.34' );
511  }
512 } else {
513  // Backwards-compatibility for extensions that read this value.
514  $wgSquidServers = $wgCdnServers;
515 }
516 
517 if ( isset( $wgSquidServersNoPurge ) ) {
518  // If the sysadmin is still setting values in $wgSquidServersNoPurge but $wgCdnServersNoPurge is
519  // the default of empty, to be safe, assume they do want these servers to be still used, so use
520  // them.
521  if ( !empty( $wgSquidServersNoPurge ) && empty( $wgCdnServersNoPurge ) ) {
522  $wgCdnServersNoPurge = $wgSquidServersNoPurge;
523  wfDeprecated( '$wgSquidServersNoPurge set, $wgCdnServersNoPurge empty; using them', '1.34' );
524  }
525 } else {
526  // Backwards-compatibility for extensions that read this value.
527  $wgSquidServersNoPurge = $wgCdnServersNoPurge;
528 }
529 
530 if ( isset( $wgSquidMaxage ) ) {
531  // If the sysadmin is still setting a value of $wgSquidMaxage and it's higher than $wgCdnMaxAge,
532  // to be safe, assume they want the higher (lower performance requirement) value, so use that.
533  if ( $wgCdnMaxAge < $wgSquidMaxage ) {
534  $wgCdnMaxAge = $wgSquidMaxage;
535  wfDeprecated( '$wgSquidMaxage set higher than $wgCdnMaxAge; using the higher value', '1.34' );
536  }
537 } else {
538  // Backwards-compatibility for extensions that read this value.
539  $wgSquidMaxage = $wgCdnMaxAge;
540 }
541 
542 // Blacklisted file extensions shouldn't appear on the "allowed" list
543 $wgFileExtensions = array_values( array_diff( $wgFileExtensions, $wgFileBlacklist ) );
544 
546  Wikimedia\suppressWarnings();
547  $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', filemtime( "$IP/LocalSettings.php" ) ) );
548  Wikimedia\restoreWarnings();
549 }
550 
551 if ( $wgNewUserLog ) {
552  // Add new user log type
553  $wgLogTypes[] = 'newusers';
554  $wgLogNames['newusers'] = 'newuserlogpage';
555  $wgLogHeaders['newusers'] = 'newuserlogpagetext';
556  $wgLogActionsHandlers['newusers/newusers'] = NewUsersLogFormatter::class;
557  $wgLogActionsHandlers['newusers/create'] = NewUsersLogFormatter::class;
558  $wgLogActionsHandlers['newusers/create2'] = NewUsersLogFormatter::class;
559  $wgLogActionsHandlers['newusers/byemail'] = NewUsersLogFormatter::class;
560  $wgLogActionsHandlers['newusers/autocreate'] = NewUsersLogFormatter::class;
561 }
562 
563 if ( $wgPageCreationLog ) {
564  // Add page creation log type
565  $wgLogTypes[] = 'create';
566  $wgLogActionsHandlers['create/create'] = LogFormatter::class;
567 }
568 
569 if ( $wgPageLanguageUseDB ) {
570  $wgLogTypes[] = 'pagelang';
571  $wgLogActionsHandlers['pagelang/pagelang'] = PageLangLogFormatter::class;
572 }
573 
574 if ( $wgCookieSecure === 'detect' ) {
575  $wgCookieSecure = ( WebRequest::detectProtocol() === 'https' );
576 }
577 
578 if ( $wgProfileOnly ) {
579  // Hard deprecated in 1.34.
580  wfDeprecated(
581  '$wgProfileOnly set the log file in $wgDebugLogGroups[\'profileoutput\'] instead',
582  '1.23'
583  );
584  $wgDebugLogGroups['profileoutput'] = $wgDebugLogFile;
585  $wgDebugLogFile = '';
586 }
587 
588 // Backwards compatibility with old password limits
589 if ( $wgMinimalPasswordLength !== false ) {
590  $wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = $wgMinimalPasswordLength;
591 }
592 
593 if ( $wgMaximalPasswordLength !== false ) {
594  $wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] = $wgMaximalPasswordLength;
595 }
596 
597 if ( $wgPHPSessionHandling !== 'enable' &&
598  $wgPHPSessionHandling !== 'warn' &&
599  $wgPHPSessionHandling !== 'disable'
600 ) {
601  $wgPHPSessionHandling = 'warn';
602 }
603 if ( defined( 'MW_NO_SESSION' ) ) {
604  // If the entry point wants no session, force 'disable' here unless they
605  // specifically set it to the (undocumented) 'warn'.
606  // @phan-suppress-next-line PhanUndeclaredConstant
607  $wgPHPSessionHandling = MW_NO_SESSION === 'warn' ? 'warn' : 'disable';
608 }
609 
611 
612 // Reset the global service locator, so any services that have already been created will be
613 // re-created while taking into account any custom settings and extensions.
614 MediaWikiServices::resetGlobalInstance( new GlobalVarConfig(), 'quick' );
615 
616 // Define a constant that indicates that the bootstrapping of the service locator
617 // is complete.
618 define( 'MW_SERVICE_BOOTSTRAP_COMPLETE', 1 );
619 
621 
622 // T30798: $wgServer must be explicitly set
623 if ( $wgServer === false ) {
624  throw new FatalError(
625  '$wgServer must be set in LocalSettings.php. ' .
626  'See <a href="https://www.mediawiki.org/wiki/Manual:$wgServer">' .
627  'https://www.mediawiki.org/wiki/Manual:$wgServer</a>.'
628  );
629 }
630 
631 if ( $wgCanonicalServer === false ) {
633 }
634 
635 // Set server name
637 if ( $wgServerName !== false ) {
638  wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
639  . 'not customized. Overwriting $wgServerName.' );
640 }
642 unset( $serverParts );
643 
644 // Set defaults for configuration variables
645 // that are derived from the server name by default
646 // Note: $wgEmergencyContact and $wgPasswordSender may be false or empty string (T104142)
647 if ( !$wgEmergencyContact ) {
648  $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
649 }
650 if ( !$wgPasswordSender ) {
651  $wgPasswordSender = 'apache@' . $wgServerName;
652 }
653 if ( !$wgNoReplyAddress ) {
655 }
656 
657 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
658  $wgSecureLogin = false;
659  wfWarn( 'Secure login was enabled on a server that only supports '
660  . 'HTTP or HTTPS. Disabling secure login.' );
661 }
662 
664 
665 // Now that GlobalFunctions is loaded, set defaults that depend on it.
666 if ( $wgTmpDirectory === false ) {
668 }
669 
670 // We don't use counters anymore. Left here for extensions still
671 // expecting this to exist. Should be removed sometime 1.26 or later.
672 if ( !isset( $wgDisableCounters ) ) {
673  $wgDisableCounters = true;
674 }
675 
676 if ( $wgMainWANCache === false ) {
677  // Setup a WAN cache from $wgMainCacheType with no relayer.
678  // Sites using multiple datacenters can configure a relayer.
679  $wgMainWANCache = 'mediawiki-main-default';
681  'class' => WANObjectCache::class,
682  'cacheId' => $wgMainCacheType
683  ];
684 }
685 
686 if ( $wgSharedDB && $wgSharedTables ) {
687  // Apply $wgSharedDB table aliases for the local LB (all non-foreign DB connections)
688  MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
689  array_fill_keys(
691  [
692  'dbname' => $wgSharedDB,
693  'schema' => $wgSharedSchema,
694  'prefix' => $wgSharedPrefix
695  ]
696  )
697  );
698 }
699 
700 // Raise the memory limit if it's too low
701 // Note, this makes use of wfDebug, and thus should not be before
702 // MWDebug::init() is called.
704 
710 if ( is_null( $wgLocaltimezone ) ) {
711  Wikimedia\suppressWarnings();
712  $wgLocaltimezone = date_default_timezone_get();
713  Wikimedia\restoreWarnings();
714 }
715 
716 date_default_timezone_set( $wgLocaltimezone );
717 if ( is_null( $wgLocalTZoffset ) ) {
718  $wgLocalTZoffset = (int)date( 'Z' ) / 60;
719 }
720 // The part after the System| is ignored, but rest of MW fills it
721 // out as the local offset.
722 $wgDefaultUserOptions['timecorrection'] = "System|$wgLocalTZoffset";
723 
724 if ( !$wgDBerrorLogTZ ) {
726 }
727 
728 // Initialize the request object in $wgRequest
729 $wgRequest = RequestContext::getMain()->getRequest(); // BackCompat
730 // Set user IP/agent information for agent session consistency purposes
731 $cpPosInfo = LBFactory::getCPInfoFromCookieValue(
732  // The cookie has no prefix and is set by MediaWiki::preOutputCommit()
733  $wgRequest->getCookie( 'cpPosIndex', '' ),
734  // Mitigate broken client-side cookie expiration handling (T190082)
735  time() - ChronologyProtector::POSITION_COOKIE_TTL
736 );
737 MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->setRequestInfo( [
738  'IPAddress' => $wgRequest->getIP(),
739  'UserAgent' => $wgRequest->getHeader( 'User-Agent' ),
740  'ChronologyProtection' => $wgRequest->getHeader( 'MediaWiki-Chronology-Protection' ),
741  'ChronologyPositionIndex' => $wgRequest->getInt( 'cpPosIndex', $cpPosInfo['index'] ),
742  'ChronologyClientId' => $cpPosInfo['clientId']
743  ?? $wgRequest->getHeader( 'MediaWiki-Chronology-Client-Id' )
744 ] );
745 unset( $cpPosInfo );
746 // Make sure that object caching does not undermine the ChronologyProtector improvements
747 if ( $wgRequest->getCookie( 'UseDC', '' ) === 'master' ) {
748  // The user is pinned to the primary DC, meaning that they made recent changes which should
749  // be reflected in their subsequent web requests. Avoid the use of interim cache keys because
750  // they use a blind TTL and could be stale if an object changes twice in a short time span.
751  MediaWikiServices::getInstance()->getMainWANObjectCache()->useInterimHoldOffCaching( false );
752 }
753 
754 // Useful debug output
755 if ( $wgCommandLineMode ) {
756  if ( isset( $self ) ) {
757  wfDebug( "\n\nStart command line script $self\n" );
758  }
759 } else {
760  $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
761  $debug .= "HTTP HEADERS:\n";
762  foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
763  $debug .= "$name: $value\n";
764  }
765  wfDebug( $debug );
766 }
767 
770 
771 // Most of the config is out, some might want to run hooks here.
772 Hooks::run( 'SetupAfterCache' );
773 
778 $wgContLang = MediaWikiServices::getInstance()->getContentLanguage();
779 
780 // Now that variant lists may be available...
781 $wgRequest->interpolateTitle();
782 
788 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
789  // If session.auto_start is there, we can't touch session name
790  if ( $wgPHPSessionHandling !== 'disable' && !wfIniGetBool( 'session.auto_start' ) ) {
791  session_name( $wgSessionName ?: $wgCookiePrefix . '_session' );
792  }
793 
794  // Create the SessionManager singleton and set up our session handler,
795  // unless we're specifically asked not to.
796  if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
798  MediaWiki\Session\SessionManager::singleton()
799  );
800  }
801 
802  // Initialize the session
803  try {
805  } catch ( MediaWiki\Session\SessionOverflowException $ex ) {
806  // The exception is because the request had multiple possible
807  // sessions tied for top priority. Report this to the user.
808  $list = [];
809  foreach ( $ex->getSessionInfos() as $info ) {
810  $list[] = $info->getProvider()->describe( $wgContLang );
811  }
812  $list = $wgContLang->listToText( $list );
813  throw new HttpError( 400,
814  Message::newFromKey( 'sessionmanager-tie', $list )->inLanguage( $wgContLang )->plain()
815  );
816  }
817 
818  if ( $session->isPersistent() ) {
819  $wgInitialSessionId = $session->getSessionId();
820  }
821 
822  $session->renew();
823  if ( MediaWiki\Session\PHPSessionHandler::isEnabled() &&
824  ( $session->isPersistent() || $session->shouldRememberUser() ) &&
825  session_id() !== $session->getId()
826  ) {
827  // Start the PHP-session for backwards compatibility
828  if ( session_id() !== '' ) {
829  wfDebugLog( 'session', 'PHP session {old_id} was already started, changing to {new_id}', 'all', [
830  'old_id' => session_id(),
831  'new_id' => $session->getId(),
832  ] );
833  session_write_close();
834  }
835  session_id( $session->getId() );
836  session_start();
837  }
838 
839  unset( $session );
840 } else {
841  // Even if we didn't set up a global Session, still install our session
842  // handler unless specifically requested not to.
843  if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
845  MediaWiki\Session\SessionManager::singleton()
846  );
847  }
848 }
849 
853 $wgUser = RequestContext::getMain()->getUser(); // BackCompat
854 
859 
863 $wgOut = RequestContext::getMain()->getOutput(); // BackCompat
864 
869 $wgParser = new StubObject( 'wgParser', function () {
870  return MediaWikiServices::getInstance()->getParser();
871 } );
872 
876 $wgTitle = null;
877 
878 // Extension setup functions
879 // Entries should be added to this variable during the inclusion
880 // of the extension file. This allows the extension to perform
881 // any necessary initialisation in the fully initialised environment
882 foreach ( $wgExtensionFunctions as $func ) {
883  call_user_func( $func );
884 }
885 
886 // If the session user has a 0 id but a valid name, that means we need to
887 // autocreate it.
888 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
889  $sessionUser = MediaWiki\Session\SessionManager::getGlobalSession()->getUser();
890  if ( $sessionUser->getId() === 0 && User::isValidUserName( $sessionUser->getName() ) ) {
891  $res = MediaWiki\Auth\AuthManager::singleton()->autoCreateUser(
892  $sessionUser,
893  MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_SESSION,
894  true
895  );
896  \MediaWiki\Logger\LoggerFactory::getInstance( 'authevents' )->info( 'Autocreation attempt', [
897  'event' => 'autocreate',
898  'status' => $res,
899  ] );
900  unset( $res );
901  }
902  unset( $sessionUser );
903 }
904 
905 if ( !$wgCommandLineMode ) {
907 }
908 
$wgInitialSessionId
Definition: Setup.php:787
$wgForeignFileRepos
Enable the use of files from one or more other wikis.
$wgUseInstantCommons
Use Wikimedia Commons as a foreign file repository.
$wgFooterIcons
Abstract list of footer icons for skins in place of old copyrightico and poweredbyico code You can ad...
$wgNewUserLog
Maintain a log of newusers at Special:Log/newusers?
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
$wgCanonicalNamespaceNames
Definitions of the NS_ constants are in Defines.php.
Definition: Setup.php:460
$wgEnotifWatchlist
Definition: Setup.php:433
$wgScript
The URL path to index.php.
$wgRightsUrl
Set this to specify an external URL containing details about the content license used on your wiki...
$wgDBerrorLogTZ
Timezone to use in the error log.
static getNonstandardLanguageCodeMapping()
Returns a mapping of non-standard language codes used by (current and previous version of) MediaWiki...
$wgSitename
Name of the site.
$wgUserEmailUseReplyTo
Definition: Setup.php:436
$wgUsersNotifiedOnAllChanges
Definition: Setup.php:437
$wgDebugLogGroups
Map of string log group names to log destinations.
if( $wgServer===false) if( $wgCanonicalServer===false) $serverParts
Definition: Setup.php:636
if( $wgLocalInterwiki) if( $wgSharedPrefix===false) if( $wgSharedSchema===false) if(! $wgCookiePrefix) $wgCookiePrefix
Definition: Setup.php:416
$wgEnotifFromEditor
Definition: Setup.php:426
$wgParser
Definition: Setup.php:869
$wgGalleryOptions
Default parameters for the "<gallery>" tag.
Definition: Setup.php:272
if( $wgScript===false) if( $wgLoadScript===false) if( $wgRestPath===false) if( $wgArticlePath===false) 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( $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&#39;s too easy for a sysadmin to set $wgName...
Definition: Setup.php:245
$wgDBpassword
Database user&#39;s password.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
$wgThumbnailScriptPath
Give a path here to use thumb.php for thumbnail generation on client request, instead of generating t...
$wgRepositoryBaseUrl
Shortcut for the &#39;descBaseUrl&#39; setting of $wgForeignFileRepos.
bool string $wgSharedUploadDBname
Shortcut for the ForeignDBRepo &#39;dbName&#39; setting in $wgForeignFileRepos.
$wgDefaultUserOptions['rcdays']
Definition: Setup.php:370
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
$wgDBtype
Database type.
$wgFileExtensions
Definition: Setup.php:543
bool $wgCacheSharedUploads
Shortcut for the ForeignDBRepo &#39;hasSharedCache&#39; setting in $wgForeignFileRepos.
$wgLocalFileRepo
File repository structures.
$wgSecureLogin
This is to let user authenticate using https when they come from http.
$wgDBmwschema
Current wiki database schema name.
$wgMetaNamespace
Name of the project namespace.
$wgSharedTables
$wgDBserver
Database host name or IP address.
static getLocalClusterInstance()
Get the main cluster-local cache object.
static getInstance( $channel)
Get a named logger instance from the currently configured logger factory.
$wgDBuser
Database username.
$wgMainWANCache
Main Wide-Area-Network cache type.
if(! $wgEmergencyContact) if(! $wgPasswordSender) if(! $wgNoReplyAddress) if( $wgSecureLogin &&substr( $wgServer, 0, 2) !=='//') $wgVirtualRestConfig['global']['domain']
Definition: Setup.php:663
$wgCookieSecure
Whether the "secure" flag should be set on the cookie.
$wgCdnServers
List of proxy servers to purge on changes; default port is 80.
A helper class for throttling authentication attempts.
$wgTmpDirectory
The local filesystem path to a temporary directory.
$wgEnableUserEmail
Definition: Setup.php:425
$wgCdnServersNoPurge
As with $wgCdnServers, except these servers aren&#39;t purged on page changes; use to set a list of trust...
static getMaxUploadSize( $forType=null)
Get the MediaWiki maximum uploaded file size for given type of upload, based on $wgMaxUploadSize.
$wgArticlePath
Definition: img_auth.php:47
$wgWANObjectCaches
Advanced WAN object cache configuration.
string $wgSharedUploadDBprefix
Shortcut for the ForeignDBRepo &#39;tablePrefix&#39; setting in $wgForeignFileRepos.
$wgMemc
Definition: Setup.php:768
$wgLogNames
Lists the message key string for each log type.
wfGetMessageCacheStorage()
Get the cache object used by the message cache.
$wgDebugLogFile
Filename for debug logging.
$wgGenerateThumbnailOnParse
Allow thumbnail rendering on page view.
$wgRCMaxAge
Recentchanges items are periodically purged; entries older than this many seconds will go...
$wgEnableEmail
Set to true to enable the e-mail basic features: Password reminders, etc.
if(!defined( 'MEDIAWIKI')) $wgScopeTest
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined...
Definition: Setup.php:40
const MW_NO_SESSION
Definition: load.php:29
$wgCacheDirectory
Directory for caching data in the local filesystem.
$wgDebugDumpSql
Write SQL queries to the debug log.
$wgInvalidateCacheOnLocalSettingsChange
Invalidate various caches when LocalSettings.php changes.
$wgGroupPermissions
Permission keys given to users in each group.
$wgExtraLanguageCodes
List of mappings from one language code to another.
Show an error that looks like an HTTP server error.
Definition: HttpError.php:30
$wgLanguageCode
Site language code.
string $wgSharedUploadPath
Shortcut for the &#39;url&#39; setting of $wgForeignFileRepos.
string $wgSharedThumbnailScriptPath
Shortcut for the &#39;thumbScriptUrl&#39; setting of $wgForeignFileRepos.
$rcMaxAgeDays
Definition: Setup.php:368
$wgStylePath
The URL path of the skins directory.
$wgPasswordPolicy
Password policy for the wiki.
$wgLang
Definition: Setup.php:858
wfTempDir()
Tries to get the system directory for temporary files.
static getMain()
Get the RequestContext object associated with the main request.
const DBO_DEBUG
Definition: defines.php:9
$wgMainCacheType
Main cache type.
$wgDeletedDirectory
What directory to place deleted uploads in.
$wgEnotifMaxRecips
Definition: Setup.php:428
static install(SessionManager $manager)
Install a session handler for the current web request.
$wgEnotifUseRealName
Definition: Setup.php:431
$wgLocalInterwikis
Array for multiple $wgLocalInterwiki values, in case there are several interwiki prefixes that point ...
static singleton()
Get the global AuthManager.
$self
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
bool $wgUseSharedUploads
Shortcut for adding an entry to $wgForeignFileRepos.
$wgEnotifRevealEditorAddress
Definition: Setup.php:430
if(is_array( $wgExtraNamespaces)) if(count( $wgDummyLanguageCodes) !==0) $wgDummyLanguageCodes
Definition: Setup.php:472
$wgEnotifUserTalk
Definition: Setup.php:432
$wgUsePathInfo
Whether to support URLs like index.php/Page_title These often break when PHP is set up in CGI mode...
$wgResourceBasePath
The default &#39;remoteBasePath&#39; value for instances of ResourceLoaderFileModule.
$wgRestPath
The URL path to the REST API Defaults to "{$wgScriptPath}/rest.php".
$wgMaximalPasswordLength
Specifies the maximal length of a user password (T64685).
static register()
Register a callback to be called when headers are sent.
$wgProfileOnly
Don&#39;t put non-profiling info into log file.
$wgEnotifMinorEdits
Definition: Setup.php:429
$wgSharedDB
Shared database for multiple wikis.
wfMemoryLimit( $newLimit)
Raise PHP&#39;s memory limit (if needed).
$wgTitle
Definition: Setup.php:876
Class to implement stub globals, which are globals that delay loading the their associated module cod...
Definition: StubObject.php:45
$wgCdnMaxAge
Cache TTL for the CDN sent as s-maxage (without ESI) or Surrogate-Control (with ESI).
$messageMemc
Definition: Setup.php:769
static getDeprecatedCodeMapping()
Returns a mapping of deprecated language codes that were used in previous versions of MediaWiki to up...
$wgRightsText
If either $wgRightsUrl or $wgRightsPage is specified then this variable gives the text for the link...
static schedulePingback()
Schedule a deferred callable that will check if a pingback should be sent and (if so) proceed to send...
Definition: Pingback.php:272
$wgSessionName
Override to customise the session name.
const NS_FILE
Definition: Defines.php:66
$GLOBALS['IP']
const NS_FILE_TALK
Definition: Defines.php:67
static detectProtocol()
Detect the protocol from $_SERVER.
Definition: WebRequest.php:280
$wgLocaltimezone
Fake out the timezone that the server thinks it&#39;s in.
$wgLockManagers[]
Initialise $wgLockManagers to include basic FS version.
Definition: Setup.php:258
if( $wgMetaNamespace===false) $wgMinUploadChunkSize
Definition: Setup.php:446
static setup()
Definition: MWDebug.php:73
const NS_MEDIAWIKI
Definition: Defines.php:68
const PROTO_HTTP
Definition: Defines.php:199
$wgLogActionsHandlers
The same as above, but here values are names of classes, not messages.
foreach( $wgExtensionFunctions as $func) if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) if(! $wgCommandLineMode) $wgFullyInitialised
Definition: Setup.php:909
$wgPasswordSender
Sender email address for e-mail notifications.
$wgEmailAuthentication
Definition: Setup.php:424
const MW_CONFIG_CALLBACK
Definition: install.php:26
$wgDBname
Current wiki database name.
Abort the web request with a custom HTML string that will represent the entire response.
Definition: FatalError.php:35
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
string $wgSharedUploadDirectory
Shortcut for the &#39;directory&#39; setting of $wgForeignFileRepos.
$wgPageCreationLog
Maintain a log of page creations at Special:Log/create?
$wgShellLocale
Locale for LC_ALL, to provide a known environment for locale-sensitive operations.
$wgUploadPath
The URL path for the images directory.
$wgMemoryLimit
The minimum amount of memory that MediaWiki "needs"; MediaWiki will try to raise PHP&#39;s memory limit i...
$wgEmergencyContact
Site admin email address.
$wgNamespaceAliases['Image']
The canonical names of namespaces 6 and 7 are, as of v1.14, "File" and "File_talk".
Definition: Setup.php:252
$wgExtraNamespaces
Additional namespaces.
static getGlobalSession()
Get the "global" session.
$wgReadOnlyFile
If this lock file exists (size > 0), the wiki will be forced into read-only mode. ...
const DBO_DEFAULT
Definition: defines.php:13
$wgLocalStylePath
The URL path of the skins directory.
$wgUseEnotif
Definition: Setup.php:435
$debug
Definition: Setup.php:761
$wgMinimalPasswordLength
Specifies the minimal length of a user password.
static installHandler()
Install handlers with PHP.
static isValidUserName( $name)
Is the input a valid username?
Definition: User.php:977
if( $wgSkipSkin) $wgSkipSkins[]
Definition: Setup.php:386
bool $wgHashedSharedUploadDirectory
Shortcut for the &#39;hashLevels&#39; setting of $wgForeignFileRepos.
$wgScriptPath
The path we should point to.
$wgLocalInterwiki
The interwiki prefix of the current wiki, or false if it doesn&#39;t have one.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not...
Stub object for the user language.
$wgExtensionAssetsPath
The URL path of the extensions directory.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
global $wgCommandLineMode
$wgDBprefix
Current wiki database table name prefix.
$cpPosInfo
Definition: Setup.php:731
$wgAllowHTMLEmail
For parts of the system that have been updated to provide HTML email content, send both text and HTML...
$wgLogHeaders
Lists the message key string for descriptive text to be shown at the top of each log type...
$wgCanonicalServer
Canonical URL of the server, to use in IRC feeds and notification e-mails.
$wgHashedUploadDirectory
Set this to false if you do not want MediaWiki to divide your images directory into many subdirectori...
$wgLogo
The URL path of the wiki logo.
$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.
if(! $wgDBerrorLogTZ) $wgRequest
Definition: Setup.php:729
$wgServer
URL of the server.
$wgGitInfoCacheDirectory
Directory where GitInfo will look for pre-computed cache files.
if( $wgServerName !==false) $wgServerName
Definition: Setup.php:641
$wgOut
Definition: Setup.php:863
$wgSharedPrefix
$wgEnotifImpersonal
Definition: Setup.php:427
$wgExtensionFunctions
A list of callback functions which are called once MediaWiki is fully initialised.
$wgUploadBaseUrl
If set, this URL is added to the start of $wgUploadPath to form a complete upload URL...
$wgLogTypes
The logging system has two levels: an event type, which describes the general category and can be vie...
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
string $wgPHPSessionHandling
Whether to use PHP session handling ($_SESSION and session_*() functions)
$wgRightsIcon
Override for copyright metadata.
$wgFileBlacklist
Files with these extensions will never be allowed as uploads.
$wgSharedSchema
$wgLoadScript
The URL path to load.php.
$wgNoReplyAddress
Reply-To address for e-mail notifications.
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.
const CANONICAL_NAMES
Definitions of the NS_ constants are in Defines.php.
$wgFileCacheDirectory
Directory where the cached page will be saved.
bool $wgFetchCommonsDescriptions
Shortcut for the &#39;fetchDescription&#39; setting of $wgForeignFileRepos.
$wgUseCdn
Enable/disable CDN.
wfShorthandToInteger( $string='', $default=-1)
Converts shorthand byte notation to integer form.
if(is_array( $wgExtraNamespaces)) if(count( $wgDummyLanguageCodes) !==0) foreach(LanguageCode::getNonstandardLanguageCodeMapping() as $code=> $bcp47) $wgContLanguageCode
Definition: Setup.php:488
$wgUploadDirectory
The filesystem path of the images directory.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:200
$wgContLang
Definition: Setup.php:778
static newFromKey( $key,... $params)
Factory function that is just wrapper for the real constructor.
Definition: Message.php:413