3 * Include most things that are needed to make MediaWiki work.
5 * This file is included by WebStart.php and doMaintenance.php so that both
6 * web and maintenance scripts share a final set up phase to include necessary
7 * files and create global object variables.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
26 use MediaWiki\MediaWikiServices
;
29 * This file is not a valid entry point, perform no further processing unless
30 * MEDIAWIKI is defined
32 if ( !defined( 'MEDIAWIKI' ) ) {
37 $ps_setup = Profiler
::instance()->scopedProfileIn( $fname );
39 // Load queued extensions
40 ExtensionRegistry
::getInstance()->loadFromQueue();
41 // Don't let any other extensions load
42 ExtensionRegistry
::getInstance()->finish();
44 // Check to see if we are at the file scope
45 if ( !isset( $wgVersion ) ) {
46 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
50 mb_internal_encoding( 'UTF-8' );
52 // Set the configured locale on all requests for consisteny
53 putenv( "LC_ALL=$wgShellLocale" );
54 setlocale( LC_ALL
, $wgShellLocale );
56 // Set various default paths sensibly...
57 $ps_default = Profiler
::instance()->scopedProfileIn( $fname . '-defaults' );
59 if ( $wgScript === false ) {
60 $wgScript = "$wgScriptPath/index.php";
62 if ( $wgLoadScript === false ) {
63 $wgLoadScript = "$wgScriptPath/load.php";
66 if ( $wgArticlePath === false ) {
67 if ( $wgUsePathInfo ) {
68 $wgArticlePath = "$wgScript/$1";
70 $wgArticlePath = "$wgScript?title=$1";
74 if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
75 // 'view' is assumed the default action path everywhere in the code
76 // but is rarely filled in $wgActionPaths
77 $wgActionPaths['view'] = $wgArticlePath;
80 if ( $wgResourceBasePath === null ) {
81 $wgResourceBasePath = $wgScriptPath;
83 if ( $wgStylePath === false ) {
84 $wgStylePath = "$wgResourceBasePath/skins";
86 if ( $wgLocalStylePath === false ) {
87 // Avoid wgResourceBasePath here since that may point to a different domain (e.g. CDN)
88 $wgLocalStylePath = "$wgScriptPath/skins";
90 if ( $wgExtensionAssetsPath === false ) {
91 $wgExtensionAssetsPath = "$wgResourceBasePath/extensions";
94 if ( $wgLogo === false ) {
95 $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
98 if ( $wgUploadPath === false ) {
99 $wgUploadPath = "$wgScriptPath/images";
101 if ( $wgUploadDirectory === false ) {
102 $wgUploadDirectory = "$IP/images";
104 if ( $wgReadOnlyFile === false ) {
105 $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
107 if ( $wgFileCacheDirectory === false ) {
108 $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
110 if ( $wgDeletedDirectory === false ) {
111 $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
114 if ( $wgGitInfoCacheDirectory === false && $wgCacheDirectory !== false ) {
115 $wgGitInfoCacheDirectory = "{$wgCacheDirectory}/gitinfo";
118 if ( $wgEnableParserCache === false ) {
119 $wgParserCacheType = CACHE_NONE
;
122 // Fix path to icon images after they were moved in 1.24
123 if ( $wgRightsIcon ) {
124 $wgRightsIcon = str_replace(
125 "{$wgStylePath}/common/images/",
126 "{$wgResourceBasePath}/resources/assets/licenses/",
131 if ( isset( $wgFooterIcons['copyright']['copyright'] )
132 && $wgFooterIcons['copyright']['copyright'] === []
134 if ( $wgRightsIcon ||
$wgRightsText ) {
135 $wgFooterIcons['copyright']['copyright'] = [
136 'url' => $wgRightsUrl,
137 'src' => $wgRightsIcon,
138 'alt' => $wgRightsText,
143 if ( isset( $wgFooterIcons['poweredby'] )
144 && isset( $wgFooterIcons['poweredby']['mediawiki'] )
145 && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
147 $wgFooterIcons['poweredby']['mediawiki']['src'] =
148 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png";
149 $wgFooterIcons['poweredby']['mediawiki']['srcset'] =
150 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png 1.5x, " .
151 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png 2x";
155 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
156 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
158 * Note that this is the definition of editinterface and it can be granted to
159 * all users if desired.
161 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
164 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
165 * and "File_talk". The old names "Image" and "Image_talk" are
166 * retained as aliases for backwards compatibility.
168 $wgNamespaceAliases['Image'] = NS_FILE
;
169 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
172 * Initialise $wgLockManagers to include basic FS version
174 $wgLockManagers[] = [
175 'name' => 'fsLockManager',
176 'class' => 'FSLockManager',
177 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
179 $wgLockManagers[] = [
180 'name' => 'nullLockManager',
181 'class' => 'NullLockManager',
185 * Default parameters for the "<gallery>" tag.
186 * @see DefaultSettings.php for description of the fields.
188 $wgGalleryOptions +
= [
191 'imageHeight' => 120,
192 'captionLength' => true,
194 'showDimensions' => true,
195 'mode' => 'traditional',
199 * Initialise $wgLocalFileRepo from backwards-compatible settings
201 if ( !$wgLocalFileRepo ) {
203 'class' => 'LocalRepo',
205 'directory' => $wgUploadDirectory,
206 'scriptDirUrl' => $wgScriptPath,
207 'scriptExtension' => '.php',
208 'url' => $wgUploadBaseUrl ?
$wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
209 'hashLevels' => $wgHashedUploadDirectory ?
2 : 0,
210 'thumbScriptUrl' => $wgThumbnailScriptPath,
211 'transformVia404' => !$wgGenerateThumbnailOnParse,
212 'deletedDir' => $wgDeletedDirectory,
213 'deletedHashLevels' => $wgHashedUploadDirectory ?
3 : 0
217 * Initialise shared repo from backwards-compatible settings
219 if ( $wgUseSharedUploads ) {
220 if ( $wgSharedUploadDBname ) {
221 $wgForeignFileRepos[] = [
222 'class' => 'ForeignDBRepo',
224 'directory' => $wgSharedUploadDirectory,
225 'url' => $wgSharedUploadPath,
226 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
227 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
228 'transformVia404' => !$wgGenerateThumbnailOnParse,
229 'dbType' => $wgDBtype,
230 'dbServer' => $wgDBserver,
231 'dbUser' => $wgDBuser,
232 'dbPassword' => $wgDBpassword,
233 'dbName' => $wgSharedUploadDBname,
234 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG
: 0 ) | DBO_DEFAULT
,
235 'tablePrefix' => $wgSharedUploadDBprefix,
236 'hasSharedCache' => $wgCacheSharedUploads,
237 'descBaseUrl' => $wgRepositoryBaseUrl,
238 'fetchDescription' => $wgFetchCommonsDescriptions,
241 $wgForeignFileRepos[] = [
242 'class' => 'FileRepo',
244 'directory' => $wgSharedUploadDirectory,
245 'url' => $wgSharedUploadPath,
246 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
247 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
248 'transformVia404' => !$wgGenerateThumbnailOnParse,
249 'descBaseUrl' => $wgRepositoryBaseUrl,
250 'fetchDescription' => $wgFetchCommonsDescriptions,
254 if ( $wgUseInstantCommons ) {
255 $wgForeignFileRepos[] = [
256 'class' => 'ForeignAPIRepo',
257 'name' => 'wikimediacommons',
258 'apibase' => 'https://commons.wikimedia.org/w/api.php',
259 'url' => 'https://upload.wikimedia.org/wikipedia/commons',
260 'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
262 'transformVia404' => true,
263 'fetchDescription' => true,
264 'descriptionCacheExpiry' => 43200,
265 'apiThumbCacheExpiry' => 0,
269 * Add on default file backend config for file repos.
270 * FileBackendGroup will handle initializing the backends.
272 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
273 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
275 foreach ( $wgForeignFileRepos as &$repo ) {
276 if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
277 $repo['directory'] = $wgUploadDirectory; // b/c
279 if ( !isset( $repo['backend'] ) ) {
280 $repo['backend'] = $repo['name'] . '-backend';
283 unset( $repo ); // no global pollution; destroy reference
285 // Convert this deprecated setting to modern system
286 if ( $wgExperimentalHtmlIds ) {
287 $wgFragmentMode = [ 'html5-legacy', 'legacy' ];
290 $rcMaxAgeDays = $wgRCMaxAge / ( 3600 * 24 );
291 if ( $wgRCFilterByAge ) {
292 // Trim down $wgRCLinkDays so that it only lists links which are valid
293 // as determined by $wgRCMaxAge.
294 // Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
295 sort( $wgRCLinkDays );
297 // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
298 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++
) {
299 // @codingStandardsIgnoreEnd
300 if ( $wgRCLinkDays[$i] >= $rcMaxAgeDays ) {
301 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i +
1, false );
306 // Ensure that default user options are not invalid, since that breaks Special:Preferences
307 $wgDefaultUserOptions['rcdays'] = min(
308 $wgDefaultUserOptions['rcdays'],
309 ceil( $rcMaxAgeDays )
311 $wgDefaultUserOptions['watchlistdays'] = min(
312 $wgDefaultUserOptions['watchlistdays'],
313 ceil( $rcMaxAgeDays )
315 unset( $rcMaxAgeDays );
318 $wgSkipSkins[] = $wgSkipSkin;
321 $wgSkipSkins[] = 'fallback';
322 $wgSkipSkins[] = 'apioutput';
324 if ( $wgLocalInterwiki ) {
325 array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
328 // Set default shared prefix
329 if ( $wgSharedPrefix === false ) {
330 $wgSharedPrefix = $wgDBprefix;
333 // Set default shared schema
334 if ( $wgSharedSchema === false ) {
335 $wgSharedSchema = $wgDBmwschema;
338 if ( !$wgCookiePrefix ) {
339 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
340 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
341 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
342 $wgCookiePrefix = $wgSharedDB;
343 } elseif ( $wgDBprefix ) {
344 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
346 $wgCookiePrefix = $wgDBname;
349 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
351 if ( $wgEnableEmail ) {
352 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
354 // Disable all other email settings automatically if $wgEnableEmail
355 // is set to false. - T65678
356 $wgAllowHTMLEmail = false;
357 $wgEmailAuthentication = false; // do not require auth if you're not sending email anyway
358 $wgEnableUserEmail = false;
359 $wgEnotifFromEditor = false;
360 $wgEnotifImpersonal = false;
361 $wgEnotifMaxRecips = 0;
362 $wgEnotifMinorEdits = false;
363 $wgEnotifRevealEditorAddress = false;
364 $wgEnotifUseRealName = false;
365 $wgEnotifUserTalk = false;
366 $wgEnotifWatchlist = false;
367 unset( $wgGroupPermissions['user']['sendemail'] );
368 $wgUseEnotif = false;
369 $wgUserEmailUseReplyTo = false;
370 $wgUsersNotifiedOnAllChanges = [];
373 if ( $wgMetaNamespace === false ) {
374 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
377 // Default value is 2000 or the suhosin limit if it is between 1 and 2000
378 if ( $wgResourceLoaderMaxQueryLength === false ) {
379 $suhosinMaxValueLength = (int)ini_get( 'suhosin.get.max_value_length' );
380 if ( $suhosinMaxValueLength > 0 && $suhosinMaxValueLength < 2000 ) {
381 $wgResourceLoaderMaxQueryLength = $suhosinMaxValueLength;
383 $wgResourceLoaderMaxQueryLength = 2000;
385 unset( $suhosinMaxValueLength );
388 // Ensure the minimum chunk size is less than PHP upload limits or the maximum
390 $wgMinUploadChunkSize = min(
391 $wgMinUploadChunkSize,
392 UploadBase
::getMaxUploadSize( 'file' ),
393 UploadBase
::getMaxPhpUploadSize(),
394 ( wfShorthandToInteger(
395 ini_get( 'post_max_size' ) ?
: ini_get( 'hhvm.server.max_post_size' ),
397 ) ?
: PHP_INT_MAX
) - 1024 // Leave some room for other POST parameters
401 * Definitions of the NS_ constants are in Defines.php
404 $wgCanonicalNamespaceNames = [
406 NS_SPECIAL
=> 'Special',
409 NS_USER_TALK
=> 'User_talk',
410 NS_PROJECT
=> 'Project',
411 NS_PROJECT_TALK
=> 'Project_talk',
413 NS_FILE_TALK
=> 'File_talk',
414 NS_MEDIAWIKI
=> 'MediaWiki',
415 NS_MEDIAWIKI_TALK
=> 'MediaWiki_talk',
416 NS_TEMPLATE
=> 'Template',
417 NS_TEMPLATE_TALK
=> 'Template_talk',
419 NS_HELP_TALK
=> 'Help_talk',
420 NS_CATEGORY
=> 'Category',
421 NS_CATEGORY_TALK
=> 'Category_talk',
425 if ( is_array( $wgExtraNamespaces ) ) {
426 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames +
$wgExtraNamespaces;
429 // Merge in the legacy language codes, incorporating overrides from the config
430 $wgDummyLanguageCodes +
= [
431 'qqq' => 'qqq', // Used for message documentation
432 'qqx' => 'qqx', // Used for viewing message keys
433 ] +
$wgExtraLanguageCodes + LanguageCode
::getDeprecatedCodeMapping();
435 // These are now the same, always
436 // To determine the user language, use $wgLang->getCode()
437 $wgContLanguageCode = $wgLanguageCode;
439 // Easy to forget to falsify $wgDebugToolbar for static caches.
440 // If file cache or CDN cache is on, just disable this (DWIMD).
441 if ( $wgUseFileCache ||
$wgUseSquid ) {
442 $wgDebugToolbar = false;
445 // We always output HTML5 since 1.22, overriding these is no longer supported
446 // we set them here for extensions that depend on its value.
448 $wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
449 $wgJsMimeType = 'text/javascript';
451 // Blacklisted file extensions shouldn't appear on the "allowed" list
452 $wgFileExtensions = array_values( array_diff( $wgFileExtensions, $wgFileBlacklist ) );
454 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
455 MediaWiki\
suppressWarnings();
456 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', filemtime( "$IP/LocalSettings.php" ) ) );
457 MediaWiki\restoreWarnings
();
460 if ( $wgNewUserLog ) {
461 // Add a new log type
462 $wgLogTypes[] = 'newusers';
463 $wgLogNames['newusers'] = 'newuserlogpage';
464 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
465 $wgLogActionsHandlers['newusers/newusers'] = 'NewUsersLogFormatter';
466 $wgLogActionsHandlers['newusers/create'] = 'NewUsersLogFormatter';
467 $wgLogActionsHandlers['newusers/create2'] = 'NewUsersLogFormatter';
468 $wgLogActionsHandlers['newusers/byemail'] = 'NewUsersLogFormatter';
469 $wgLogActionsHandlers['newusers/autocreate'] = 'NewUsersLogFormatter';
472 if ( $wgPageLanguageUseDB ) {
473 $wgLogTypes[] = 'pagelang';
474 $wgLogActionsHandlers['pagelang/pagelang'] = 'PageLangLogFormatter';
477 if ( $wgCookieSecure === 'detect' ) {
478 $wgCookieSecure = ( WebRequest
::detectProtocol() === 'https' );
481 if ( $wgProfileOnly ) {
482 $wgDebugLogGroups['profileoutput'] = $wgDebugLogFile;
483 $wgDebugLogFile = '';
486 // Backwards compatibility with old password limits
487 if ( $wgMinimalPasswordLength !== false ) {
488 $wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = $wgMinimalPasswordLength;
491 if ( $wgMaximalPasswordLength !== false ) {
492 $wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] = $wgMaximalPasswordLength;
495 // Backwards compatibility warning
496 if ( !$wgSessionsInObjectCache ) {
497 wfDeprecated( '$wgSessionsInObjectCache = false', '1.27' );
498 if ( $wgSessionHandler ) {
499 wfDeprecated( '$wgSessionsHandler', '1.27' );
501 $cacheType = get_class( ObjectCache
::getInstance( $wgSessionCacheType ) );
504 "Session data will be stored in \"$cacheType\" cache with " .
505 "expiry $wgObjectCacheSessionExpiry seconds"
508 $wgSessionsInObjectCache = true;
510 if ( $wgPHPSessionHandling !== 'enable' &&
511 $wgPHPSessionHandling !== 'warn' &&
512 $wgPHPSessionHandling !== 'disable'
514 $wgPHPSessionHandling = 'warn';
516 if ( defined( 'MW_NO_SESSION' ) ) {
517 // If the entry point wants no session, force 'disable' here unless they
518 // specifically set it to the (undocumented) 'warn'.
519 $wgPHPSessionHandling = MW_NO_SESSION
=== 'warn' ?
'warn' : 'disable';
522 Profiler
::instance()->scopedProfileOut( $ps_default );
524 // Disable MWDebug for command line mode, this prevents MWDebug from eating up
525 // all the memory from logging SQL queries on maintenance scripts
526 global $wgCommandLineMode;
527 if ( $wgDebugToolbar && !$wgCommandLineMode ) {
531 // Reset the global service locator, so any services that have already been created will be
532 // re-created while taking into account any custom settings and extensions.
533 MediaWikiServices
::resetGlobalInstance( new GlobalVarConfig(), 'quick' );
535 if ( $wgSharedDB && $wgSharedTables ) {
536 // Apply $wgSharedDB table aliases for the local LB (all non-foreign DB connections)
537 MediaWikiServices
::getInstance()->getDBLoadBalancer()->setTableAliases(
541 'dbname' => $wgSharedDB,
542 'schema' => $wgSharedSchema,
543 'prefix' => $wgSharedPrefix
549 // Define a constant that indicates that the bootstrapping of the service locator
551 define( 'MW_SERVICE_BOOTSTRAP_COMPLETE', 1 );
553 MWExceptionHandler
::installHandler();
555 require_once "$IP/includes/compat/normal/UtfNormalUtil.php";
557 $ps_validation = Profiler
::instance()->scopedProfileIn( $fname . '-validation' );
559 // T48998: Bail out early if $wgArticlePath is non-absolute
560 foreach ( [ 'wgArticlePath', 'wgVariantArticlePath' ] as $varName ) {
561 if ( $
$varName && !preg_match( '/^(https?:\/\/|\/)/', $
$varName ) ) {
562 throw new FatalError(
563 "If you use a relative URL for \$$varName, it must start " .
564 'with a slash (<code>/</code>).<br><br>See ' .
565 "<a href=\"https://www.mediawiki.org/wiki/Manual:\$$varName\">" .
566 "https://www.mediawiki.org/wiki/Manual:\$$varName</a>."
571 Profiler
::instance()->scopedProfileOut( $ps_validation );
573 $ps_default2 = Profiler
::instance()->scopedProfileIn( $fname . '-defaults2' );
575 if ( $wgCanonicalServer === false ) {
576 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP
);
580 $serverParts = wfParseUrl( $wgCanonicalServer );
581 if ( $wgServerName !== false ) {
582 wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
583 . 'not customized. Overwriting $wgServerName.' );
585 $wgServerName = $serverParts['host'];
586 unset( $serverParts );
588 // Set defaults for configuration variables
589 // that are derived from the server name by default
590 // Note: $wgEmergencyContact and $wgPasswordSender may be false or empty string (T104142)
591 if ( !$wgEmergencyContact ) {
592 $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
594 if ( !$wgPasswordSender ) {
595 $wgPasswordSender = 'apache@' . $wgServerName;
597 if ( !$wgNoReplyAddress ) {
598 $wgNoReplyAddress = $wgPasswordSender;
601 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
602 $wgSecureLogin = false;
603 wfWarn( 'Secure login was enabled on a server that only supports '
604 . 'HTTP or HTTPS. Disabling secure login.' );
607 $wgVirtualRestConfig['global']['domain'] = $wgCanonicalServer;
609 // Now that GlobalFunctions is loaded, set defaults that depend on it.
610 if ( $wgTmpDirectory === false ) {
611 $wgTmpDirectory = wfTempDir();
614 // We don't use counters anymore. Left here for extensions still
615 // expecting this to exist. Should be removed sometime 1.26 or later.
616 if ( !isset( $wgDisableCounters ) ) {
617 $wgDisableCounters = true;
620 if ( $wgMainWANCache === false ) {
621 // Setup a WAN cache from $wgMainCacheType with no relayer.
622 // Sites using multiple datacenters can configure a relayer.
623 $wgMainWANCache = 'mediawiki-main-default';
624 $wgWANObjectCaches[$wgMainWANCache] = [
625 'class' => 'WANObjectCache',
626 'cacheId' => $wgMainCacheType,
627 'channels' => [ 'purge' => 'wancache-main-default-purge' ]
631 Profiler
::instance()->scopedProfileOut( $ps_default2 );
633 $ps_misc = Profiler
::instance()->scopedProfileIn( $fname . '-misc1' );
635 // Raise the memory limit if it's too low
639 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
640 * that happens whenever you use a date function without the timezone being
641 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
643 if ( is_null( $wgLocaltimezone ) ) {
644 MediaWiki\
suppressWarnings();
645 $wgLocaltimezone = date_default_timezone_get();
646 MediaWiki\restoreWarnings
();
649 date_default_timezone_set( $wgLocaltimezone );
650 if ( is_null( $wgLocalTZoffset ) ) {
651 $wgLocalTZoffset = date( 'Z' ) / 60;
653 // The part after the System| is ignored, but rest of MW fills it
654 // out as the local offset.
655 $wgDefaultUserOptions['timecorrection'] = "System|$wgLocalTZoffset";
657 if ( !$wgDBerrorLogTZ ) {
658 $wgDBerrorLogTZ = $wgLocaltimezone;
661 // initialize the request object in $wgRequest
662 $wgRequest = RequestContext
::getMain()->getRequest(); // BackCompat
663 // Set user IP/agent information for causal consistency purposes
664 MediaWikiServices
::getInstance()->getDBLoadBalancerFactory()->setRequestInfo( [
665 'IPAddress' => $wgRequest->getIP(),
666 'UserAgent' => $wgRequest->getHeader( 'User-Agent' ),
667 'ChronologyProtection' => $wgRequest->getHeader( 'ChronologyProtection' )
670 // Useful debug output
671 if ( $wgCommandLineMode ) {
672 wfDebug( "\n\nStart command line script $self\n" );
674 $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
676 if ( $wgDebugPrintHttpHeaders ) {
677 $debug .= "HTTP HEADERS:\n";
679 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
680 $debug .= "$name: $value\n";
686 Profiler
::instance()->scopedProfileOut( $ps_misc );
687 $ps_memcached = Profiler
::instance()->scopedProfileIn( $fname . '-memcached' );
689 $wgMemc = wfGetMainCache();
690 $messageMemc = wfGetMessageCacheStorage();
693 * @deprecated since 1.30
695 $parserMemc = new DeprecatedGlobal( 'parserMemc', function () {
696 return MediaWikiServices
::getInstance()->getParserCache()->getCacheStorage();
699 wfDebugLog( 'caches',
700 'cluster: ' . get_class( $wgMemc ) .
701 ', WAN: ' . ( $wgMainWANCache === CACHE_NONE ?
'CACHE_NONE' : $wgMainWANCache ) .
702 ', stash: ' . $wgMainStash .
703 ', message: ' . get_class( $messageMemc ) .
704 ', session: ' . get_class( ObjectCache
::getInstance( $wgSessionCacheType ) )
707 Profiler
::instance()->scopedProfileOut( $ps_memcached );
709 // Most of the config is out, some might want to run hooks here.
710 Hooks
::run( 'SetupAfterCache' );
712 $ps_globals = Profiler
::instance()->scopedProfileIn( $fname . '-globals' );
715 * @var Language $wgContLang
717 $wgContLang = Language
::factory( $wgLanguageCode );
718 $wgContLang->initContLang();
720 // Now that variant lists may be available...
721 $wgRequest->interpolateTitle();
723 if ( !is_object( $wgAuth ) ) {
724 $wgAuth = new MediaWiki\Auth\AuthManagerAuthPlugin
;
725 Hooks
::run( 'AuthPluginSetup', [ &$wgAuth ] );
727 if ( $wgAuth && !$wgAuth instanceof MediaWiki\Auth\AuthManagerAuthPlugin
) {
728 MediaWiki\Auth\AuthManager
::singleton()->forcePrimaryAuthenticationProviders( [
729 new MediaWiki\Auth\
TemporaryPasswordPrimaryAuthenticationProvider( [
730 'authoritative' => false,
732 new MediaWiki\Auth\
AuthPluginPrimaryAuthenticationProvider( $wgAuth ),
733 new MediaWiki\Auth\
LocalPasswordPrimaryAuthenticationProvider( [
734 'authoritative' => true,
736 ], '$wgAuth is ' . get_class( $wgAuth ) );
739 // Set up the session
740 $ps_session = Profiler
::instance()->scopedProfileIn( $fname . '-session' );
742 * @var MediaWiki\Session\SessionId|null $wgInitialSessionId The persistent
743 * session ID (if any) loaded at startup
745 $wgInitialSessionId = null;
746 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
747 // If session.auto_start is there, we can't touch session name
748 if ( $wgPHPSessionHandling !== 'disable' && !wfIniGetBool( 'session.auto_start' ) ) {
749 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
752 // Create the SessionManager singleton and set up our session handler,
753 // unless we're specifically asked not to.
754 if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
755 MediaWiki\Session\PHPSessionHandler
::install(
756 MediaWiki\Session\SessionManager
::singleton()
760 // Initialize the session
762 $session = MediaWiki\Session\SessionManager
::getGlobalSession();
763 } catch ( OverflowException
$ex ) {
764 if ( isset( $ex->sessionInfos
) && count( $ex->sessionInfos
) >= 2 ) {
765 // The exception is because the request had multiple possible
766 // sessions tied for top priority. Report this to the user.
768 foreach ( $ex->sessionInfos
as $info ) {
769 $list[] = $info->getProvider()->describe( $wgContLang );
771 $list = $wgContLang->listToText( $list );
772 throw new HttpError( 400,
773 Message
::newFromKey( 'sessionmanager-tie', $list )->inLanguage( $wgContLang )->plain()
777 // Not the one we want, rethrow
781 if ( $session->isPersistent() ) {
782 $wgInitialSessionId = $session->getSessionId();
786 if ( MediaWiki\Session\PHPSessionHandler
::isEnabled() &&
787 ( $session->isPersistent() ||
$session->shouldRememberUser() )
789 // Start the PHP-session for backwards compatibility
790 session_id( $session->getId() );
791 MediaWiki\
quietCall( 'session_start' );
796 // Even if we didn't set up a global Session, still install our session
797 // handler unless specifically requested not to.
798 if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
799 MediaWiki\Session\PHPSessionHandler
::install(
800 MediaWiki\Session\SessionManager
::singleton()
804 Profiler
::instance()->scopedProfileOut( $ps_session );
809 $wgUser = RequestContext
::getMain()->getUser(); // BackCompat
812 * @var Language $wgLang
814 $wgLang = new StubUserLang
;
817 * @var OutputPage $wgOut
819 $wgOut = RequestContext
::getMain()->getOutput(); // BackCompat
822 * @var Parser $wgParser
824 $wgParser = new StubObject( 'wgParser', function () {
825 return MediaWikiServices
::getInstance()->getParser();
829 * @var Title $wgTitle
833 Profiler
::instance()->scopedProfileOut( $ps_globals );
834 $ps_extensions = Profiler
::instance()->scopedProfileIn( $fname . '-extensions' );
836 // Extension setup functions
837 // Entries should be added to this variable during the inclusion
838 // of the extension file. This allows the extension to perform
839 // any necessary initialisation in the fully initialised environment
840 foreach ( $wgExtensionFunctions as $func ) {
841 // Allow closures in PHP 5.3+
842 if ( is_object( $func ) && $func instanceof Closure
) {
843 $profName = $fname . '-extensions-closure';
844 } elseif ( is_array( $func ) ) {
845 if ( is_object( $func[0] ) ) {
846 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
848 $profName = $fname . '-extensions-' . implode( '::', $func );
851 $profName = $fname . '-extensions-' . strval( $func );
854 $ps_ext_func = Profiler
::instance()->scopedProfileIn( $profName );
855 call_user_func( $func );
856 Profiler
::instance()->scopedProfileOut( $ps_ext_func );
859 // If the session user has a 0 id but a valid name, that means we need to
861 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
862 $sessionUser = MediaWiki\Session\SessionManager
::getGlobalSession()->getUser();
863 if ( $sessionUser->getId() === 0 && User
::isValidUserName( $sessionUser->getName() ) ) {
864 $ps_autocreate = Profiler
::instance()->scopedProfileIn( $fname . '-autocreate' );
865 $res = MediaWiki\Auth\AuthManager
::singleton()->autoCreateUser(
867 MediaWiki\Auth\AuthManager
::AUTOCREATE_SOURCE_SESSION
,
870 Profiler
::instance()->scopedProfileOut( $ps_autocreate );
871 \MediaWiki\Logger\LoggerFactory
::getInstance( 'authevents' )->info( 'Autocreation attempt', [
872 'event' => 'autocreate',
877 unset( $sessionUser );
880 if ( !$wgCommandLineMode ) {
881 Pingback
::schedulePingback();
884 $wgFullyInitialised = true;
886 Profiler
::instance()->scopedProfileOut( $ps_extensions );
887 Profiler
::instance()->scopedProfileOut( $ps_setup );