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
28 * This file is not a valid entry point, perform no further processing unless
29 * MEDIAWIKI is defined
31 if ( !defined( 'MEDIAWIKI' ) ) {
36 $ps_setup = Profiler
::instance()->scopedProfileIn( $fname );
38 // If any extensions are still queued, force load them
39 ExtensionRegistry
::getInstance()->loadFromQueue();
41 // Check to see if we are at the file scope
42 if ( !isset( $wgVersion ) ) {
43 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
47 // Set various default paths sensibly...
48 $ps_default = Profiler
::instance()->scopedProfileIn( $fname . '-defaults' );
50 if ( $wgScript === false ) {
51 $wgScript = "$wgScriptPath/index.php";
53 if ( $wgLoadScript === false ) {
54 $wgLoadScript = "$wgScriptPath/load.php";
57 if ( $wgArticlePath === false ) {
58 if ( $wgUsePathInfo ) {
59 $wgArticlePath = "$wgScript/$1";
61 $wgArticlePath = "$wgScript?title=$1";
65 if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
66 // 'view' is assumed the default action path everywhere in the code
67 // but is rarely filled in $wgActionPaths
68 $wgActionPaths['view'] = $wgArticlePath;
71 if ( $wgResourceBasePath === null ) {
72 $wgResourceBasePath = $wgScriptPath;
74 if ( $wgStylePath === false ) {
75 $wgStylePath = "$wgResourceBasePath/skins";
77 if ( $wgLocalStylePath === false ) {
78 // Avoid wgResourceBasePath here since that may point to a different domain (e.g. CDN)
79 $wgLocalStylePath = "$wgScriptPath/skins";
81 if ( $wgExtensionAssetsPath === false ) {
82 $wgExtensionAssetsPath = "$wgResourceBasePath/extensions";
85 if ( $wgLogo === false ) {
86 $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
89 if ( $wgUploadPath === false ) {
90 $wgUploadPath = "$wgScriptPath/images";
92 if ( $wgUploadDirectory === false ) {
93 $wgUploadDirectory = "$IP/images";
95 if ( $wgReadOnlyFile === false ) {
96 $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
98 if ( $wgFileCacheDirectory === false ) {
99 $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
101 if ( $wgDeletedDirectory === false ) {
102 $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
105 if ( $wgGitInfoCacheDirectory === false && $wgCacheDirectory !== false ) {
106 $wgGitInfoCacheDirectory = "{$wgCacheDirectory}/gitinfo";
109 if ( $wgEnableParserCache === false ) {
110 $wgParserCacheType = CACHE_NONE
;
113 // Fix path to icon images after they were moved in 1.24
114 if ( $wgRightsIcon ) {
115 $wgRightsIcon = str_replace(
116 "{$wgStylePath}/common/images/",
117 "{$wgResourceBasePath}/resources/assets/licenses/",
122 if ( isset( $wgFooterIcons['copyright']['copyright'] )
123 && $wgFooterIcons['copyright']['copyright'] === []
125 if ( $wgRightsIcon ||
$wgRightsText ) {
126 $wgFooterIcons['copyright']['copyright'] = [
127 'url' => $wgRightsUrl,
128 'src' => $wgRightsIcon,
129 'alt' => $wgRightsText,
134 if ( isset( $wgFooterIcons['poweredby'] )
135 && isset( $wgFooterIcons['poweredby']['mediawiki'] )
136 && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
138 $wgFooterIcons['poweredby']['mediawiki']['src'] =
139 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png";
140 $wgFooterIcons['poweredby']['mediawiki']['srcset'] =
141 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png 1.5x, " .
142 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png 2x";
146 * Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a
147 * sysadmin to set $wgNamespaceProtection incorrectly and leave the wiki insecure.
149 * Note that this is the definition of editinterface and it can be granted to
150 * all users if desired.
152 $wgNamespaceProtection[NS_MEDIAWIKI
] = 'editinterface';
155 * The canonical names of namespaces 6 and 7 are, as of v1.14, "File"
156 * and "File_talk". The old names "Image" and "Image_talk" are
157 * retained as aliases for backwards compatibility.
159 $wgNamespaceAliases['Image'] = NS_FILE
;
160 $wgNamespaceAliases['Image_talk'] = NS_FILE_TALK
;
163 * Initialise $wgLockManagers to include basic FS version
165 $wgLockManagers[] = [
166 'name' => 'fsLockManager',
167 'class' => 'FSLockManager',
168 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
170 $wgLockManagers[] = [
171 'name' => 'nullLockManager',
172 'class' => 'NullLockManager',
176 * Initialise $wgLocalFileRepo from backwards-compatible settings
178 if ( !$wgLocalFileRepo ) {
180 'class' => 'LocalRepo',
182 'directory' => $wgUploadDirectory,
183 'scriptDirUrl' => $wgScriptPath,
184 'scriptExtension' => '.php',
185 'url' => $wgUploadBaseUrl ?
$wgUploadBaseUrl . $wgUploadPath : $wgUploadPath,
186 'hashLevels' => $wgHashedUploadDirectory ?
2 : 0,
187 'thumbScriptUrl' => $wgThumbnailScriptPath,
188 'transformVia404' => !$wgGenerateThumbnailOnParse,
189 'deletedDir' => $wgDeletedDirectory,
190 'deletedHashLevels' => $wgHashedUploadDirectory ?
3 : 0
194 * Initialise shared repo from backwards-compatible settings
196 if ( $wgUseSharedUploads ) {
197 if ( $wgSharedUploadDBname ) {
198 $wgForeignFileRepos[] = [
199 'class' => 'ForeignDBRepo',
201 'directory' => $wgSharedUploadDirectory,
202 'url' => $wgSharedUploadPath,
203 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
204 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
205 'transformVia404' => !$wgGenerateThumbnailOnParse,
206 'dbType' => $wgDBtype,
207 'dbServer' => $wgDBserver,
208 'dbUser' => $wgDBuser,
209 'dbPassword' => $wgDBpassword,
210 'dbName' => $wgSharedUploadDBname,
211 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG
: 0 ) | DBO_DEFAULT
,
212 'tablePrefix' => $wgSharedUploadDBprefix,
213 'hasSharedCache' => $wgCacheSharedUploads,
214 'descBaseUrl' => $wgRepositoryBaseUrl,
215 'fetchDescription' => $wgFetchCommonsDescriptions,
218 $wgForeignFileRepos[] = [
219 'class' => 'FileRepo',
221 'directory' => $wgSharedUploadDirectory,
222 'url' => $wgSharedUploadPath,
223 'hashLevels' => $wgHashedSharedUploadDirectory ?
2 : 0,
224 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
225 'transformVia404' => !$wgGenerateThumbnailOnParse,
226 'descBaseUrl' => $wgRepositoryBaseUrl,
227 'fetchDescription' => $wgFetchCommonsDescriptions,
231 if ( $wgUseInstantCommons ) {
232 $wgForeignFileRepos[] = [
233 'class' => 'ForeignAPIRepo',
234 'name' => 'wikimediacommons',
235 'apibase' => 'https://commons.wikimedia.org/w/api.php',
236 'url' => 'https://upload.wikimedia.org/wikipedia/commons',
237 'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
239 'transformVia404' => true,
240 'fetchDescription' => true,
241 'descriptionCacheExpiry' => 43200,
242 'apiThumbCacheExpiry' => 86400,
246 * Add on default file backend config for file repos.
247 * FileBackendGroup will handle initializing the backends.
249 if ( !isset( $wgLocalFileRepo['backend'] ) ) {
250 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
252 foreach ( $wgForeignFileRepos as &$repo ) {
253 if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
254 $repo['directory'] = $wgUploadDirectory; // b/c
256 if ( !isset( $repo['backend'] ) ) {
257 $repo['backend'] = $repo['name'] . '-backend';
260 unset( $repo ); // no global pollution; destroy reference
262 $rcMaxAgeDays = $wgRCMaxAge / ( 3600 * 24 );
263 if ( $wgRCFilterByAge ) {
264 // Trim down $wgRCLinkDays so that it only lists links which are valid
265 // as determined by $wgRCMaxAge.
266 // Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
267 sort( $wgRCLinkDays );
269 // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
270 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++
) {
271 // @codingStandardsIgnoreEnd
272 if ( $wgRCLinkDays[$i] >= $rcMaxAgeDays ) {
273 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i +
1, false );
278 // Ensure that default user options are not invalid, since that breaks Special:Preferences
279 $wgDefaultUserOptions['rcdays'] = min(
280 $wgDefaultUserOptions['rcdays'],
281 ceil( $rcMaxAgeDays )
283 $wgDefaultUserOptions['watchlistdays'] = min(
284 $wgDefaultUserOptions['watchlistdays'],
285 ceil( $rcMaxAgeDays )
287 unset( $rcMaxAgeDays );
290 $wgSkipSkins[] = $wgSkipSkin;
294 // Use a closure to avoid leaking into global state
295 call_user_func( function () use ( $wgValidSkinNames ) {
296 $factory = SkinFactory
::getDefaultInstance();
297 foreach ( $wgValidSkinNames as $name => $skin ) {
298 $factory->register( $name, $skin, function () use ( $name, $skin ) {
299 $class = "Skin$skin";
300 return new $class( $name );
303 // Register a hidden "fallback" skin
304 $factory->register( 'fallback', 'Fallback', function () {
305 return new SkinFallback
;
307 // Register a hidden skin for api output
308 $factory->register( 'apioutput', 'ApiOutput', function () {
312 $wgSkipSkins[] = 'fallback';
313 $wgSkipSkins[] = 'apioutput';
315 if ( $wgLocalInterwiki ) {
316 array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
319 // Set default shared prefix
320 if ( $wgSharedPrefix === false ) {
321 $wgSharedPrefix = $wgDBprefix;
324 // Set default shared schema
325 if ( $wgSharedSchema === false ) {
326 $wgSharedSchema = $wgDBmwschema;
329 if ( !$wgCookiePrefix ) {
330 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
331 $wgCookiePrefix = $wgSharedDB . '_' . $wgSharedPrefix;
332 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
333 $wgCookiePrefix = $wgSharedDB;
334 } elseif ( $wgDBprefix ) {
335 $wgCookiePrefix = $wgDBname . '_' . $wgDBprefix;
337 $wgCookiePrefix = $wgDBname;
340 $wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
342 if ( $wgEnableEmail ) {
343 $wgUseEnotif = $wgEnotifUserTalk ||
$wgEnotifWatchlist;
345 // Disable all other email settings automatically if $wgEnableEmail
346 // is set to false. - bug 63678
347 $wgAllowHTMLEmail = false;
348 $wgEmailAuthentication = false; // do not require auth if you're not sending email anyway
349 $wgEnableUserEmail = false;
350 $wgEnotifFromEditor = false;
351 $wgEnotifImpersonal = false;
352 $wgEnotifMaxRecips = 0;
353 $wgEnotifMinorEdits = false;
354 $wgEnotifRevealEditorAddress = false;
355 $wgEnotifUseRealName = false;
356 $wgEnotifUserTalk = false;
357 $wgEnotifWatchlist = false;
358 unset( $wgGroupPermissions['user']['sendemail'] );
359 $wgUseEnotif = false;
360 $wgUserEmailUseReplyTo = false;
361 $wgUsersNotifiedOnAllChanges = [];
364 if ( $wgMetaNamespace === false ) {
365 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
368 // Default value is 2000 or the suhosin limit if it is between 1 and 2000
369 if ( $wgResourceLoaderMaxQueryLength === false ) {
370 $suhosinMaxValueLength = (int)ini_get( 'suhosin.get.max_value_length' );
371 if ( $suhosinMaxValueLength > 0 && $suhosinMaxValueLength < 2000 ) {
372 $wgResourceLoaderMaxQueryLength = $suhosinMaxValueLength;
374 $wgResourceLoaderMaxQueryLength = 2000;
376 unset( $suhosinMaxValueLength );
379 // Ensure the minimum chunk size is less than PHP upload limits or the maximum
381 $wgMinUploadChunkSize = min(
382 $wgMinUploadChunkSize,
383 UploadBase
::getMaxUploadSize( 'file' ),
384 UploadBase
::getMaxPhpUploadSize(),
385 ( wfShorthandToInteger(
386 ini_get( 'post_max_size' ) ?
: ini_get( 'hhvm.server.max_post_size' ),
388 ) ?
: PHP_INT_MAX
) - 1024 // Leave some room for other POST parameters
392 * Definitions of the NS_ constants are in Defines.php
395 $wgCanonicalNamespaceNames = [
397 NS_SPECIAL
=> 'Special',
400 NS_USER_TALK
=> 'User_talk',
401 NS_PROJECT
=> 'Project',
402 NS_PROJECT_TALK
=> 'Project_talk',
404 NS_FILE_TALK
=> 'File_talk',
405 NS_MEDIAWIKI
=> 'MediaWiki',
406 NS_MEDIAWIKI_TALK
=> 'MediaWiki_talk',
407 NS_TEMPLATE
=> 'Template',
408 NS_TEMPLATE_TALK
=> 'Template_talk',
410 NS_HELP_TALK
=> 'Help_talk',
411 NS_CATEGORY
=> 'Category',
412 NS_CATEGORY_TALK
=> 'Category_talk',
416 if ( is_array( $wgExtraNamespaces ) ) {
417 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames +
$wgExtraNamespaces;
420 // These are now the same, always
421 // To determine the user language, use $wgLang->getCode()
422 $wgContLanguageCode = $wgLanguageCode;
424 // Easy to forget to falsify $wgDebugToolbar for static caches.
425 // If file cache or CDN cache is on, just disable this (DWIMD).
426 if ( $wgUseFileCache ||
$wgUseSquid ) {
427 $wgDebugToolbar = false;
430 // We always output HTML5 since 1.22, overriding these is no longer supported
431 // we set them here for extensions that depend on its value.
433 $wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
434 $wgJsMimeType = 'text/javascript';
436 // Blacklisted file extensions shouldn't appear on the "allowed" list
437 $wgFileExtensions = array_values( array_diff( $wgFileExtensions, $wgFileBlacklist ) );
439 if ( $wgInvalidateCacheOnLocalSettingsChange ) {
440 MediaWiki\
suppressWarnings();
441 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', filemtime( "$IP/LocalSettings.php" ) ) );
442 MediaWiki\restoreWarnings
();
445 if ( $wgNewUserLog ) {
446 // Add a new log type
447 $wgLogTypes[] = 'newusers';
448 $wgLogNames['newusers'] = 'newuserlogpage';
449 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
450 $wgLogActionsHandlers['newusers/newusers'] = 'NewUsersLogFormatter';
451 $wgLogActionsHandlers['newusers/create'] = 'NewUsersLogFormatter';
452 $wgLogActionsHandlers['newusers/create2'] = 'NewUsersLogFormatter';
453 $wgLogActionsHandlers['newusers/byemail'] = 'NewUsersLogFormatter';
454 $wgLogActionsHandlers['newusers/autocreate'] = 'NewUsersLogFormatter';
457 if ( $wgPageLanguageUseDB ) {
458 $wgLogTypes[] = 'pagelang';
459 $wgLogActionsHandlers['pagelang/pagelang'] = 'PageLangLogFormatter';
462 if ( $wgCookieSecure === 'detect' ) {
463 $wgCookieSecure = ( WebRequest
::detectProtocol() === 'https' );
466 if ( $wgProfileOnly ) {
467 $wgDebugLogGroups['profileoutput'] = $wgDebugLogFile;
468 $wgDebugLogFile = '';
471 // Backwards compatibility with old password limits
472 if ( $wgMinimalPasswordLength !== false ) {
473 $wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = $wgMinimalPasswordLength;
476 if ( $wgMaximalPasswordLength !== false ) {
477 $wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] = $wgMaximalPasswordLength;
480 // Backwards compatibility warning
481 if ( !$wgSessionsInObjectCache && !$wgSessionsInMemcached ) {
482 wfDeprecated( '$wgSessionsInObjectCache = false', '1.27' );
483 if ( $wgSessionHandler ) {
484 wfDeprecated( '$wgSessionsHandler', '1.27' );
486 $cacheType = get_class( ObjectCache
::getInstance( $wgSessionCacheType ) );
489 "Session data will be stored in \"$cacheType\" cache with " .
490 "expiry $wgObjectCacheSessionExpiry seconds"
493 $wgSessionsInObjectCache = true;
495 if ( $wgPHPSessionHandling !== 'enable' &&
496 $wgPHPSessionHandling !== 'warn' &&
497 $wgPHPSessionHandling !== 'disable'
499 $wgPHPSessionHandling = 'warn';
501 if ( defined( 'MW_NO_SESSION' ) ) {
502 // If the entry point wants no session, force 'disable' here unless they
503 // specifically set it to the (undocumented) 'warn'.
504 $wgPHPSessionHandling = MW_NO_SESSION
=== 'warn' ?
'warn' : 'disable';
507 Profiler
::instance()->scopedProfileOut( $ps_default );
509 // Disable MWDebug for command line mode, this prevents MWDebug from eating up
510 // all the memory from logging SQL queries on maintenance scripts
511 global $wgCommandLineMode;
512 if ( $wgDebugToolbar && !$wgCommandLineMode ) {
516 if ( !class_exists( 'AutoLoader' ) ) {
517 require_once "$IP/includes/AutoLoader.php";
520 // Install a header callback to prevent caching of responses with cookies (T127993)
521 if ( !$wgCommandLineMode ) {
522 header_register_callback( function () {
524 foreach ( headers_list() as $header ) {
525 list( $name, $value ) = explode( ':', $header, 2 );
526 $headers[strtolower( trim( $name ) )][] = trim( $value );
529 if ( isset( $headers['set-cookie'] ) ) {
530 $cacheControl = isset( $headers['cache-control'] )
531 ?
implode( ', ', $headers['cache-control'] )
534 if ( !preg_match( '/(?:^|,)\s*(?:private|no-cache|no-store)\s*(?:$|,)/i', $cacheControl ) ) {
535 header( 'Expires: Thu, 01 Jan 1970 00:00:00 GMT' );
536 header( 'Cache-Control: private, max-age=0, s-maxage=0' );
537 MediaWiki\Logger\LoggerFactory
::getInstance( 'cache-cookies' )->warning(
538 'Cookies set on {url} with Cache-Control "{cache-control}"', [
539 'url' => WebRequest
::getGlobalRequestURL(),
540 'cookies' => $headers['set-cookie'],
541 'cache-control' => $cacheControl ?
: '<not set>',
549 MWExceptionHandler
::installHandler();
551 require_once "$IP/includes/compat/normal/UtfNormalUtil.php";
553 $ps_validation = Profiler
::instance()->scopedProfileIn( $fname . '-validation' );
555 // T48998: Bail out early if $wgArticlePath is non-absolute
556 foreach ( [ 'wgArticlePath', 'wgVariantArticlePath' ] as $varName ) {
557 if ( $
$varName && !preg_match( '/^(https?:\/\/|\/)/', $
$varName ) ) {
558 throw new FatalError(
559 "If you use a relative URL for \$$varName, it must start " .
560 'with a slash (<code>/</code>).<br><br>See ' .
561 "<a href=\"https://www.mediawiki.org/wiki/Manual:\$$varName\">" .
562 "https://www.mediawiki.org/wiki/Manual:\$$varName</a>."
567 Profiler
::instance()->scopedProfileOut( $ps_validation );
569 $ps_default2 = Profiler
::instance()->scopedProfileIn( $fname . '-defaults2' );
571 if ( $wgCanonicalServer === false ) {
572 $wgCanonicalServer = wfExpandUrl( $wgServer, PROTO_HTTP
);
576 $serverParts = wfParseUrl( $wgCanonicalServer );
577 if ( $wgServerName !== false ) {
578 wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
579 . 'not customized. Overwriting $wgServerName.' );
581 $wgServerName = $serverParts['host'];
582 unset( $serverParts );
584 // Set defaults for configuration variables
585 // that are derived from the server name by default
586 // Note: $wgEmergencyContact and $wgPasswordSender may be false or empty string (T104142)
587 if ( !$wgEmergencyContact ) {
588 $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
590 if ( !$wgPasswordSender ) {
591 $wgPasswordSender = 'apache@' . $wgServerName;
593 if ( !$wgNoReplyAddress ) {
594 $wgNoReplyAddress = $wgPasswordSender;
597 if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
598 $wgSecureLogin = false;
599 wfWarn( 'Secure login was enabled on a server that only supports '
600 . 'HTTP or HTTPS. Disabling secure login.' );
603 $wgVirtualRestConfig['global']['domain'] = $wgCanonicalServer;
605 // Now that GlobalFunctions is loaded, set defaults that depend on it.
606 if ( $wgTmpDirectory === false ) {
607 $wgTmpDirectory = wfTempDir();
610 // We don't use counters anymore. Left here for extensions still
611 // expecting this to exist. Should be removed sometime 1.26 or later.
612 if ( !isset( $wgDisableCounters ) ) {
613 $wgDisableCounters = true;
616 if ( $wgMainWANCache === false ) {
617 // Setup a WAN cache from $wgMainCacheType with no relayer.
618 // Sites using multiple datacenters can configure a relayer.
619 $wgMainWANCache = 'mediawiki-main-default';
620 $wgWANObjectCaches[$wgMainWANCache] = [
621 'class' => 'WANObjectCache',
622 'cacheId' => $wgMainCacheType,
623 'pool' => 'mediawiki-main-default',
624 'relayerConfig' => [ 'class' => 'EventRelayerNull' ]
628 Profiler
::instance()->scopedProfileOut( $ps_default2 );
630 $ps_misc = Profiler
::instance()->scopedProfileIn( $fname . '-misc1' );
632 // Raise the memory limit if it's too low
636 * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
637 * that happens whenever you use a date function without the timezone being
638 * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
640 if ( is_null( $wgLocaltimezone ) ) {
641 MediaWiki\
suppressWarnings();
642 $wgLocaltimezone = date_default_timezone_get();
643 MediaWiki\restoreWarnings
();
646 date_default_timezone_set( $wgLocaltimezone );
647 if ( is_null( $wgLocalTZoffset ) ) {
648 $wgLocalTZoffset = date( 'Z' ) / 60;
651 if ( !$wgDBerrorLogTZ ) {
652 $wgDBerrorLogTZ = $wgLocaltimezone;
655 // initialize the request object in $wgRequest
656 $wgRequest = RequestContext
::getMain()->getRequest(); // BackCompat
658 // Useful debug output
659 if ( $wgCommandLineMode ) {
660 wfDebug( "\n\nStart command line script $self\n" );
662 $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
664 if ( $wgDebugPrintHttpHeaders ) {
665 $debug .= "HTTP HEADERS:\n";
667 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
668 $debug .= "$name: $value\n";
674 Profiler
::instance()->scopedProfileOut( $ps_misc );
675 $ps_memcached = Profiler
::instance()->scopedProfileIn( $fname . '-memcached' );
677 $wgMemc = wfGetMainCache();
678 $messageMemc = wfGetMessageCacheStorage();
679 $parserMemc = wfGetParserCacheStorage();
681 wfDebugLog( 'caches',
682 'cluster: ' . get_class( $wgMemc ) .
683 ', WAN: ' . $wgMainWANCache .
684 ', stash: ' . $wgMainStash .
685 ', message: ' . get_class( $messageMemc ) .
686 ', parser: ' . get_class( $parserMemc ) );
688 Profiler
::instance()->scopedProfileOut( $ps_memcached );
690 // Most of the config is out, some might want to run hooks here.
691 Hooks
::run( 'SetupAfterCache' );
693 $ps_globals = Profiler
::instance()->scopedProfileIn( $fname . '-globals' );
696 * @var Language $wgContLang
698 $wgContLang = Language
::factory( $wgLanguageCode );
699 $wgContLang->initEncoding();
700 $wgContLang->initContLang();
702 // Now that variant lists may be available...
703 $wgRequest->interpolateTitle();
705 if ( !is_object( $wgAuth ) ) {
706 $wgAuth = new AuthPlugin
;
707 Hooks
::run( 'AuthPluginSetup', [ &$wgAuth ] );
710 // Set up the session
711 $ps_session = Profiler
::instance()->scopedProfileIn( $fname . '-session' );
713 * @var MediaWiki\Session\SessionId|null $wgInitialSessionId The persistent
714 * session ID (if any) loaded at startup
716 $wgInitialSessionId = null;
717 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
718 // If session.auto_start is there, we can't touch session name
719 if ( $wgPHPSessionHandling !== 'disable' && !wfIniGetBool( 'session.auto_start' ) ) {
720 session_name( $wgSessionName ?
$wgSessionName : $wgCookiePrefix . '_session' );
723 // Create the SessionManager singleton and set up our session handler,
724 // unless we're specifically asked not to.
725 if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
726 MediaWiki\Session\PHPSessionHandler
::install(
727 MediaWiki\Session\SessionManager
::singleton()
731 // Initialize the session
733 $session = MediaWiki\Session\SessionManager
::getGlobalSession();
734 } catch ( OverflowException
$ex ) {
735 if ( isset( $ex->sessionInfos
) && count( $ex->sessionInfos
) >= 2 ) {
736 // The exception is because the request had multiple possible
737 // sessions tied for top priority. Report this to the user.
739 foreach ( $ex->sessionInfos
as $info ) {
740 $list[] = $info->getProvider()->describe( $wgContLang );
742 $list = $wgContLang->listToText( $list );
743 throw new HttpError( 400,
744 Message
::newFromKey( 'sessionmanager-tie', $list )->inLanguage( $wgContLang )->plain()
748 // Not the one we want, rethrow
752 if ( $session->isPersistent() ) {
753 $wgInitialSessionId = $session->getSessionId();
757 if ( MediaWiki\Session\PHPSessionHandler
::isEnabled() &&
758 ( $session->isPersistent() ||
$session->shouldRememberUser() )
760 // Start the PHP-session for backwards compatibility
761 session_id( $session->getId() );
762 MediaWiki\
quietCall( 'session_start' );
767 // Even if we didn't set up a global Session, still install our session
768 // handler unless specifically requested not to.
769 if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
770 MediaWiki\Session\PHPSessionHandler
::install(
771 MediaWiki\Session\SessionManager
::singleton()
775 Profiler
::instance()->scopedProfileOut( $ps_session );
780 $wgUser = RequestContext
::getMain()->getUser(); // BackCompat
783 * @var Language $wgLang
785 $wgLang = new StubUserLang
;
788 * @var OutputPage $wgOut
790 $wgOut = RequestContext
::getMain()->getOutput(); // BackCompat
793 * @var Parser $wgParser
795 $wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] );
798 * @var Title $wgTitle
802 Profiler
::instance()->scopedProfileOut( $ps_globals );
803 $ps_extensions = Profiler
::instance()->scopedProfileIn( $fname . '-extensions' );
805 // Extension setup functions
806 // Entries should be added to this variable during the inclusion
807 // of the extension file. This allows the extension to perform
808 // any necessary initialisation in the fully initialised environment
809 foreach ( $wgExtensionFunctions as $func ) {
810 // Allow closures in PHP 5.3+
811 if ( is_object( $func ) && $func instanceof Closure
) {
812 $profName = $fname . '-extensions-closure';
813 } elseif ( is_array( $func ) ) {
814 if ( is_object( $func[0] ) ) {
815 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
817 $profName = $fname . '-extensions-' . implode( '::', $func );
820 $profName = $fname . '-extensions-' . strval( $func );
823 $ps_ext_func = Profiler
::instance()->scopedProfileIn( $profName );
824 call_user_func( $func );
825 Profiler
::instance()->scopedProfileOut( $ps_ext_func );
828 // If the session user has a 0 id but a valid name, that means we need to
830 if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
831 $sessionUser = MediaWiki\Session\SessionManager
::getGlobalSession()->getUser();
832 if ( $sessionUser->getId() === 0 && User
::isValidUserName( $sessionUser->getName() ) ) {
833 $ps_autocreate = Profiler
::instance()->scopedProfileIn( $fname . '-autocreate' );
834 MediaWiki\Session\SessionManager
::autoCreateUser( $sessionUser );
835 Profiler
::instance()->scopedProfileOut( $ps_autocreate );
837 unset( $sessionUser );
840 wfDebug( "Fully initialised\n" );
841 $wgFullyInitialised = true;
843 Profiler
::instance()->scopedProfileOut( $ps_extensions );
844 Profiler
::instance()->scopedProfileOut( $ps_setup );