MediaWiki REL1_30
Setup.php
Go to the documentation of this file.
1<?php
27
32if ( !defined( 'MEDIAWIKI' ) ) {
33 exit( 1 );
34}
35
36$fname = 'Setup.php';
37$ps_setup = Profiler::instance()->scopedProfileIn( $fname );
38
39// Load queued extensions
40ExtensionRegistry::getInstance()->loadFromQueue();
41// Don't let any other extensions load
43
44// Check to see if we are at the file scope
45if ( !isset( $wgVersion ) ) {
46 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
47 die( 1 );
48}
49
50mb_internal_encoding( 'UTF-8' );
51
52// Set the configured locale on all requests for consisteny
53putenv( "LC_ALL=$wgShellLocale" );
54setlocale( LC_ALL, $wgShellLocale );
55
56// Set various default paths sensibly...
57$ps_default = Profiler::instance()->scopedProfileIn( $fname . '-defaults' );
58
59if ( $wgScript === false ) {
60 $wgScript = "$wgScriptPath/index.php";
61}
62if ( $wgLoadScript === false ) {
63 $wgLoadScript = "$wgScriptPath/load.php";
64}
65
66if ( $wgArticlePath === false ) {
67 if ( $wgUsePathInfo ) {
68 $wgArticlePath = "$wgScript/$1";
69 } else {
70 $wgArticlePath = "$wgScript?title=$1";
71 }
72}
73
74if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
75 // 'view' is assumed the default action path everywhere in the code
76 // but is rarely filled in $wgActionPaths
78}
79
80if ( $wgResourceBasePath === null ) {
82}
83if ( $wgStylePath === false ) {
84 $wgStylePath = "$wgResourceBasePath/skins";
85}
86if ( $wgLocalStylePath === false ) {
87 // Avoid wgResourceBasePath here since that may point to a different domain (e.g. CDN)
88 $wgLocalStylePath = "$wgScriptPath/skins";
89}
90if ( $wgExtensionAssetsPath === false ) {
91 $wgExtensionAssetsPath = "$wgResourceBasePath/extensions";
92}
93
94if ( $wgLogo === false ) {
95 $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
96}
97
98if ( $wgUploadPath === false ) {
99 $wgUploadPath = "$wgScriptPath/images";
100}
101if ( $wgUploadDirectory === false ) {
102 $wgUploadDirectory = "$IP/images";
103}
104if ( $wgReadOnlyFile === false ) {
105 $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
106}
107if ( $wgFileCacheDirectory === false ) {
108 $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
109}
110if ( $wgDeletedDirectory === false ) {
111 $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
112}
113
114if ( $wgGitInfoCacheDirectory === false && $wgCacheDirectory !== false ) {
115 $wgGitInfoCacheDirectory = "{$wgCacheDirectory}/gitinfo";
116}
117
118if ( $wgEnableParserCache === false ) {
120}
121
122// Fix path to icon images after they were moved in 1.24
123if ( $wgRightsIcon ) {
124 $wgRightsIcon = str_replace(
125 "{$wgStylePath}/common/images/",
126 "{$wgResourceBasePath}/resources/assets/licenses/",
128 );
129}
130
131if ( isset( $wgFooterIcons['copyright']['copyright'] )
132 && $wgFooterIcons['copyright']['copyright'] === []
133) {
134 if ( $wgRightsIcon || $wgRightsText ) {
135 $wgFooterIcons['copyright']['copyright'] = [
136 'url' => $wgRightsUrl,
137 'src' => $wgRightsIcon,
138 'alt' => $wgRightsText,
139 ];
140 }
141}
142
143if ( isset( $wgFooterIcons['poweredby'] )
144 && isset( $wgFooterIcons['poweredby']['mediawiki'] )
145 && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
146) {
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";
152}
153
162
170
175 'name' => 'fsLockManager',
176 'class' => 'FSLockManager',
177 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
178];
179$wgLockManagers[] = [
180 'name' => 'nullLockManager',
181 'class' => 'NullLockManager',
182];
183
189 'imagesPerRow' => 0,
190 'imageWidth' => 120,
191 'imageHeight' => 120,
192 'captionLength' => true,
193 'showBytes' => true,
194 'showDimensions' => true,
195 'mode' => 'traditional',
196];
197
201if ( !$wgLocalFileRepo ) {
203 'class' => 'LocalRepo',
204 'name' => 'local',
205 'directory' => $wgUploadDirectory,
206 'scriptDirUrl' => $wgScriptPath,
207 'scriptExtension' => '.php',
209 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
210 'thumbScriptUrl' => $wgThumbnailScriptPath,
211 'transformVia404' => !$wgGenerateThumbnailOnParse,
212 'deletedDir' => $wgDeletedDirectory,
213 'deletedHashLevels' => $wgHashedUploadDirectory ? 3 : 0
214 ];
215}
219if ( $wgUseSharedUploads ) {
220 if ( $wgSharedUploadDBname ) {
222 'class' => 'ForeignDBRepo',
223 'name' => 'shared',
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,
239 ];
240 } else {
242 'class' => 'FileRepo',
243 'name' => 'shared',
244 'directory' => $wgSharedUploadDirectory,
245 'url' => $wgSharedUploadPath,
246 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
247 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
248 'transformVia404' => !$wgGenerateThumbnailOnParse,
249 'descBaseUrl' => $wgRepositoryBaseUrl,
250 'fetchDescription' => $wgFetchCommonsDescriptions,
251 ];
252 }
253}
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',
261 'hashLevels' => 2,
262 'transformVia404' => true,
263 'fetchDescription' => true,
264 'descriptionCacheExpiry' => 43200,
265 'apiThumbCacheExpiry' => 0,
266 ];
267}
268/*
269 * Add on default file backend config for file repos.
270 * FileBackendGroup will handle initializing the backends.
271 */
272if ( !isset( $wgLocalFileRepo['backend'] ) ) {
273 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
274}
275foreach ( $wgForeignFileRepos as &$repo ) {
276 if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
277 $repo['directory'] = $wgUploadDirectory; // b/c
278 }
279 if ( !isset( $repo['backend'] ) ) {
280 $repo['backend'] = $repo['name'] . '-backend';
281 }
282}
283unset( $repo ); // no global pollution; destroy reference
284
285// Convert this deprecated setting to modern system
287 $wgFragmentMode = [ 'html5-legacy', 'legacy' ];
288}
289
290$rcMaxAgeDays = $wgRCMaxAge / ( 3600 * 24 );
291if ( $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 );
296
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 );
302 break;
303 }
304 }
305}
306// Ensure that default user options are not invalid, since that breaks Special:Preferences
307$wgDefaultUserOptions['rcdays'] = min(
308 $wgDefaultUserOptions['rcdays'],
309 ceil( $rcMaxAgeDays )
310);
311$wgDefaultUserOptions['watchlistdays'] = min(
312 $wgDefaultUserOptions['watchlistdays'],
313 ceil( $rcMaxAgeDays )
314);
315unset( $rcMaxAgeDays );
316
317if ( $wgSkipSkin ) {
319}
320
321$wgSkipSkins[] = 'fallback';
322$wgSkipSkins[] = 'apioutput';
323
324if ( $wgLocalInterwiki ) {
325 array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
326}
327
328// Set default shared prefix
329if ( $wgSharedPrefix === false ) {
331}
332
333// Set default shared schema
334if ( $wgSharedSchema === false ) {
336}
337
338if ( !$wgCookiePrefix ) {
339 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
341 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
343 } elseif ( $wgDBprefix ) {
345 } else {
347 }
348}
349$wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
350
351if ( $wgEnableEmail ) {
353} else {
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
367 unset( $wgGroupPermissions['user']['sendemail'] );
371}
372
373if ( $wgMetaNamespace === false ) {
374 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
375}
376
377// Default value is 2000 or the suhosin limit if it is between 1 and 2000
378if ( $wgResourceLoaderMaxQueryLength === false ) {
379 $suhosinMaxValueLength = (int)ini_get( 'suhosin.get.max_value_length' );
380 if ( $suhosinMaxValueLength > 0 && $suhosinMaxValueLength < 2000 ) {
381 $wgResourceLoaderMaxQueryLength = $suhosinMaxValueLength;
382 } else {
384 }
385 unset( $suhosinMaxValueLength );
386}
387
388// Ensure the minimum chunk size is less than PHP upload limits or the maximum
389// upload size.
395 ini_get( 'post_max_size' ) ?: ini_get( 'hhvm.server.max_post_size' ),
396 PHP_INT_MAX
397 ) ?: PHP_INT_MAX ) - 1024 // Leave some room for other POST parameters
398);
399
405 NS_MEDIA => 'Media',
406 NS_SPECIAL => 'Special',
407 NS_TALK => 'Talk',
408 NS_USER => 'User',
409 NS_USER_TALK => 'User_talk',
410 NS_PROJECT => 'Project',
411 NS_PROJECT_TALK => 'Project_talk',
412 NS_FILE => 'File',
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',
418 NS_HELP => 'Help',
419 NS_HELP_TALK => 'Help_talk',
420 NS_CATEGORY => 'Category',
421 NS_CATEGORY_TALK => 'Category_talk',
422];
423
425if ( is_array( $wgExtraNamespaces ) ) {
427}
428
429// Merge in the legacy language codes, incorporating overrides from the config
431 'qqq' => 'qqq', // Used for message documentation
432 'qqx' => 'qqx', // Used for viewing message keys
434
435// These are now the same, always
436// To determine the user language, use $wgLang->getCode()
438
439// Easy to forget to falsify $wgDebugToolbar for static caches.
440// If file cache or CDN cache is on, just disable this (DWIMD).
442 $wgDebugToolbar = false;
443}
444
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.
447$wgHtml5 = true;
448$wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
449$wgJsMimeType = 'text/javascript';
450
451// Blacklisted file extensions shouldn't appear on the "allowed" list
452$wgFileExtensions = array_values( array_diff( $wgFileExtensions, $wgFileBlacklist ) );
453
455 MediaWiki\suppressWarnings();
456 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', filemtime( "$IP/LocalSettings.php" ) ) );
457 MediaWiki\restoreWarnings();
458}
459
460if ( $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';
470}
471
473 $wgLogTypes[] = 'pagelang';
474 $wgLogActionsHandlers['pagelang/pagelang'] = 'PageLangLogFormatter';
475}
476
477if ( $wgCookieSecure === 'detect' ) {
479}
480
481if ( $wgProfileOnly ) {
482 $wgDebugLogGroups['profileoutput'] = $wgDebugLogFile;
483 $wgDebugLogFile = '';
484}
485
486// Backwards compatibility with old password limits
487if ( $wgMinimalPasswordLength !== false ) {
488 $wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = $wgMinimalPasswordLength;
489}
490
491if ( $wgMaximalPasswordLength !== false ) {
492 $wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] = $wgMaximalPasswordLength;
493}
494
495// Backwards compatibility warning
497 wfDeprecated( '$wgSessionsInObjectCache = false', '1.27' );
498 if ( $wgSessionHandler ) {
499 wfDeprecated( '$wgSessionsHandler', '1.27' );
500 }
501 $cacheType = get_class( ObjectCache::getInstance( $wgSessionCacheType ) );
503 'caches',
504 "Session data will be stored in \"$cacheType\" cache with " .
505 "expiry $wgObjectCacheSessionExpiry seconds"
506 );
507}
509
510if ( $wgPHPSessionHandling !== 'enable' &&
511 $wgPHPSessionHandling !== 'warn' &&
512 $wgPHPSessionHandling !== 'disable'
513) {
514 $wgPHPSessionHandling = 'warn';
515}
516if ( 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';
520}
521
522Profiler::instance()->scopedProfileOut( $ps_default );
523
524// Disable MWDebug for command line mode, this prevents MWDebug from eating up
525// all the memory from logging SQL queries on maintenance scripts
528 MWDebug::init();
529}
530
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.
533MediaWikiServices::resetGlobalInstance( new GlobalVarConfig(), 'quick' );
534
536 // Apply $wgSharedDB table aliases for the local LB (all non-foreign DB connections)
537 MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
538 array_fill_keys(
540 [
541 'dbname' => $wgSharedDB,
542 'schema' => $wgSharedSchema,
543 'prefix' => $wgSharedPrefix
544 ]
545 )
546 );
547}
548
549// Define a constant that indicates that the bootstrapping of the service locator
550// is complete.
551define( 'MW_SERVICE_BOOTSTRAP_COMPLETE', 1 );
552
553MWExceptionHandler::installHandler();
554
555require_once "$IP/includes/compat/normal/UtfNormalUtil.php";
556
557$ps_validation = Profiler::instance()->scopedProfileIn( $fname . '-validation' );
558
559// T48998: Bail out early if $wgArticlePath is non-absolute
560foreach ( [ '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>."
567 );
568 }
569}
570
571Profiler::instance()->scopedProfileOut( $ps_validation );
572
573$ps_default2 = Profiler::instance()->scopedProfileIn( $fname . '-defaults2' );
574
575if ( $wgCanonicalServer === false ) {
577}
578
579// Set server name
581if ( $wgServerName !== false ) {
582 wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
583 . 'not customized. Overwriting $wgServerName.' );
584}
586unset( $serverParts );
587
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)
591if ( !$wgEmergencyContact ) {
592 $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
593}
594if ( !$wgPasswordSender ) {
595 $wgPasswordSender = 'apache@' . $wgServerName;
596}
597if ( !$wgNoReplyAddress ) {
599}
600
601if ( $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.' );
605}
606
608
609// Now that GlobalFunctions is loaded, set defaults that depend on it.
610if ( $wgTmpDirectory === false ) {
612}
613
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.
616if ( !isset( $wgDisableCounters ) ) {
617 $wgDisableCounters = true;
618}
619
620if ( $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';
625 'class' => 'WANObjectCache',
626 'cacheId' => $wgMainCacheType,
627 'channels' => [ 'purge' => 'wancache-main-default-purge' ]
628 ];
629}
630
631Profiler::instance()->scopedProfileOut( $ps_default2 );
632
633$ps_misc = Profiler::instance()->scopedProfileIn( $fname . '-misc1' );
634
635// Raise the memory limit if it's too low
637
643if ( is_null( $wgLocaltimezone ) ) {
644 MediaWiki\suppressWarnings();
645 $wgLocaltimezone = date_default_timezone_get();
646 MediaWiki\restoreWarnings();
647}
648
649date_default_timezone_set( $wgLocaltimezone );
650if ( is_null( $wgLocalTZoffset ) ) {
651 $wgLocalTZoffset = date( 'Z' ) / 60;
652}
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";
656
657if ( !$wgDBerrorLogTZ ) {
659}
660
661// initialize the request object in $wgRequest
662$wgRequest = RequestContext::getMain()->getRequest(); // BackCompat
663// Set user IP/agent information for causal consistency purposes
664MediaWikiServices::getInstance()->getDBLoadBalancerFactory()->setRequestInfo( [
665 'IPAddress' => $wgRequest->getIP(),
666 'UserAgent' => $wgRequest->getHeader( 'User-Agent' ),
667 'ChronologyProtection' => $wgRequest->getHeader( 'ChronologyProtection' )
668] );
669
670// Useful debug output
671if ( $wgCommandLineMode ) {
672 wfDebug( "\n\nStart command line script $self\n" );
673} else {
674 $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
675
677 $debug .= "HTTP HEADERS:\n";
678
679 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
680 $debug .= "$name: $value\n";
681 }
682 }
683 wfDebug( $debug );
684}
685
686Profiler::instance()->scopedProfileOut( $ps_misc );
687$ps_memcached = Profiler::instance()->scopedProfileIn( $fname . '-memcached' );
688
691
695$parserMemc = new DeprecatedGlobal( 'parserMemc', function () {
696 return MediaWikiServices::getInstance()->getParserCache()->getCacheStorage();
697}, '1.30' );
698
699wfDebugLog( '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 ) )
705);
706
707Profiler::instance()->scopedProfileOut( $ps_memcached );
708
709// Most of the config is out, some might want to run hooks here.
710Hooks::run( 'SetupAfterCache' );
711
712$ps_globals = Profiler::instance()->scopedProfileIn( $fname . '-globals' );
713
717$wgContLang = Language::factory( $wgLanguageCode );
718$wgContLang->initContLang();
719
720// Now that variant lists may be available...
721$wgRequest->interpolateTitle();
722
723if ( !is_object( $wgAuth ) ) {
725 Hooks::run( 'AuthPluginSetup', [ &$wgAuth ] );
726}
727if ( $wgAuth && !$wgAuth instanceof MediaWiki\Auth\AuthManagerAuthPlugin ) {
728 MediaWiki\Auth\AuthManager::singleton()->forcePrimaryAuthenticationProviders( [
729 new MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider( [
730 'authoritative' => false,
731 ] ),
732 new MediaWiki\Auth\AuthPluginPrimaryAuthenticationProvider( $wgAuth ),
733 new MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider( [
734 'authoritative' => true,
735 ] ),
736 ], '$wgAuth is ' . get_class( $wgAuth ) );
737}
738
739// Set up the session
740$ps_session = Profiler::instance()->scopedProfileIn( $fname . '-session' );
746if ( !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' );
750 }
751
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()
757 );
758 }
759
760 // Initialize the session
761 try {
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.
767 $list = [];
768 foreach ( $ex->sessionInfos as $info ) {
769 $list[] = $info->getProvider()->describe( $wgContLang );
770 }
771 $list = $wgContLang->listToText( $list );
772 throw new HttpError( 400,
773 Message::newFromKey( 'sessionmanager-tie', $list )->inLanguage( $wgContLang )->plain()
774 );
775 }
776
777 // Not the one we want, rethrow
778 throw $ex;
779 }
780
781 if ( $session->isPersistent() ) {
782 $wgInitialSessionId = $session->getSessionId();
783 }
784
785 $session->renew();
786 if ( MediaWiki\Session\PHPSessionHandler::isEnabled() &&
787 ( $session->isPersistent() || $session->shouldRememberUser() ) &&
788 session_id() !== $session->getId()
789 ) {
790 // Start the PHP-session for backwards compatibility
791 if ( session_id() !== '' ) {
792 wfDebugLog( 'session', 'PHP session {old_id} was already started, changing to {new_id}', 'all', [
793 'old_id' => session_id(),
794 'new_id' => $session->getId(),
795 ] );
796 session_write_close();
797 }
798 session_id( $session->getId() );
799 session_start();
800 }
801
802 unset( $session );
803} else {
804 // Even if we didn't set up a global Session, still install our session
805 // handler unless specifically requested not to.
806 if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
807 MediaWiki\Session\PHPSessionHandler::install(
808 MediaWiki\Session\SessionManager::singleton()
809 );
810 }
811}
812Profiler::instance()->scopedProfileOut( $ps_session );
813
817$wgUser = RequestContext::getMain()->getUser(); // BackCompat
818
823
827$wgOut = RequestContext::getMain()->getOutput(); // BackCompat
828
832$wgParser = new StubObject( 'wgParser', function () {
833 return MediaWikiServices::getInstance()->getParser();
834} );
835
839$wgTitle = null;
840
841Profiler::instance()->scopedProfileOut( $ps_globals );
842$ps_extensions = Profiler::instance()->scopedProfileIn( $fname . '-extensions' );
843
844// Extension setup functions
845// Entries should be added to this variable during the inclusion
846// of the extension file. This allows the extension to perform
847// any necessary initialisation in the fully initialised environment
848foreach ( $wgExtensionFunctions as $func ) {
849 // Allow closures in PHP 5.3+
850 if ( is_object( $func ) && $func instanceof Closure ) {
851 $profName = $fname . '-extensions-closure';
852 } elseif ( is_array( $func ) ) {
853 if ( is_object( $func[0] ) ) {
854 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
855 } else {
856 $profName = $fname . '-extensions-' . implode( '::', $func );
857 }
858 } else {
859 $profName = $fname . '-extensions-' . strval( $func );
860 }
861
862 $ps_ext_func = Profiler::instance()->scopedProfileIn( $profName );
863 call_user_func( $func );
864 Profiler::instance()->scopedProfileOut( $ps_ext_func );
865}
866
867// If the session user has a 0 id but a valid name, that means we need to
868// autocreate it.
869if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
870 $sessionUser = MediaWiki\Session\SessionManager::getGlobalSession()->getUser();
871 if ( $sessionUser->getId() === 0 && User::isValidUserName( $sessionUser->getName() ) ) {
872 $ps_autocreate = Profiler::instance()->scopedProfileIn( $fname . '-autocreate' );
873 $res = MediaWiki\Auth\AuthManager::singleton()->autoCreateUser(
874 $sessionUser,
875 MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_SESSION,
876 true
877 );
878 Profiler::instance()->scopedProfileOut( $ps_autocreate );
879 \MediaWiki\Logger\LoggerFactory::getInstance( 'authevents' )->info( 'Autocreation attempt', [
880 'event' => 'autocreate',
881 'status' => $res,
882 ] );
883 unset( $res );
884 }
885 unset( $sessionUser );
886}
887
888if ( !$wgCommandLineMode ) {
890}
891
893
894Profiler::instance()->scopedProfileOut( $ps_extensions );
895Profiler::instance()->scopedProfileOut( $ps_setup );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
$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.
$wgUsePathInfo
Whether to support URLs like index.php/Page_title These often break when PHP is set up in CGI mode.
$wgLanguageCode
Site language code.
$wgParserCacheType
The cache type for storing article HTML.
$wgSessionHandler
$wgSharedThumbnailScriptPath
$wgEmergencyContact
Site admin email address.
$wgDBprefix
Table name prefix.
$wgDBuser
Database username.
string $wgPHPSessionHandling
Whether to use PHP session handling ($_SESSION and session_*() functions)
$wgScript
The URL path to index.php.
$wgUseInstantCommons
Use Commons as a remote file repository.
$wgCacheDirectory
Directory for caching data in the local filesystem.
$wgHashedSharedUploadDirectory
Set the following to false especially if you have a set of files that need to be accessible by all wi...
$wgGenerateThumbnailOnParse
Allow thumbnail rendering on page view.
$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.
$wgLocalInterwiki
The interwiki prefix of the current wiki, or false if it doesn't have one.
$wgPasswordPolicy
Password policy for local wiki users.
$wgLogNames
Lists the message key string for each log type.
$wgSharedUploadPath
Full path on the web server where shared uploads can be found.
$wgHashedUploadDirectory
Set this to false if you do not want MediaWiki to divide your images directory into many subdirectori...
$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.
$wgDBtype
Database type.
$wgDBmwschema
Mediawiki schema.
$wgNoReplyAddress
Reply-To address for e-mail notifications.
$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.
$wgSharedUploadDirectory
Path on the file system where shared uploads can be found.
$wgReadOnlyFile
If this lock file exists (size > 0), the wiki will be forced into read-only mode.
$wgResourceLoaderMaxQueryLength
If set to a positive number, ResourceLoader will not generate URLs whose query string is more than th...
$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.
$wgResourceBasePath
The default 'remoteBasePath' value for instances of ResourceLoaderFileModule.
$wgProfileOnly
Don't put non-profiling info into log file.
$wgFooterIcons
Abstract list of footer icons for skins in place of old copyrightico and poweredbyico code You can ad...
$wgUploadPath
The URL path for the images directory.
$wgCacheSharedUploads
Cache shared metadata in memcached.
$wgEnableParserCache
Kept for extension compatibility; see $wgParserCacheType.
$wgFileBlacklist
Files with these extensions will never be allowed as uploads.
$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.
$wgUseSquid
Enable/disable CDN.
$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.
$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.
$wgGroupPermissions
Permission keys given to users in each group.
$wgLocalInterwikis
Array for multiple $wgLocalInterwiki values, in case there are several interwiki prefixes that point ...
$wgVersion
MediaWiki version number.
$wgExperimentalHtmlIds
Abandoned experiment with HTML5-style ID escaping.
$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.
$wgAuth $wgAuth
Authentication plugin.
$wgAllowHTMLEmail
For parts of the system that have been updated to provide HTML email content, send both text and HTML...
$wgFragmentMode
How should section IDs be encoded? This array can contain 1 or 2 elements, each of them can be one of...
$wgSharedUploadDBname
DB name with metadata about shared directory.
$wgMainStash
Main object stash type.
$wgExtensionAssetsPath
The URL path of the extensions directory.
$wgDebugToolbar
Display the new debugging toolbar.
$wgForeignFileRepos
$wgRepositoryBaseUrl
Base URL for a repository wiki.
$wgLogHeaders
Lists the message key string for descriptive text to be shown at the top of each log type.
$wgDebugLogGroups
Map of string log group names to log destinations.
$wgSharedDB
Shared database for multiple wikis.
$wgSessionCacheType
The cache type for storing session data.
$wgSharedUploadDBprefix
Optional table prefix used in database.
$wgDebugDumpSql
Write SQL queries to the debug log.
$wgFetchCommonsDescriptions
Fetch commons image description pages and display them on the local wiki?
$wgDBserver
Database host name or IP address.
$wgLoadScript
The URL path to load.php.
$wgCookieSecure
Whether the "secure" flag should be set on the cookie.
$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.
$wgRCFilterByAge
Filter $wgRCLinkDays by $wgRCMaxAge to avoid showing links for numbers higher than what will be store...
$wgMinimalPasswordLength
Specifies the minimal length of a user password.
$wgMetaNamespace
Name of the project namespace.
$wgLogo
The URL path of the wiki logo.
$wgUseFileCache
This will cache static pages for non-logged-in users to reduce database traffic on public sites.
$wgSharedSchema
$wgDebugLogFile
Filename for debug logging.
$wgPasswordSender
Sender email address for e-mail notifications.
$wgLogActionsHandlers
The same as above, but here values are names of classes, not messages.
$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.
$wgDebugPrintHttpHeaders
Print HTTP headers for every request in the debug information.
$wgUseSharedUploads
If you operate multiple wikis, you can define a shared upload path here.
$wgDBpassword
Database user's password.
$wgRCLinkDays
List of Days options to list in the Special:Recentchanges and Special:Recentchangeslinked pages.
$wgNewUserLog
Maintain a log of newusers at Log/newusers?
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
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.
wfIniGetBool( $setting)
Safety wrapper around ini_get() for boolean settings.
wfGetMessageCacheStorage()
Get the cache object used by the message cache.
wfExpandUrl( $url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
wfGetMainCache()
Get the main cache object.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfShorthandToInteger( $string='', $default=-1)
Converts shorthand byte notation to integer form.
wfMemoryLimit()
Set PHP's memory limit to the larger of php.ini or $wgMemoryLimit.
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Throws a warning that $function is deprecated.
$wgGalleryOptions
Default parameters for the "<gallery>" tag.
Definition Setup.php:188
$ps_extensions
Definition Setup.php:842
$messageMemc
Definition Setup.php:690
$parserMemc
Definition Setup.php:695
$wgFileExtensions
Definition Setup.php:452
$wgEnotifWatchlist
Definition Setup.php:366
$ps_memcached
Definition Setup.php:687
$wgEnotifMaxRecips
Definition Setup.php:361
$wgEnotifUserTalk
Definition Setup.php:365
if($wgInvalidateCacheOnLocalSettingsChange) if( $wgNewUserLog) if($wgPageLanguageUseDB) if( $wgCookieSecure==='detect') if($wgProfileOnly) if( $wgMinimalPasswordLength !==false) if($wgMaximalPasswordLength !==false) if(! $wgSessionsInObjectCache) $wgSessionsInObjectCache
Definition Setup.php:508
if( $wgRCFilterByAge) $wgDefaultUserOptions['rcdays']
Definition Setup.php:307
$wgUser
Definition Setup.php:817
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition Setup.php:36
$wgEnableUserEmail
Definition Setup.php:358
if( $wgUseFileCache|| $wgUseSquid) $wgHtml5
Definition Setup.php:447
$ps_validation
Definition Setup.php:557
$wgOut
Definition Setup.php:827
$wgCanonicalNamespaceNames
Definitions of the NS_ constants are in Defines.php.
Definition Setup.php:404
$wgMemc
Definition Setup.php:689
$wgParser
Definition Setup.php:832
global $wgCommandLineMode
Definition Setup.php:526
foreach( $wgExtensionFunctions as $func) if(!defined('MW_NO_SESSION') &&! $wgCommandLineMode) if(! $wgCommandLineMode) $wgFullyInitialised
Definition Setup.php:892
$wgTitle
Definition Setup.php:839
if(is_array( $wgExtraNamespaces)) $wgDummyLanguageCodes
Definition Setup.php:430
if(!is_object($wgAuth)) if( $wgAuth &&! $wgAuth instanceof MediaWiki\Auth\AuthManagerAuthPlugin) $ps_session
Definition Setup.php:740
$wgEnotifFromEditor
Definition Setup.php:359
$wgJsMimeType
Definition Setup.php:449
$wgUseEnotif
Definition Setup.php:368
$wgEnotifRevealEditorAddress
Definition Setup.php:363
if( $wgExperimentalHtmlIds) $rcMaxAgeDays
Definition Setup.php:290
$wgInitialSessionId
Definition Setup.php:745
$wgEnotifImpersonal
Definition Setup.php:360
$wgContLanguageCode
Definition Setup.php:437
$wgUsersNotifiedOnAllChanges
Definition Setup.php:370
$wgUserEmailUseReplyTo
Definition Setup.php:369
if(! $wgDBerrorLogTZ) $wgRequest
Definition Setup.php:662
$wgLang
Definition Setup.php:822
$ps_default2
Definition Setup.php:573
$wgContLang
Definition Setup.php:717
$ps_default
Definition Setup.php:57
if($wgLocalInterwiki) if( $wgSharedPrefix===false) if($wgSharedSchema===false) if(! $wgCookiePrefix) $wgCookiePrefix
Definition Setup.php:349
if( $wgServerName !==false) $wgServerName
Definition Setup.php:585
$wgEnotifMinorEdits
Definition Setup.php:362
$ps_setup
Definition Setup.php:37
$ps_globals
Definition Setup.php:712
$wgXhtmlDefaultNamespace
Definition Setup.php:448
$wgLockManagers[]
Initialise $wgLockManagers to include basic FS version.
Definition Setup.php:174
$wgEmailAuthentication
Definition Setup.php:357
$wgNamespaceAliases['Image']
The canonical names of namespaces 6 and 7 are, as of v1.14, "File" and "File_talk".
Definition Setup.php:168
if(! $wgEmergencyContact) if(! $wgPasswordSender) if(! $wgNoReplyAddress) if( $wgSecureLogin &&substr( $wgServer, 0, 2) !=='//') $wgVirtualRestConfig['global']['domain']
Definition Setup.php:607
if( $wgCanonicalServer===false) $serverParts
Definition Setup.php:580
$ps_misc
Definition Setup.php:633
if( $wgSkipSkin) $wgSkipSkins[]
Definition Setup.php:321
if( $wgScript===false) if($wgLoadScript===false) if( $wgArticlePath===false) if(!empty($wgActionPaths) &&!isset($wgActionPaths[ 'view'])) if( $wgResourceBasePath===null) if($wgStylePath===false) if( $wgLocalStylePath===false) if($wgExtensionAssetsPath===false) if( $wgLogo===false) if($wgUploadPath===false) if( $wgUploadDirectory===false) if($wgReadOnlyFile===false) if( $wgFileCacheDirectory===false) if($wgDeletedDirectory===false) if( $wgGitInfoCacheDirectory===false && $wgCacheDirectory !==false) if($wgEnableParserCache===false) if( $wgRightsIcon) if(isset($wgFooterIcons[ 'copyright'][ 'copyright']) &&$wgFooterIcons[ 'copyright'][ 'copyright']===[]) if(isset( $wgFooterIcons['poweredby']) &&isset( $wgFooterIcons['poweredby']['mediawiki']) && $wgFooterIcons['poweredby']['mediawiki']['src']===null) $wgNamespaceProtection[NS_MEDIAWIKI]
Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a sysadmin to set $wgName...
Definition Setup.php:161
$wgEnotifUseRealName
Definition Setup.php:364
if($wgMetaNamespace===false) if( $wgResourceLoaderMaxQueryLength===false) $wgMinUploadChunkSize
Definition Setup.php:390
Class to allow throwing wfDeprecated warnings when people use globals that we do not want them to.
Exception class which takes an HTML error message, and does not produce a backtrace.
Accesses configuration settings from $GLOBALS.
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition Hooks.php:203
Show an error that looks like an HTTP server error.
Definition HttpError.php:30
static getDeprecatedCodeMapping()
Returns a mapping of deprecated language codes that were used in previous versions of MediaWiki to up...
Backwards-compatibility wrapper for AuthManager via $wgAuth.
MediaWikiServices is the service locator for the application scope of MediaWiki.
Functions to get cache objects.
static schedulePingback()
Schedule a deferred callable that will check if a pingback should be sent and (if so) proceed to send...
Definition Pingback.php:254
static instance()
Singleton.
Definition Profiler.php:62
static getMain()
Static methods.
Class to implement stub globals, which are globals that delay loading the their associated module cod...
Stub object for the user language.
static getMaxUploadSize( $forType=null)
Get the MediaWiki maximum uploaded file size for given type of upload, based on $wgMaxUploadSize.
static getMaxPhpUploadSize()
Get the PHP maximum uploaded file size, based on ini settings.
static detectProtocol()
Detect the protocol from $_SERVER.
$res
Definition database.txt:21
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const NS_HELP
Definition Defines.php:77
const NS_USER
Definition Defines.php:67
const NS_FILE
Definition Defines.php:71
const CACHE_NONE
Definition Defines.php:103
const NS_MEDIAWIKI_TALK
Definition Defines.php:74
const NS_PROJECT_TALK
Definition Defines.php:70
const NS_MEDIAWIKI
Definition Defines.php:73
const NS_TEMPLATE
Definition Defines.php:75
const NS_SPECIAL
Definition Defines.php:54
const NS_FILE_TALK
Definition Defines.php:72
const NS_HELP_TALK
Definition Defines.php:78
const NS_CATEGORY_TALK
Definition Defines.php:80
const PROTO_HTTP
Definition Defines.php:220
const NS_MEDIA
Definition Defines.php:53
const NS_TALK
Definition Defines.php:66
const NS_USER_TALK
Definition Defines.php:68
const NS_PROJECT
Definition Defines.php:69
const NS_CATEGORY
Definition Defines.php:79
const NS_TEMPLATE_TALK
Definition Defines.php:76
either a plain
Definition hooks.txt:2026
$wgActionPaths
Definition img_auth.php:46
$wgArticlePath
Definition img_auth.php:45
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
const MW_NO_SESSION
Definition load.php:30
$debug
Definition mcc.php:31
controlled by $wgMainCacheType controlled by $wgParserCacheType controlled by $wgMessageCacheType If you set CACHE_NONE to one of the three control default value for MediaWiki still create a but requests to it are no ops and we always fall through to the database If the cache daemon can t be it should also disable itself fairly smoothly By $wgMemc is used but when it is $parserMemc or $messageMemc this is mentioned $wgDBname
CACHE_MEMCACHED $wgMainCacheType
Definition memcached.txt:63
A helper class for throttling authentication attempts.
const DBO_DEFAULT
Definition defines.php:13
const DBO_DEBUG
Definition defines.php:9