MediaWiki REL1_37
Setup.php
Go to the documentation of this file.
1<?php
56use Psr\Log\LoggerInterface;
57use Wikimedia\RequestTimeout\RequestTimeout;
58
66// This file must be included from a valid entry point (e.g. WebStart.php, Maintenance.php)
67if ( !defined( 'MEDIAWIKI' ) ) {
68 exit( 1 );
69}
70
71// This file must have global scope.
72$wgScopeTest = 'MediaWiki Setup.php scope test';
73if ( !isset( $GLOBALS['wgScopeTest'] ) || $GLOBALS['wgScopeTest'] !== $wgScopeTest ) {
74 echo "Error, Setup.php must be included from the file scope.\n";
75 die( 1 );
76}
77unset( $wgScopeTest );
78
79// PHP must not be configured to overload mbstring functions. (T5782, T122807)
80// This was deprecated by upstream in PHP 7.2, likely to be removed in PHP 8.0.
81if ( ini_get( 'mbstring.func_overload' ) ) {
82 die( 'MediaWiki does not support installations where mbstring.func_overload is non-zero.' );
83}
84
85// The MW_ENTRY_POINT constant must always exists, to make it safe to access.
86// For compat, we do support older and custom MW entryoints that don't set this,
87// in which case we assign a default here.
88if ( !defined( 'MW_ENTRY_POINT' ) ) {
94 define( 'MW_ENTRY_POINT', 'unknown' );
95}
96
103require_once "$IP/includes/AutoLoader.php";
104require_once "$IP/includes/Defines.php";
105require_once "$IP/includes/DefaultSettings.php";
106require_once "$IP/includes/GlobalFunctions.php";
107
108// Load composer's autoloader if present
109if ( is_readable( "$IP/vendor/autoload.php" ) ) {
110 require_once "$IP/vendor/autoload.php";
111} elseif ( file_exists( "$IP/vendor/autoload.php" ) ) {
112 die( "$IP/vendor/autoload.php exists but is not readable" );
113}
114
115// Assert that composer dependencies were successfully loaded
116if ( !interface_exists( LoggerInterface::class ) ) {
117 $message = (
118 'MediaWiki requires the <a href="https://github.com/php-fig/log">PSR-3 logging ' .
119 "library</a> to be present. This library is not embedded directly in MediaWiki's " .
120 "git repository and must be installed separately by the end user.\n\n" .
121 'Please see the <a href="https://www.mediawiki.org/wiki/Download_from_Git' .
122 '#Fetch_external_libraries">instructions for installing libraries</a> on mediawiki.org ' .
123 'for help on installing the required components.'
124 );
125 echo $message;
126 trigger_error( $message, E_USER_ERROR );
127}
128
129HeaderCallback::register();
130
131// Set the encoding used by PHP for reading HTTP input, and writing output.
132// This is also the default for mbstring functions.
133mb_internal_encoding( 'UTF-8' );
134
139if ( defined( 'MW_CONFIG_CALLBACK' ) ) {
140 call_user_func( MW_CONFIG_CALLBACK );
141} else {
142 if ( !defined( 'MW_CONFIG_FILE' ) ) {
143 define( 'MW_CONFIG_FILE', "$IP/LocalSettings.php" );
144 }
145 require_once MW_CONFIG_FILE;
146}
147
155if ( defined( 'MW_SETUP_CALLBACK' ) ) {
156 call_user_func( MW_SETUP_CALLBACK );
157}
158
159// Start time limit
161 RequestTimeout::singleton()->setWallTimeLimit( $wgRequestTimeLimit );
162}
163
168ExtensionRegistry::getInstance()->loadFromQueue();
169// Don't let any other extensions load
171
172// Set the configured locale on all requests for consistency
173// This must be after LocalSettings.php (and is informed by the installer).
174putenv( "LC_ALL=$wgShellLocale" );
175setlocale( LC_ALL, $wgShellLocale );
176
181if ( $wgScript === false ) {
182 $wgScript = "$wgScriptPath/index.php";
183}
184if ( $wgLoadScript === false ) {
185 $wgLoadScript = "$wgScriptPath/load.php";
186}
187if ( $wgRestPath === false ) {
188 $wgRestPath = "$wgScriptPath/rest.php";
189}
190if ( $wgArticlePath === false ) {
191 if ( $wgUsePathInfo ) {
192 $wgArticlePath = "$wgScript/$1";
193 } else {
194 $wgArticlePath = "$wgScript?title=$1";
195 }
196}
197if ( $wgResourceBasePath === null ) {
199}
200if ( $wgStylePath === false ) {
201 $wgStylePath = "$wgResourceBasePath/skins";
202}
203if ( $wgLocalStylePath === false ) {
204 // Avoid wgResourceBasePath here since that may point to a different domain (e.g. CDN)
205 $wgLocalStylePath = "$wgScriptPath/skins";
206}
207if ( $wgExtensionAssetsPath === false ) {
208 $wgExtensionAssetsPath = "$wgResourceBasePath/extensions";
209}
210
211// For backwards compatibility, the value of wgLogos is copied to wgLogo.
212// This is because some extensions/skins may be using $config->get('Logo')
213// to access the value.
214if ( $wgLogos !== false && isset( $wgLogos['1x'] ) ) {
215 $wgLogo = $wgLogos['1x'];
216}
217if ( $wgLogo === false ) {
218 $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
219}
220
221if ( $wgUploadPath === false ) {
222 $wgUploadPath = "$wgScriptPath/images";
223}
224if ( $wgUploadDirectory === false ) {
225 $wgUploadDirectory = "$IP/images";
226}
227if ( $wgReadOnlyFile === false ) {
228 $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
229}
230if ( $wgFileCacheDirectory === false ) {
231 $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
232}
233if ( $wgDeletedDirectory === false ) {
234 $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
235}
236if ( $wgGitInfoCacheDirectory === false && $wgCacheDirectory !== false ) {
237 $wgGitInfoCacheDirectory = "{$wgCacheDirectory}/gitinfo";
238}
239if ( $wgSharedPrefix === false ) {
241}
242if ( $wgSharedSchema === false ) {
244}
245if ( $wgMetaNamespace === false ) {
246 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
247}
248
249if ( $wgMainWANCache === false ) {
250 // Create a WAN cache from $wgMainCacheType
251 $wgMainWANCache = 'mediawiki-main-default';
253 'class' => WANObjectCache::class,
254 'cacheId' => $wgMainCacheType,
255 ];
256}
257
258// Back-compat
259if ( isset( $wgFileBlacklist ) ) {
260 $wgProhibitedFileExtensions = array_merge( $wgProhibitedFileExtensions, $wgFileBlacklist );
261} else {
262 $wgFileBlacklist = $wgProhibitedFileExtensions;
263}
264if ( isset( $wgMimeTypeBlacklist ) ) {
265 $wgMimeTypeExclusions = array_merge( $wgMimeTypeExclusions, $wgMimeTypeBlacklist );
266} else {
267 $wgMimeTypeBlacklist = $wgMimeTypeExclusions;
268}
269if ( isset( $wgEnableUserEmailBlacklist ) ) {
270 $wgEnableUserEmailMuteList = $wgEnableUserEmailBlacklist;
271} else {
272 $wgEnableUserEmailBlacklist = $wgEnableUserEmailMuteList;
273}
274if ( isset( $wgShortPagesNamespaceBlacklist ) ) {
275 $wgShortPagesNamespaceExclusions = $wgShortPagesNamespaceBlacklist;
276} else {
277 $wgShortPagesNamespaceBlacklist = $wgShortPagesNamespaceExclusions;
278}
279
280// Prohibited file extensions shouldn't appear on the "allowed" list
282
283// Fix path to icon images after they were moved in 1.24
284if ( $wgRightsIcon ) {
285 $wgRightsIcon = str_replace(
286 "{$wgStylePath}/common/images/",
287 "{$wgResourceBasePath}/resources/assets/licenses/",
289 );
290}
291
292if ( isset( $wgFooterIcons['copyright']['copyright'] )
293 && $wgFooterIcons['copyright']['copyright'] === []
294) {
295 if ( $wgRightsIcon || $wgRightsText ) {
296 $wgFooterIcons['copyright']['copyright'] = [
297 'url' => $wgRightsUrl,
298 'src' => $wgRightsIcon,
299 'alt' => $wgRightsText,
300 ];
301 }
302}
303
304if ( isset( $wgFooterIcons['poweredby'] )
305 && isset( $wgFooterIcons['poweredby']['mediawiki'] )
306 && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
307) {
308 $wgFooterIcons['poweredby']['mediawiki']['src'] =
309 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png";
310 $wgFooterIcons['poweredby']['mediawiki']['srcset'] =
311 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png 1.5x, " .
312 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png 2x";
313}
314
323
328 'name' => 'fsLockManager',
329 'class' => FSLockManager::class,
330 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
331];
332$wgLockManagers[] = [
333 'name' => 'nullLockManager',
334 'class' => NullLockManager::class,
335];
336
342 'imagesPerRow' => 0,
343 'imageWidth' => 120,
344 'imageHeight' => 120,
345 'captionLength' => true,
346 'showBytes' => true,
347 'showDimensions' => true,
348 'mode' => 'traditional',
349];
350
354if ( !$wgLocalFileRepo ) {
356 'class' => LocalRepo::class,
357 'name' => 'local',
358 'directory' => $wgUploadDirectory,
359 'scriptDirUrl' => $wgScriptPath,
361 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
362 'thumbScriptUrl' => $wgThumbnailScriptPath,
363 'transformVia404' => !$wgGenerateThumbnailOnParse,
364 'deletedDir' => $wgDeletedDirectory,
365 'deletedHashLevels' => $wgHashedUploadDirectory ? 3 : 0,
366 'updateCompatibleMetadata' => $wgUpdateCompatibleMetadata,
367 'reserializeMetadata' => $wgUpdateCompatibleMetadata,
368 ];
369}
370
371if ( !isset( $wgLocalFileRepo['backend'] ) ) {
372 // Create a default FileBackend name.
373 // FileBackendGroup will register a default, if absent from $wgFileBackends.
374 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
375}
376
380if ( $wgUseSharedUploads ) {
381 if ( $wgSharedUploadDBname ) {
383 'class' => ForeignDBRepo::class,
384 'name' => 'shared',
385 'directory' => $wgSharedUploadDirectory,
386 'url' => $wgSharedUploadPath,
387 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
388 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
389 'transformVia404' => !$wgGenerateThumbnailOnParse,
390 'dbType' => $wgDBtype,
391 'dbServer' => $wgDBserver,
392 'dbUser' => $wgDBuser,
393 'dbPassword' => $wgDBpassword,
394 'dbName' => $wgSharedUploadDBname,
395 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
396 'tablePrefix' => $wgSharedUploadDBprefix,
397 'hasSharedCache' => $wgCacheSharedUploads,
398 'descBaseUrl' => $wgRepositoryBaseUrl,
399 'fetchDescription' => $wgFetchCommonsDescriptions,
400 ];
401 } else {
403 'class' => FileRepo::class,
404 'name' => 'shared',
405 'directory' => $wgSharedUploadDirectory,
406 'url' => $wgSharedUploadPath,
407 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
408 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
409 'transformVia404' => !$wgGenerateThumbnailOnParse,
410 'descBaseUrl' => $wgRepositoryBaseUrl,
411 'fetchDescription' => $wgFetchCommonsDescriptions,
412 ];
413 }
414}
417 'class' => ForeignAPIRepo::class,
418 'name' => 'wikimediacommons',
419 'apibase' => 'https://commons.wikimedia.org/w/api.php',
420 'url' => 'https://upload.wikimedia.org/wikipedia/commons',
421 'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
422 'hashLevels' => 2,
423 'transformVia404' => true,
424 'fetchDescription' => true,
425 'descriptionCacheExpiry' => 43200,
426 'apiThumbCacheExpiry' => 0,
427 ];
428}
429foreach ( $wgForeignFileRepos as &$repo ) {
430 if ( !isset( $repo['directory'] ) && $repo['class'] === ForeignAPIRepo::class ) {
431 $repo['directory'] = $wgUploadDirectory; // b/c
432 }
433 if ( !isset( $repo['backend'] ) ) {
434 $repo['backend'] = $repo['name'] . '-backend';
435 }
436}
437unset( $repo ); // no global pollution; destroy reference
438
439$rcMaxAgeDays = $wgRCMaxAge / ( 3600 * 24 );
440// Ensure that default user options are not invalid, since that breaks Special:Preferences
441$wgDefaultUserOptions['rcdays'] = min(
442 $wgDefaultUserOptions['rcdays'],
443 ceil( $rcMaxAgeDays )
444);
445$wgDefaultUserOptions['watchlistdays'] = min(
446 $wgDefaultUserOptions['watchlistdays'],
447 ceil( $rcMaxAgeDays )
448);
449unset( $rcMaxAgeDays );
450
451if ( !$wgCookiePrefix ) {
452 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
454 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
456 } elseif ( $wgDBprefix ) {
458 } else {
460 }
461}
462$wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
463
464if ( $wgEnableEmail ) {
466} else {
467 // Disable all other email settings automatically if $wgEnableEmail
468 // is set to false. - T65678
469 $wgAllowHTMLEmail = false;
470 $wgEmailAuthentication = false; // do not require auth if you're not sending email anyway
480 unset( $wgGroupPermissions['user']['sendemail'] );
484}
485
486if ( $wgLocaltimezone === null ) {
487 // This defaults to the `date.timezone` value of the PHP INI option. If this option is not set,
488 // it falls back to UTC. Prior to PHP 7.0, this fallback produced a warning.
489 $wgLocaltimezone = date_default_timezone_get();
490}
491date_default_timezone_set( $wgLocaltimezone );
492if ( $wgLocalTZoffset === null ) {
493 $wgLocalTZoffset = (int)date( 'Z' ) / 60;
494}
495// The part after the System| is ignored, but rest of MW fills it out as the local offset.
496$wgDefaultUserOptions['timecorrection'] = "System|$wgLocalTZoffset";
497
498if ( !$wgDBerrorLogTZ ) {
500}
501
506$wgCanonicalNamespaceNames = NamespaceInfo::CANONICAL_NAMES;
507
508// @todo UGLY UGLY
509if ( is_array( $wgExtraNamespaces ) ) {
511}
512
513// Hard-deprecate setting $wgDummyLanguageCodes in LocalSettings.php
514if ( count( $wgDummyLanguageCodes ) !== 0 ) {
515 wfDeprecated( '$wgDummyLanguageCodes', '1.29' );
516}
517// Merge in the legacy language codes, incorporating overrides from the config
519 // Internal language codes of the private-use area which get mapped to
520 // themselves.
521 'qqq' => 'qqq', // Used for message documentation
522 'qqx' => 'qqx', // Used for viewing message keys
523] + $wgExtraLanguageCodes + LanguageCode::getDeprecatedCodeMapping();
524// Merge in (inverted) BCP 47 mappings
525foreach ( LanguageCode::getNonstandardLanguageCodeMapping() as $code => $bcp47 ) {
526 $bcp47 = strtolower( $bcp47 ); // force case-insensitivity
527 if ( !isset( $wgDummyLanguageCodes[$bcp47] ) ) {
528 $wgDummyLanguageCodes[$bcp47] = $wgDummyLanguageCodes[$code] ?? $code;
529 }
530}
531unset( $code ); // no global pollution; destroy reference
532unset( $bcp47 ); // no global pollution; destroy reference
533
534// Temporary backwards-compatibility reading of old replica lag settings as of MediaWiki 1.36,
535// to support sysadmins who fail to update their settings immediately:
536
537if ( isset( $wgSlaveLagWarning ) ) {
538 // If the old value is set to something other than the default, use it.
539 if ( $wgDatabaseReplicaLagWarning === 10 && $wgSlaveLagWarning !== 10 ) {
540 $wgDatabaseReplicaLagWarning = $wgSlaveLagWarning;
542 '$wgSlaveLagWarning set but $wgDatabaseReplicaLagWarning unchanged; using $wgSlaveLagWarning',
543 '1.36'
544 );
545 }
546} else {
547 // Backwards-compatibility for extensions that read this value.
548 $wgSlaveLagWarning = $wgDatabaseReplicaLagWarning;
549}
550
551if ( isset( $wgSlaveLagCritical ) ) {
552 // If the old value is set to something other than the default, use it.
553 if ( $wgDatabaseReplicaLagCritical === 30 && $wgSlaveLagCritical !== 30 ) {
554 $wgDatabaseReplicaLagCritical = $wgSlaveLagCritical;
556 '$wgSlaveLagCritical set but $wgDatabaseReplicaLagCritical unchanged; using $wgSlaveLagCritical',
557 '1.36'
558 );
559 }
560} else {
561 // Backwards-compatibility for extensions that read this value.
562 $wgSlaveLagCritical = $wgDatabaseReplicaLagCritical;
563}
564
566 Wikimedia\suppressWarnings();
567 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', filemtime( "$IP/LocalSettings.php" ) ) );
568 Wikimedia\restoreWarnings();
569}
570
571if ( $wgNewUserLog ) {
572 // Add new user log type
573 $wgLogTypes[] = 'newusers';
574 $wgLogNames['newusers'] = 'newuserlogpage';
575 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
576 $wgLogActionsHandlers['newusers/newusers'] = NewUsersLogFormatter::class;
577 $wgLogActionsHandlers['newusers/create'] = NewUsersLogFormatter::class;
578 $wgLogActionsHandlers['newusers/create2'] = NewUsersLogFormatter::class;
579 $wgLogActionsHandlers['newusers/byemail'] = NewUsersLogFormatter::class;
580 $wgLogActionsHandlers['newusers/autocreate'] = NewUsersLogFormatter::class;
581}
582
583if ( $wgPageCreationLog ) {
584 // Add page creation log type
585 $wgLogTypes[] = 'create';
586 $wgLogActionsHandlers['create/create'] = LogFormatter::class;
587}
588
590 $wgLogTypes[] = 'pagelang';
591 $wgLogActionsHandlers['pagelang/pagelang'] = PageLangLogFormatter::class;
592}
593
594if ( $wgCookieSecure === 'detect' ) {
596}
597
598// Backwards compatibility with old password limits
599if ( $wgMinimalPasswordLength !== false ) {
600 $wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = $wgMinimalPasswordLength;
601}
602
603if ( $wgMaximalPasswordLength !== false ) {
604 $wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] = $wgMaximalPasswordLength;
605}
606
607if ( $wgPHPSessionHandling !== 'enable' &&
608 $wgPHPSessionHandling !== 'warn' &&
609 $wgPHPSessionHandling !== 'disable'
610) {
611 $wgPHPSessionHandling = 'warn';
612}
613if ( defined( 'MW_NO_SESSION' ) ) {
614 // If the entry point wants no session, force 'disable' here unless they
615 // specifically set it to the (undocumented) 'warn'.
616 $wgPHPSessionHandling = MW_NO_SESSION === 'warn' ? 'warn' : 'disable';
617}
618
620
621// Enable the global service locator.
622// Trivial expansion of site configuration should go before this point.
623// Any non-trivial expansion that requires calling into MediaWikiServices or other parts of MW.
624MediaWikiServices::allowGlobalInstance();
625
626// Define a constant that indicates that the bootstrapping of the service locator
627// is complete.
628define( 'MW_SERVICE_BOOTSTRAP_COMPLETE', 1 );
629
630MWExceptionHandler::installHandler();
631
632// Non-trivial validation of: $wgServer
633// The FatalError page only renders cleanly after MWExceptionHandler is installed.
634if ( $wgServer === false ) {
635 // T30798: $wgServer must be explicitly set
636 throw new FatalError(
637 '$wgServer must be set in LocalSettings.php. ' .
638 'See <a href="https://www.mediawiki.org/wiki/Manual:$wgServer">' .
639 'https://www.mediawiki.org/wiki/Manual:$wgServer</a>.'
640 );
641}
642
643// Non-trivial expansion of: $wgCanonicalServer, $wgServerName.
644// These require calling global functions.
645// Also here are other settings that further depend on these two.
646if ( $wgCanonicalServer === false ) {
648}
650
652if ( $wgServerName !== false ) {
653 wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
654 . 'not customized. Overwriting $wgServerName.' );
655}
657unset( $serverParts );
658
659// $wgEmergencyContact and $wgPasswordSender may be false or empty string (T104142)
660if ( !$wgEmergencyContact ) {
661 $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
662}
663if ( !$wgPasswordSender ) {
664 $wgPasswordSender = 'apache@' . $wgServerName;
665}
666if ( !$wgNoReplyAddress ) {
668}
669
670// Non-trivial expansion of: $wgSecureLogin
671// (due to calling wfWarn).
672if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
673 $wgSecureLogin = false;
674 wfWarn( 'Secure login was enabled on a server that only supports '
675 . 'HTTP or HTTPS. Disabling secure login.' );
676}
677
678// Now that GlobalFunctions is loaded, set defaults that depend on it.
679if ( $wgTmpDirectory === false ) {
681}
682
684 // Apply $wgSharedDB table aliases for the local LB (all non-foreign DB connections)
685 MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
686 array_fill_keys(
688 [
689 'dbname' => $wgSharedDB,
690 'schema' => $wgSharedSchema,
691 'prefix' => $wgSharedPrefix
692 ]
693 )
694 );
695}
696
697// Raise the memory limit if it's too low
698// NOTE: This use wfDebug, and must remain after the MWDebug::setup() call.
700
701// Initialize the request object in $wgRequest
702$wgRequest = RequestContext::getMain()->getRequest(); // BackCompat
703
704// Make sure that object caching does not undermine the ChronologyProtector improvements
705if ( $wgRequest->getCookie( 'UseDC', '' ) === 'master' ) {
706 // The user is pinned to the primary DC, meaning that they made recent changes which should
707 // be reflected in their subsequent web requests. Avoid the use of interim cache keys because
708 // they use a blind TTL and could be stale if an object changes twice in a short time span.
709 MediaWikiServices::getInstance()->getMainWANObjectCache()->useInterimHoldOffCaching( false );
710}
711
712// Useful debug output
713( static function () {
715 $logger = LoggerFactory::getInstance( 'wfDebug' );
716 if ( $wgCommandLineMode ) {
717 $self = $_SERVER['PHP_SELF'] ?? '';
718 $logger->debug( "\n\nStart command line script $self" );
719 } else {
720 $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
721 $debug .= "IP: " . $wgRequest->getIP() . "\n";
722 $debug .= "HTTP HEADERS:\n";
723 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
724 $debug .= "$name: $value\n";
725 }
726 $debug .= "(end headers)";
727 $logger->debug( $debug );
728 }
729} )();
730
731// Most of the config is out, some might want to run hooks here.
732Hooks::runner()->onSetupAfterCache();
733
734// Now that variant lists may be available, parse any action paths and article paths
735// as query parameters.
736//
737// Skip title interpolation on API queries where it is useless and sometimes harmful (T18019).
738//
739// Optimization: Skip on load.php and all other entrypoints besides index.php to save time.
740//
741// TODO: Figure out if this can be safely done after everything else in Setup.php (e.g. any
742// hooks or other state that would miss this?). If so, move to wfIndexMain or MediaWiki::run.
743if ( MW_ENTRY_POINT === 'index' ) {
744 $wgRequest->interpolateTitle();
745}
746
751if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
752 // If session.auto_start is there, we can't touch session name
753 if ( $wgPHPSessionHandling !== 'disable' && !wfIniGetBool( 'session.auto_start' ) ) {
754 HeaderCallback::warnIfHeadersSent();
755 session_name( $wgSessionName ?: $wgCookiePrefix . '_session' );
756 }
757
758 // Create the SessionManager singleton and set up our session handler,
759 // unless we're specifically asked not to.
760 if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
761 MediaWiki\Session\PHPSessionHandler::install(
762 MediaWiki\Session\SessionManager::singleton()
763 );
764 }
765
766 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
767
768 // Initialize the session
769 try {
770 $session = MediaWiki\Session\SessionManager::getGlobalSession();
771 } catch ( MediaWiki\Session\SessionOverflowException $ex ) {
772 // The exception is because the request had multiple possible
773 // sessions tied for top priority. Report this to the user.
774 $list = [];
775 foreach ( $ex->getSessionInfos() as $info ) {
776 $list[] = $info->getProvider()->describe( $contLang );
777 }
778 $list = $contLang->listToText( $list );
779 throw new HttpError( 400,
780 Message::newFromKey( 'sessionmanager-tie', $list )->inLanguage( $contLang )
781 );
782 }
783
784 unset( $contLang );
785
786 if ( $session->isPersistent() ) {
787 $wgInitialSessionId = $session->getSessionId();
788 }
789
790 $session->renew();
791 if ( MediaWiki\Session\PHPSessionHandler::isEnabled() &&
792 ( $session->isPersistent() || $session->shouldRememberUser() ) &&
793 session_id() !== $session->getId()
794 ) {
795 // Start the PHP-session for backwards compatibility
796 if ( session_id() !== '' ) {
797 wfDebugLog( 'session', 'PHP session {old_id} was already started, changing to {new_id}', 'all', [
798 'old_id' => session_id(),
799 'new_id' => $session->getId(),
800 ] );
801 session_write_close();
802 }
803 session_id( $session->getId() );
804 session_start();
805 }
806
807 unset( $session );
808} else {
809 // Even if we didn't set up a global Session, still install our session
810 // handler unless specifically requested not to.
811 if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
812 MediaWiki\Session\PHPSessionHandler::install(
813 MediaWiki\Session\SessionManager::singleton()
814 );
815 }
816}
817
823$wgUser = new StubGlobalUser( RequestContext::getMain()->getUser() ); // BackCompat
824register_shutdown_function( static function () {
826} );
827
832
836$wgOut = RequestContext::getMain()->getOutput(); // BackCompat
837
842$wgParser = new DeprecatedGlobal( 'wgParser', static function () {
843 return MediaWikiServices::getInstance()->getParser();
844}, '1.32' );
845
849$wgTitle = null;
850
851// Extension setup functions
852// Entries should be added to this variable during the inclusion
853// of the extension file. This allows the extension to perform
854// any necessary initialisation in the fully initialised environment
855foreach ( $wgExtensionFunctions as $func ) {
856 call_user_func( $func );
857}
858unset( $func ); // no global pollution; destroy reference
859
860// If the session user has a 0 id but a valid name, that means we need to
861// autocreate it.
862if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
863 $sessionUser = MediaWiki\Session\SessionManager::getGlobalSession()->getUser();
864 if ( $sessionUser->getId() === 0 &&
865 MediaWikiServices::getInstance()->getUserNameUtils()->isValid( $sessionUser->getName() )
866 ) {
867 $res = MediaWikiServices::getInstance()->getAuthManager()->autoCreateUser(
868 $sessionUser,
869 MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_SESSION,
870 true
871 );
872 \MediaWiki\Logger\LoggerFactory::getInstance( 'authevents' )->info( 'Autocreation attempt', [
873 'event' => 'autocreate',
874 'status' => strval( $res ),
875 ] );
876 unset( $res );
877 }
878 unset( $sessionUser );
879}
880
881if ( !$wgCommandLineMode ) {
883}
884
886
887// T264370
888if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
889 MediaWiki\Session\SessionManager::singleton()->logPotentialSessionLeakage();
890}
$wgProhibitedFileExtensions
Files with these extensions will never be allowed as uploads.
$wgRightsIcon
Override for copyright metadata.
$wgCacheEpoch
Set this to current time to invalidate all prior cached pages.
bool $wgPageLanguageUseDB
Enable page language feature Allows setting page language in database.
string $wgSharedUploadDirectory
Shortcut for the 'directory' setting of $wgForeignFileRepos.
$wgUsePathInfo
Whether to support URLs like index.php/Page_title These often break when PHP is set up in CGI mode.
$wgMemoryLimit
The minimum amount of memory that MediaWiki "needs"; MediaWiki will try to raise PHP's memory limit i...
$wgEmergencyContact
Site admin email address.
$wgDBprefix
Current wiki database table name prefix.
$wgDBuser
Database username.
$wgUpdateCompatibleMetadata
Shortcut for the 'updateCompatibleMetadata' setting of $wgLocalFileRepo.
string $wgPHPSessionHandling
Whether to use PHP session handling ($_SESSION and session_*() functions)
bool $wgCacheSharedUploads
Shortcut for the ForeignDBRepo 'hasSharedCache' setting in $wgForeignFileRepos.
bool string $wgSharedUploadDBname
Shortcut for the ForeignDBRepo 'dbName' setting in $wgForeignFileRepos.
$wgScript
The URL path to index.php.
$wgUseInstantCommons
Use Wikimedia Commons as a foreign file repository.
$wgEnableUserEmailMuteList
Set to true to enable user-to-user e-mail mutelist.
bool $wgHashedSharedUploadDirectory
Shortcut for the 'hashLevels' setting of $wgForeignFileRepos.
$wgCacheDirectory
Directory for caching data in the local filesystem.
$wgRightsUrl
Set this to specify an external URL containing details about the content license used on your wiki.
$wgSharedTables
$wgSessionName
Override to customise the session name.
$wgMainCacheType
Main cache type.
$wgPasswordPolicy
Password policy for the wiki.
$wgLogNames
Lists the message key string for each log type.
$wgInvalidateCacheOnLocalSettingsChange
Invalidate various caches when LocalSettings.php changes.
$wgLocalStylePath
The URL path of the skins directory.
$wgThumbnailScriptPath
Give a path here to use thumb.php for thumbnail generation on client request, instead of generating t...
$wgExtraNamespaces
Additional namespaces.
$wgTmpDirectory
The local filesystem path to a temporary directory.
bool $wgGenerateThumbnailOnParse
Render thumbnails while parsing wikitext.
bool $wgUseSharedUploads
Shortcut for adding an entry to $wgForeignFileRepos.
string $wgSharedUploadDBprefix
Shortcut for the ForeignDBRepo 'tablePrefix' setting in $wgForeignFileRepos.
$wgDBtype
Database type.
$wgDBmwschema
Current wiki database schema name.
$wgNoReplyAddress
Reply-To address for e-mail notifications.
$wgDBname
Current wiki database name.
$wgDBerrorLogTZ
Timezone to use in the error log.
$wgUploadDirectory
The filesystem path of the images directory.
$wgLogTypes
The logging system has two levels: an event type, which describes the general category and can be vie...
$wgMaximalPasswordLength
Specifies the maximal length of a user password (T64685).
$wgSitename
Name of the site.
$wgShortPagesNamespaceExclusions
Optional array of namespaces which should be excluded from Special:ShortPages.
$wgReadOnlyFile
If this lock file exists (size > 0), the wiki will be forced into read-only mode.
$wgFileCacheDirectory
Directory where the cached page will be saved.
$wgRightsText
If either $wgRightsUrl or $wgRightsPage is specified then this variable gives the text for the link.
$wgGitInfoCacheDirectory
Directory where GitInfo will look for pre-computed cache files.
$wgPageCreationLog
Maintain a log of page creations at Special:Log/create?
$wgDatabaseReplicaLagCritical
$wgResourceBasePath
The default 'remoteBasePath' value for instances of ResourceLoaderFileModule.
$wgFooterIcons
Abstract list of footer icons for skins in place of old copyrightico and poweredbyico code You can ad...
$wgArticlePath
The URL path for primary article page views.
$wgUploadPath
The URL path for the images directory.
$wgEnableEmail
Set to true to enable the e-mail basic features: Password reminders, etc.
$wgExtensionFunctions
A list of callback functions which are called once MediaWiki is fully initialised.
$wgShellLocale
Locale for LC_ALL, to provide a known environment for locale-sensitive operations.
$wgSecureLogin
This is to let user authenticate using https when they come from http.
$wgRCMaxAge
Recentchanges items are periodically purged; entries older than this many seconds will go.
bool $wgHashedUploadDirectory
Shortcut for setting hashLevels=2 in $wgLocalFileRepo.
$wgLocaltimezone
Fake out the timezone that the server thinks it's in.
$wgUploadBaseUrl
If set, this URL is added to the start of $wgUploadPath to form a complete upload URL.
bool $wgFetchCommonsDescriptions
Shortcut for the 'fetchDescription' setting of $wgForeignFileRepos.
$wgGroupPermissions
Permission keys given to users in each group.
$wgRestPath
The URL path to the REST API Defaults to "{$wgScriptPath}/rest.php".
string $wgSharedThumbnailScriptPath
Shortcut for the 'thumbScriptUrl' setting of $wgForeignFileRepos.
$wgLocalFileRepo
File repository structures.
$wgDeletedDirectory
What directory to place deleted uploads in.
$wgScriptPath
The path we should point to.
$wgWANObjectCaches
Advanced WAN object cache configuration.
$wgAllowHTMLEmail
For parts of the system that have been updated to provide HTML email content, send both text and HTML...
array false $wgLogos
Specification for different versions of the wiki logo.
$wgExtensionAssetsPath
The URL path of the extensions directory.
$wgForeignFileRepos
Enable the use of files from one or more other wikis.
$wgRepositoryBaseUrl
Shortcut for the 'descBaseUrl' setting of $wgForeignFileRepos.
$wgLogHeaders
Lists the message key string for descriptive text to be shown at the top of each log type.
int null $wgRequestTimeLimit
Set a limit on server request wall clock time.
$wgSharedDB
Shared database for multiple wikis.
$wgDebugDumpSql
Write SQL queries to the debug log.
$wgDatabaseReplicaLagWarning
If lag is higher than $wgDatabaseReplicaLagWarning, show a warning in some special pages (like watchl...
$wgDBserver
Database host name or IP address.
bool $wgForceHTTPS
If this is true, when an insecure HTTP request is received, always redirect to HTTPS.
$wgLoadScript
The URL path to load.php.
$wgCookieSecure
Whether the "secure" flag should be set on the cookie.
$wgMimeTypeExclusions
Files with these MIME types will never be allowed as uploads if $wgVerifyMimeType is enabled.
$wgExtraLanguageCodes
List of mappings from one language code to another.
$wgCanonicalServer
Canonical URL of the server, to use in IRC feeds and notification e-mails.
$wgStylePath
The URL path of the skins directory.
$wgServer
URL of the server.
$wgMinimalPasswordLength
Specifies the minimal length of a user password.
$wgMetaNamespace
Name of the project namespace.
$wgLogo
The URL path of the wiki logo.
$wgSharedSchema
$wgPasswordSender
Sender email address for e-mail notifications.
$wgLogActionsHandlers
The same as above, but here values are names of classes, not messages.
string $wgSharedUploadPath
Shortcut for the 'url' setting of $wgForeignFileRepos.
$wgLocalTZoffset
Set an offset from UTC in minutes to use for the default timezone setting for anonymous users and new...
$wgSharedPrefix
$wgMainWANCache
Main Wide-Area-Network cache type.
$wgDBpassword
Database user's password.
$wgNewUserLog
Maintain a log of newusers at Special:Log/newusers?
const NS_MEDIAWIKI
Definition Defines.php:72
const PROTO_HTTP
Definition Defines.php:192
global $wgCommandLineMode
wfParseUrl( $url)
parse_url() work-alike, but non-broken.
wfTempDir()
Tries to get the system directory for temporary files.
wfWarn( $msg, $callerOffset=1, $level=E_USER_NOTICE)
Send a warning either to the debug log or in a PHP error depending on $wgDevelopmentWarnings.
wfMemoryLimit( $newLimit)
Raise PHP's memory limit (if needed).
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
$wgGalleryOptions
Default parameters for the "<gallery>" tag.
Definition Setup.php:341
$wgRequest
Definition Setup.php:702
$wgFileExtensions
Definition Setup.php:281
if(is_array($wgExtraNamespaces)) if(count( $wgDummyLanguageCodes) !==0) $wgDummyLanguageCodes
Definition Setup.php:518
$wgEnotifWatchlist
Definition Setup.php:479
$wgEnotifMaxRecips
Definition Setup.php:474
$wgEnotifUserTalk
Definition Setup.php:478
$wgEnableUserEmail
Definition Setup.php:471
$rcMaxAgeDays
Definition Setup.php:439
$wgOut
Definition Setup.php:836
$wgParser
Definition Setup.php:842
if(!defined('MW_NO_SESSION') &&! $wgCommandLineMode) if(! $wgCommandLineMode) $wgFullyInitialised
Definition Setup.php:885
$wgEnotifFromEditor
Definition Setup.php:472
$wgUseEnotif
Definition Setup.php:481
$wgEnotifRevealEditorAddress
Definition Setup.php:476
if(!defined( 'MEDIAWIKI')) $wgScopeTest
Environment checks.
Definition Setup.php:72
if(! $wgCookiePrefix) $wgCookiePrefix
Definition Setup.php:462
$serverParts
Definition Setup.php:651
if(MW_ENTRY_POINT==='index') MediaWiki Session SessionId null $wgInitialSessionId
The persistent session ID (if any) loaded at startup.
Definition Setup.php:750
$wgEnotifImpersonal
Definition Setup.php:473
$wgUsersNotifiedOnAllChanges
Definition Setup.php:483
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:322
$wgUserEmailUseReplyTo
Definition Setup.php:482
if(! $wgDBerrorLogTZ) $wgCanonicalNamespaceNames
Definitions of the NS_ constants are in Defines.php.
Definition Setup.php:506
$wgLang
Definition Setup.php:831
if( $wgServerName !==false) $wgServerName
Definition Setup.php:656
$wgEnotifMinorEdits
Definition Setup.php:475
$wgLockManagers[]
Initialise $wgLockManagers to include basic FS version.
Definition Setup.php:327
$wgDefaultUserOptions['rcdays']
Definition Setup.php:441
$wgTitle
Definition Setup.php:849
$wgEmailAuthentication
Definition Setup.php:470
if($wgServer===false) if( $wgCanonicalServer===false) $wgVirtualRestConfig['global']['domain']
Definition Setup.php:649
$wgEnotifUseRealName
Definition Setup.php:477
const MW_ENTRY_POINT
Definition api.php:41
Class to allow throwing wfDeprecated warnings when people use globals that we do not want them to.
Abort the web request with a custom HTML string that will represent the entire response.
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
Definition Hooks.php:173
Show an error that looks like an HTTP server error.
Definition HttpError.php:32
static setup()
Definition MWDebug.php:78
PSR-3 logger instance factory.
MediaWikiServices is the service locator for the application scope of MediaWiki.
static newFromKey( $key,... $params)
Factory function that is just wrapper for the real constructor.
Definition Message.php:396
static schedulePingback()
Schedule a deferred callable that will check if a pingback should be sent and (if so) proceed to send...
Definition Pingback.php:290
Stub object for the global user ($wgUser) that makes it possible to change the relevant underlying ob...
static bool $destructorDeprecationDisarmed
Stub object for the user language.
static detectProtocol()
Detect the protocol from $_SERVER.
const MW_CONFIG_CALLBACK
Definition install.php:28
const MW_NO_SESSION
Definition load.php:32
$debug
Definition mcc.php:31
A helper class for throttling authentication attempts.
const DBO_DEFAULT
Definition defines.php:13
const DBO_DEBUG
Definition defines.php:9