MediaWiki REL1_27
Setup.php
Go to the documentation of this file.
1<?php
31if ( !defined( 'MEDIAWIKI' ) ) {
32 exit( 1 );
33}
34
35$fname = 'Setup.php';
36$ps_setup = Profiler::instance()->scopedProfileIn( $fname );
37
38// If any extensions are still queued, force load them
39ExtensionRegistry::getInstance()->loadFromQueue();
40
41// Check to see if we are at the file scope
42if ( !isset( $wgVersion ) ) {
43 echo "Error, Setup.php must be included from the file scope, after DefaultSettings.php\n";
44 die( 1 );
45}
46
47mb_internal_encoding( 'UTF-8' );
48
49// Set various default paths sensibly...
50$ps_default = Profiler::instance()->scopedProfileIn( $fname . '-defaults' );
51
52if ( $wgScript === false ) {
53 $wgScript = "$wgScriptPath/index.php";
54}
55if ( $wgLoadScript === false ) {
56 $wgLoadScript = "$wgScriptPath/load.php";
57}
58
59if ( $wgArticlePath === false ) {
60 if ( $wgUsePathInfo ) {
61 $wgArticlePath = "$wgScript/$1";
62 } else {
63 $wgArticlePath = "$wgScript?title=$1";
64 }
65}
66
67if ( !empty( $wgActionPaths ) && !isset( $wgActionPaths['view'] ) ) {
68 // 'view' is assumed the default action path everywhere in the code
69 // but is rarely filled in $wgActionPaths
71}
72
73if ( $wgResourceBasePath === null ) {
75}
76if ( $wgStylePath === false ) {
77 $wgStylePath = "$wgResourceBasePath/skins";
78}
79if ( $wgLocalStylePath === false ) {
80 // Avoid wgResourceBasePath here since that may point to a different domain (e.g. CDN)
81 $wgLocalStylePath = "$wgScriptPath/skins";
82}
83if ( $wgExtensionAssetsPath === false ) {
84 $wgExtensionAssetsPath = "$wgResourceBasePath/extensions";
85}
86
87if ( $wgLogo === false ) {
88 $wgLogo = "$wgResourceBasePath/resources/assets/wiki.png";
89}
90
91if ( $wgUploadPath === false ) {
92 $wgUploadPath = "$wgScriptPath/images";
93}
94if ( $wgUploadDirectory === false ) {
95 $wgUploadDirectory = "$IP/images";
96}
97if ( $wgReadOnlyFile === false ) {
98 $wgReadOnlyFile = "{$wgUploadDirectory}/lock_yBgMBwiR";
99}
100if ( $wgFileCacheDirectory === false ) {
101 $wgFileCacheDirectory = "{$wgUploadDirectory}/cache";
102}
103if ( $wgDeletedDirectory === false ) {
104 $wgDeletedDirectory = "{$wgUploadDirectory}/deleted";
105}
106
107if ( $wgGitInfoCacheDirectory === false && $wgCacheDirectory !== false ) {
108 $wgGitInfoCacheDirectory = "{$wgCacheDirectory}/gitinfo";
109}
110
111if ( $wgEnableParserCache === false ) {
113}
114
115// Fix path to icon images after they were moved in 1.24
116if ( $wgRightsIcon ) {
117 $wgRightsIcon = str_replace(
118 "{$wgStylePath}/common/images/",
119 "{$wgResourceBasePath}/resources/assets/licenses/",
121 );
122}
123
124if ( isset( $wgFooterIcons['copyright']['copyright'] )
125 && $wgFooterIcons['copyright']['copyright'] === []
126) {
127 if ( $wgRightsIcon || $wgRightsText ) {
128 $wgFooterIcons['copyright']['copyright'] = [
129 'url' => $wgRightsUrl,
130 'src' => $wgRightsIcon,
131 'alt' => $wgRightsText,
132 ];
133 }
134}
135
136if ( isset( $wgFooterIcons['poweredby'] )
137 && isset( $wgFooterIcons['poweredby']['mediawiki'] )
138 && $wgFooterIcons['poweredby']['mediawiki']['src'] === null
139) {
140 $wgFooterIcons['poweredby']['mediawiki']['src'] =
141 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_88x31.png";
142 $wgFooterIcons['poweredby']['mediawiki']['srcset'] =
143 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_132x47.png 1.5x, " .
144 "$wgResourceBasePath/resources/assets/poweredby_mediawiki_176x62.png 2x";
145}
146
155
163
168 'name' => 'fsLockManager',
169 'class' => 'FSLockManager',
170 'lockDirectory' => "{$wgUploadDirectory}/lockdir",
171];
172$wgLockManagers[] = [
173 'name' => 'nullLockManager',
174 'class' => 'NullLockManager',
175];
176
180if ( !$wgLocalFileRepo ) {
182 'class' => 'LocalRepo',
183 'name' => 'local',
184 'directory' => $wgUploadDirectory,
185 'scriptDirUrl' => $wgScriptPath,
186 'scriptExtension' => '.php',
188 'hashLevels' => $wgHashedUploadDirectory ? 2 : 0,
189 'thumbScriptUrl' => $wgThumbnailScriptPath,
190 'transformVia404' => !$wgGenerateThumbnailOnParse,
191 'deletedDir' => $wgDeletedDirectory,
192 'deletedHashLevels' => $wgHashedUploadDirectory ? 3 : 0
193 ];
194}
198if ( $wgUseSharedUploads ) {
199 if ( $wgSharedUploadDBname ) {
201 'class' => 'ForeignDBRepo',
202 'name' => 'shared',
203 'directory' => $wgSharedUploadDirectory,
204 'url' => $wgSharedUploadPath,
205 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
206 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
207 'transformVia404' => !$wgGenerateThumbnailOnParse,
208 'dbType' => $wgDBtype,
209 'dbServer' => $wgDBserver,
210 'dbUser' => $wgDBuser,
211 'dbPassword' => $wgDBpassword,
212 'dbName' => $wgSharedUploadDBname,
213 'dbFlags' => ( $wgDebugDumpSql ? DBO_DEBUG : 0 ) | DBO_DEFAULT,
214 'tablePrefix' => $wgSharedUploadDBprefix,
215 'hasSharedCache' => $wgCacheSharedUploads,
216 'descBaseUrl' => $wgRepositoryBaseUrl,
217 'fetchDescription' => $wgFetchCommonsDescriptions,
218 ];
219 } else {
221 'class' => 'FileRepo',
222 'name' => 'shared',
223 'directory' => $wgSharedUploadDirectory,
224 'url' => $wgSharedUploadPath,
225 'hashLevels' => $wgHashedSharedUploadDirectory ? 2 : 0,
226 'thumbScriptUrl' => $wgSharedThumbnailScriptPath,
227 'transformVia404' => !$wgGenerateThumbnailOnParse,
228 'descBaseUrl' => $wgRepositoryBaseUrl,
229 'fetchDescription' => $wgFetchCommonsDescriptions,
230 ];
231 }
232}
235 'class' => 'ForeignAPIRepo',
236 'name' => 'wikimediacommons',
237 'apibase' => 'https://commons.wikimedia.org/w/api.php',
238 'url' => 'https://upload.wikimedia.org/wikipedia/commons',
239 'thumbUrl' => 'https://upload.wikimedia.org/wikipedia/commons/thumb',
240 'hashLevels' => 2,
241 'transformVia404' => true,
242 'fetchDescription' => true,
243 'descriptionCacheExpiry' => 43200,
244 'apiThumbCacheExpiry' => 0,
245 ];
246}
247/*
248 * Add on default file backend config for file repos.
249 * FileBackendGroup will handle initializing the backends.
250 */
251if ( !isset( $wgLocalFileRepo['backend'] ) ) {
252 $wgLocalFileRepo['backend'] = $wgLocalFileRepo['name'] . '-backend';
253}
254foreach ( $wgForeignFileRepos as &$repo ) {
255 if ( !isset( $repo['directory'] ) && $repo['class'] === 'ForeignAPIRepo' ) {
256 $repo['directory'] = $wgUploadDirectory; // b/c
257 }
258 if ( !isset( $repo['backend'] ) ) {
259 $repo['backend'] = $repo['name'] . '-backend';
260 }
261}
262unset( $repo ); // no global pollution; destroy reference
263
264$rcMaxAgeDays = $wgRCMaxAge / ( 3600 * 24 );
265if ( $wgRCFilterByAge ) {
266 // Trim down $wgRCLinkDays so that it only lists links which are valid
267 // as determined by $wgRCMaxAge.
268 // Note that we allow 1 link higher than the max for things like 56 days but a 60 day link.
269 sort( $wgRCLinkDays );
270
271 // @codingStandardsIgnoreStart Generic.CodeAnalysis.ForLoopWithTestFunctionCall.NotAllowed
272 for ( $i = 0; $i < count( $wgRCLinkDays ); $i++ ) {
273 // @codingStandardsIgnoreEnd
274 if ( $wgRCLinkDays[$i] >= $rcMaxAgeDays ) {
275 $wgRCLinkDays = array_slice( $wgRCLinkDays, 0, $i + 1, false );
276 break;
277 }
278 }
279}
280// Ensure that default user options are not invalid, since that breaks Special:Preferences
281$wgDefaultUserOptions['rcdays'] = min(
282 $wgDefaultUserOptions['rcdays'],
283 ceil( $rcMaxAgeDays )
284);
285$wgDefaultUserOptions['watchlistdays'] = min(
286 $wgDefaultUserOptions['watchlistdays'],
287 ceil( $rcMaxAgeDays )
288);
289unset( $rcMaxAgeDays );
290
291if ( $wgSkipSkin ) {
293}
294
295// Register skins
296// Use a closure to avoid leaking into global state
297call_user_func( function () use ( $wgValidSkinNames ) {
299 foreach ( $wgValidSkinNames as $name => $skin ) {
300 $factory->register( $name, $skin, function () use ( $name, $skin ) {
301 $class = "Skin$skin";
302 return new $class( $name );
303 } );
304 }
305 // Register a hidden "fallback" skin
306 $factory->register( 'fallback', 'Fallback', function () {
307 return new SkinFallback;
308 } );
309 // Register a hidden skin for api output
310 $factory->register( 'apioutput', 'ApiOutput', function () {
311 return new SkinApi;
312 } );
313} );
314$wgSkipSkins[] = 'fallback';
315$wgSkipSkins[] = 'apioutput';
316
317if ( $wgLocalInterwiki ) {
318 array_unshift( $wgLocalInterwikis, $wgLocalInterwiki );
319}
320
321// Set default shared prefix
322if ( $wgSharedPrefix === false ) {
324}
325
326// Set default shared schema
327if ( $wgSharedSchema === false ) {
329}
330
331if ( !$wgCookiePrefix ) {
332 if ( $wgSharedDB && $wgSharedPrefix && in_array( 'user', $wgSharedTables ) ) {
334 } elseif ( $wgSharedDB && in_array( 'user', $wgSharedTables ) ) {
336 } elseif ( $wgDBprefix ) {
338 } else {
340 }
341}
342$wgCookiePrefix = strtr( $wgCookiePrefix, '=,; +."\'\\[', '__________' );
343
344if ( $wgEnableEmail ) {
346} else {
347 // Disable all other email settings automatically if $wgEnableEmail
348 // is set to false. - bug 63678
349 $wgAllowHTMLEmail = false;
350 $wgEmailAuthentication = false; // do not require auth if you're not sending email anyway
360 unset( $wgGroupPermissions['user']['sendemail'] );
364}
365
366if ( $wgMetaNamespace === false ) {
367 $wgMetaNamespace = str_replace( ' ', '_', $wgSitename );
368}
369
370// Default value is 2000 or the suhosin limit if it is between 1 and 2000
371if ( $wgResourceLoaderMaxQueryLength === false ) {
372 $suhosinMaxValueLength = (int)ini_get( 'suhosin.get.max_value_length' );
373 if ( $suhosinMaxValueLength > 0 && $suhosinMaxValueLength < 2000 ) {
374 $wgResourceLoaderMaxQueryLength = $suhosinMaxValueLength;
375 } else {
377 }
378 unset( $suhosinMaxValueLength );
379}
380
381// Ensure the minimum chunk size is less than PHP upload limits or the maximum
382// upload size.
388 ini_get( 'post_max_size' ) ?: ini_get( 'hhvm.server.max_post_size' ),
389 PHP_INT_MAX
390 ) ?: PHP_INT_MAX ) - 1024 // Leave some room for other POST parameters
391);
392
398 NS_MEDIA => 'Media',
399 NS_SPECIAL => 'Special',
400 NS_TALK => 'Talk',
401 NS_USER => 'User',
402 NS_USER_TALK => 'User_talk',
403 NS_PROJECT => 'Project',
404 NS_PROJECT_TALK => 'Project_talk',
405 NS_FILE => 'File',
406 NS_FILE_TALK => 'File_talk',
407 NS_MEDIAWIKI => 'MediaWiki',
408 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
409 NS_TEMPLATE => 'Template',
410 NS_TEMPLATE_TALK => 'Template_talk',
411 NS_HELP => 'Help',
412 NS_HELP_TALK => 'Help_talk',
413 NS_CATEGORY => 'Category',
414 NS_CATEGORY_TALK => 'Category_talk',
415];
416
418if ( is_array( $wgExtraNamespaces ) ) {
420}
421
422// These are now the same, always
423// To determine the user language, use $wgLang->getCode()
425
426// Easy to forget to falsify $wgDebugToolbar for static caches.
427// If file cache or CDN cache is on, just disable this (DWIMD).
429 $wgDebugToolbar = false;
430}
431
432// We always output HTML5 since 1.22, overriding these is no longer supported
433// we set them here for extensions that depend on its value.
434$wgHtml5 = true;
435$wgXhtmlDefaultNamespace = 'http://www.w3.org/1999/xhtml';
436$wgJsMimeType = 'text/javascript';
437
438// Blacklisted file extensions shouldn't appear on the "allowed" list
439$wgFileExtensions = array_values( array_diff( $wgFileExtensions, $wgFileBlacklist ) );
440
442 MediaWiki\suppressWarnings();
443 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', filemtime( "$IP/LocalSettings.php" ) ) );
444 MediaWiki\restoreWarnings();
445}
446
447if ( $wgNewUserLog ) {
448 // Add a new log type
449 $wgLogTypes[] = 'newusers';
450 $wgLogNames['newusers'] = 'newuserlogpage';
451 $wgLogHeaders['newusers'] = 'newuserlogpagetext';
452 $wgLogActionsHandlers['newusers/newusers'] = 'NewUsersLogFormatter';
453 $wgLogActionsHandlers['newusers/create'] = 'NewUsersLogFormatter';
454 $wgLogActionsHandlers['newusers/create2'] = 'NewUsersLogFormatter';
455 $wgLogActionsHandlers['newusers/byemail'] = 'NewUsersLogFormatter';
456 $wgLogActionsHandlers['newusers/autocreate'] = 'NewUsersLogFormatter';
457}
458
460 $wgLogTypes[] = 'pagelang';
461 $wgLogActionsHandlers['pagelang/pagelang'] = 'PageLangLogFormatter';
462}
463
464if ( $wgCookieSecure === 'detect' ) {
466}
467
468if ( $wgProfileOnly ) {
469 $wgDebugLogGroups['profileoutput'] = $wgDebugLogFile;
470 $wgDebugLogFile = '';
471}
472
473// Backwards compatibility with old password limits
474if ( $wgMinimalPasswordLength !== false ) {
475 $wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = $wgMinimalPasswordLength;
476}
477
478if ( $wgMaximalPasswordLength !== false ) {
479 $wgPasswordPolicy['policies']['default']['MaximalPasswordLength'] = $wgMaximalPasswordLength;
480}
481
482// Backwards compatibility warning
484 wfDeprecated( '$wgSessionsInObjectCache = false', '1.27' );
485 if ( $wgSessionHandler ) {
486 wfDeprecated( '$wgSessionsHandler', '1.27' );
487 }
488 $cacheType = get_class( ObjectCache::getInstance( $wgSessionCacheType ) );
490 'caches',
491 "Session data will be stored in \"$cacheType\" cache with " .
492 "expiry $wgObjectCacheSessionExpiry seconds"
493 );
494}
496
497if ( $wgPHPSessionHandling !== 'enable' &&
498 $wgPHPSessionHandling !== 'warn' &&
499 $wgPHPSessionHandling !== 'disable'
500) {
501 $wgPHPSessionHandling = 'warn';
502}
503if ( defined( 'MW_NO_SESSION' ) ) {
504 // If the entry point wants no session, force 'disable' here unless they
505 // specifically set it to the (undocumented) 'warn'.
506 $wgPHPSessionHandling = MW_NO_SESSION === 'warn' ? 'warn' : 'disable';
507}
508
509Profiler::instance()->scopedProfileOut( $ps_default );
510
511// Disable MWDebug for command line mode, this prevents MWDebug from eating up
512// all the memory from logging SQL queries on maintenance scripts
515 MWDebug::init();
516}
517
518if ( !class_exists( 'AutoLoader' ) ) {
519 require_once "$IP/includes/AutoLoader.php";
520}
521
522// Install a header callback to prevent caching of responses with cookies (T127993)
523if ( !$wgCommandLineMode ) {
524 header_register_callback( function () {
525 $headers = [];
526 foreach ( headers_list() as $header ) {
527 list( $name, $value ) = explode( ':', $header, 2 );
528 $headers[strtolower( trim( $name ) )][] = trim( $value );
529 }
530
531 if ( isset( $headers['set-cookie'] ) ) {
532 $cacheControl = isset( $headers['cache-control'] )
533 ? implode( ', ', $headers['cache-control'] )
534 : '';
535
536 if ( !preg_match( '/(?:^|,)\s*(?:private|no-cache|no-store)\s*(?:$|,)/i', $cacheControl ) ) {
537 header( 'Expires: Thu, 01 Jan 1970 00:00:00 GMT' );
538 header( 'Cache-Control: private, max-age=0, s-maxage=0' );
539 MediaWiki\Logger\LoggerFactory::getInstance( 'cache-cookies' )->warning(
540 'Cookies set on {url} with Cache-Control "{cache-control}"', [
541 'url' => WebRequest::getGlobalRequestURL(),
542 'cookies' => $headers['set-cookie'],
543 'cache-control' => $cacheControl ?: '<not set>',
544 ]
545 );
546 }
547 }
548 } );
549}
550
552
553require_once "$IP/includes/compat/normal/UtfNormalUtil.php";
554
555$ps_validation = Profiler::instance()->scopedProfileIn( $fname . '-validation' );
556
557// T48998: Bail out early if $wgArticlePath is non-absolute
558foreach ( [ 'wgArticlePath', 'wgVariantArticlePath' ] as $varName ) {
559 if ( $$varName && !preg_match( '/^(https?:\/\/|\/)/', $$varName ) ) {
560 throw new FatalError(
561 "If you use a relative URL for \$$varName, it must start " .
562 'with a slash (<code>/</code>).<br><br>See ' .
563 "<a href=\"https://www.mediawiki.org/wiki/Manual:\$$varName\">" .
564 "https://www.mediawiki.org/wiki/Manual:\$$varName</a>."
565 );
566 }
567}
568
569Profiler::instance()->scopedProfileOut( $ps_validation );
570
571$ps_default2 = Profiler::instance()->scopedProfileIn( $fname . '-defaults2' );
572
573if ( $wgCanonicalServer === false ) {
575}
576
577// Set server name
579if ( $wgServerName !== false ) {
580 wfWarn( '$wgServerName should be derived from $wgCanonicalServer, '
581 . 'not customized. Overwriting $wgServerName.' );
582}
584unset( $serverParts );
585
586// Set defaults for configuration variables
587// that are derived from the server name by default
588// Note: $wgEmergencyContact and $wgPasswordSender may be false or empty string (T104142)
589if ( !$wgEmergencyContact ) {
590 $wgEmergencyContact = 'wikiadmin@' . $wgServerName;
591}
592if ( !$wgPasswordSender ) {
593 $wgPasswordSender = 'apache@' . $wgServerName;
594}
595if ( !$wgNoReplyAddress ) {
597}
598
599if ( $wgSecureLogin && substr( $wgServer, 0, 2 ) !== '//' ) {
600 $wgSecureLogin = false;
601 wfWarn( 'Secure login was enabled on a server that only supports '
602 . 'HTTP or HTTPS. Disabling secure login.' );
603}
604
606
607// Now that GlobalFunctions is loaded, set defaults that depend on it.
608if ( $wgTmpDirectory === false ) {
610}
611
612// We don't use counters anymore. Left here for extensions still
613// expecting this to exist. Should be removed sometime 1.26 or later.
614if ( !isset( $wgDisableCounters ) ) {
615 $wgDisableCounters = true;
616}
617
618if ( $wgMainWANCache === false ) {
619 // Setup a WAN cache from $wgMainCacheType with no relayer.
620 // Sites using multiple datacenters can configure a relayer.
621 $wgMainWANCache = 'mediawiki-main-default';
623 'class' => 'WANObjectCache',
624 'cacheId' => $wgMainCacheType,
625 'channels' => [ 'purge' => 'wancache-main-default-purge' ]
626 ];
627}
628
629Profiler::instance()->scopedProfileOut( $ps_default2 );
630
631$ps_misc = Profiler::instance()->scopedProfileIn( $fname . '-misc1' );
632
633// Raise the memory limit if it's too low
635
641if ( is_null( $wgLocaltimezone ) ) {
642 MediaWiki\suppressWarnings();
643 $wgLocaltimezone = date_default_timezone_get();
644 MediaWiki\restoreWarnings();
645}
646
647date_default_timezone_set( $wgLocaltimezone );
648if ( is_null( $wgLocalTZoffset ) ) {
649 $wgLocalTZoffset = date( 'Z' ) / 60;
650}
651
652if ( !$wgDBerrorLogTZ ) {
654}
655
656// initialize the request object in $wgRequest
657$wgRequest = RequestContext::getMain()->getRequest(); // BackCompat
658
659// Useful debug output
660if ( $wgCommandLineMode ) {
661 wfDebug( "\n\nStart command line script $self\n" );
662} else {
663 $debug = "\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
664
666 $debug .= "HTTP HEADERS:\n";
667
668 foreach ( $wgRequest->getAllHeaders() as $name => $value ) {
669 $debug .= "$name: $value\n";
670 }
671 }
672 wfDebug( $debug );
673}
674
675Profiler::instance()->scopedProfileOut( $ps_misc );
676$ps_memcached = Profiler::instance()->scopedProfileIn( $fname . '-memcached' );
677
681
682wfDebugLog( 'caches',
683 'cluster: ' . get_class( $wgMemc ) .
684 ', WAN: ' . $wgMainWANCache .
685 ', stash: ' . $wgMainStash .
686 ', message: ' . get_class( $messageMemc ) .
687 ', parser: ' . get_class( $parserMemc ) .
688 ', session: ' . get_class( ObjectCache::getInstance( $wgSessionCacheType ) )
689);
690
691Profiler::instance()->scopedProfileOut( $ps_memcached );
692
693// Most of the config is out, some might want to run hooks here.
694Hooks::run( 'SetupAfterCache' );
695
696$ps_globals = Profiler::instance()->scopedProfileIn( $fname . '-globals' );
697
701$wgContLang = Language::factory( $wgLanguageCode );
702$wgContLang->initEncoding();
703$wgContLang->initContLang();
704
705// Now that variant lists may be available...
706$wgRequest->interpolateTitle();
707
708if ( !is_object( $wgAuth ) ) {
710 Hooks::run( 'AuthPluginSetup', [ &$wgAuth ] );
711}
712if ( $wgAuth && !$wgAuth instanceof MediaWiki\Auth\AuthManagerAuthPlugin ) {
713 MediaWiki\Auth\AuthManager::singleton()->forcePrimaryAuthenticationProviders( [
714 new MediaWiki\Auth\TemporaryPasswordPrimaryAuthenticationProvider( [
715 'authoritative' => false,
716 ] ),
717 new MediaWiki\Auth\AuthPluginPrimaryAuthenticationProvider( $wgAuth ),
718 new MediaWiki\Auth\LocalPasswordPrimaryAuthenticationProvider( [
719 'authoritative' => true,
720 ] ),
721 ], '$wgAuth is ' . get_class( $wgAuth ) );
722}
723
724// Set up the session
725$ps_session = Profiler::instance()->scopedProfileIn( $fname . '-session' );
731if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
732 // If session.auto_start is there, we can't touch session name
733 if ( $wgPHPSessionHandling !== 'disable' && !wfIniGetBool( 'session.auto_start' ) ) {
734 session_name( $wgSessionName ? $wgSessionName : $wgCookiePrefix . '_session' );
735 }
736
737 // Create the SessionManager singleton and set up our session handler,
738 // unless we're specifically asked not to.
739 if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
740 MediaWiki\Session\PHPSessionHandler::install(
741 MediaWiki\Session\SessionManager::singleton()
742 );
743 }
744
745 // Initialize the session
746 try {
747 $session = MediaWiki\Session\SessionManager::getGlobalSession();
748 } catch ( OverflowException $ex ) {
749 if ( isset( $ex->sessionInfos ) && count( $ex->sessionInfos ) >= 2 ) {
750 // The exception is because the request had multiple possible
751 // sessions tied for top priority. Report this to the user.
752 $list = [];
753 foreach ( $ex->sessionInfos as $info ) {
754 $list[] = $info->getProvider()->describe( $wgContLang );
755 }
756 $list = $wgContLang->listToText( $list );
757 throw new HttpError( 400,
758 Message::newFromKey( 'sessionmanager-tie', $list )->inLanguage( $wgContLang )->plain()
759 );
760 }
761
762 // Not the one we want, rethrow
763 throw $ex;
764 }
765
766 if ( $session->isPersistent() ) {
767 $wgInitialSessionId = $session->getSessionId();
768 }
769
770 $session->renew();
771 if ( MediaWiki\Session\PHPSessionHandler::isEnabled() &&
772 ( $session->isPersistent() || $session->shouldRememberUser() )
773 ) {
774 // Start the PHP-session for backwards compatibility
775 session_id( $session->getId() );
776 MediaWiki\quietCall( 'session_start' );
777 }
778
779 unset( $session );
780} else {
781 // Even if we didn't set up a global Session, still install our session
782 // handler unless specifically requested not to.
783 if ( !defined( 'MW_NO_SESSION_HANDLER' ) ) {
784 MediaWiki\Session\PHPSessionHandler::install(
785 MediaWiki\Session\SessionManager::singleton()
786 );
787 }
788}
789Profiler::instance()->scopedProfileOut( $ps_session );
790
794$wgUser = RequestContext::getMain()->getUser(); // BackCompat
795
800
804$wgOut = RequestContext::getMain()->getOutput(); // BackCompat
805
809$wgParser = new StubObject( 'wgParser', $wgParserConf['class'], [ $wgParserConf ] );
810
814$wgTitle = null;
815
816Profiler::instance()->scopedProfileOut( $ps_globals );
817$ps_extensions = Profiler::instance()->scopedProfileIn( $fname . '-extensions' );
818
819// Extension setup functions
820// Entries should be added to this variable during the inclusion
821// of the extension file. This allows the extension to perform
822// any necessary initialisation in the fully initialised environment
823foreach ( $wgExtensionFunctions as $func ) {
824 // Allow closures in PHP 5.3+
825 if ( is_object( $func ) && $func instanceof Closure ) {
826 $profName = $fname . '-extensions-closure';
827 } elseif ( is_array( $func ) ) {
828 if ( is_object( $func[0] ) ) {
829 $profName = $fname . '-extensions-' . get_class( $func[0] ) . '::' . $func[1];
830 } else {
831 $profName = $fname . '-extensions-' . implode( '::', $func );
832 }
833 } else {
834 $profName = $fname . '-extensions-' . strval( $func );
835 }
836
837 $ps_ext_func = Profiler::instance()->scopedProfileIn( $profName );
838 call_user_func( $func );
839 Profiler::instance()->scopedProfileOut( $ps_ext_func );
840}
841
842// If the session user has a 0 id but a valid name, that means we need to
843// autocreate it.
844if ( !defined( 'MW_NO_SESSION' ) && !$wgCommandLineMode ) {
845 $sessionUser = MediaWiki\Session\SessionManager::getGlobalSession()->getUser();
846 if ( $sessionUser->getId() === 0 && User::isValidUserName( $sessionUser->getName() ) ) {
847 $ps_autocreate = Profiler::instance()->scopedProfileIn( $fname . '-autocreate' );
848 $res = MediaWiki\Auth\AuthManager::singleton()->autoCreateUser(
849 $sessionUser,
850 MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_SESSION,
851 true
852 );
853 Profiler::instance()->scopedProfileOut( $ps_autocreate );
854 \MediaWiki\Logger\LoggerFactory::getInstance( 'authmanager' )->info( 'Autocreation attempt', [
855 'event' => 'autocreate',
856 'status' => $res,
857 ] );
858 unset( $res );
859 }
860 unset( $sessionUser );
861}
862
863wfDebug( "Fully initialised\n" );
865
866Profiler::instance()->scopedProfileOut( $ps_extensions );
867Profiler::instance()->scopedProfileOut( $ps_setup );
$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.
$wgValidSkinNames
List of valid skin names.
$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.
$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.
$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...
$wgSharedUploadDBname
DB name with metadata about shared directory.
$wgMainStash
Main object stash type.
$wgParserConf
Parser configuration.
$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.
$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
$wgSessionsInMemcached
Deprecated alias for $wgSessionsInObjectCache.
$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.
wfGetParserCacheStorage()
Get the cache object used by the parser cache.
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.
$i
Definition Parser.php:1694
$ps_extensions
Definition Setup.php:817
$messageMemc
Definition Setup.php:679
$parserMemc
Definition Setup.php:680
$wgFileExtensions
Definition Setup.php:439
$wgEnotifWatchlist
Definition Setup.php:359
$ps_memcached
Definition Setup.php:676
$wgEnotifMaxRecips
Definition Setup.php:354
$wgEnotifUserTalk
Definition Setup.php:358
if($wgInvalidateCacheOnLocalSettingsChange) if( $wgNewUserLog) if($wgPageLanguageUseDB) if( $wgCookieSecure==='detect') if($wgProfileOnly) if( $wgMinimalPasswordLength !==false) if($wgMaximalPasswordLength !==false) if(! $wgSessionsInObjectCache &&! $wgSessionsInMemcached) $wgSessionsInObjectCache
Definition Setup.php:495
if( $wgRCFilterByAge) $wgDefaultUserOptions['rcdays']
Definition Setup.php:281
$wgUser
Definition Setup.php:794
if(!defined( 'MEDIAWIKI')) $fname
This file is not a valid entry point, perform no further processing unless MEDIAWIKI is defined.
Definition Setup.php:35
$wgEnableUserEmail
Definition Setup.php:351
$rcMaxAgeDays
Definition Setup.php:264
if( $wgUseFileCache|| $wgUseSquid) $wgHtml5
Definition Setup.php:434
$ps_validation
Definition Setup.php:555
$wgOut
Definition Setup.php:804
$wgCanonicalNamespaceNames
Definitions of the NS_ constants are in Defines.php.
Definition Setup.php:397
$wgMemc
Definition Setup.php:678
$wgParser
Definition Setup.php:809
global $wgCommandLineMode
Definition Setup.php:513
$wgTitle
Definition Setup.php:814
if(!is_object($wgAuth)) if( $wgAuth &&! $wgAuth instanceof MediaWiki\Auth\AuthManagerAuthPlugin) $ps_session
Definition Setup.php:725
$wgEnotifFromEditor
Definition Setup.php:352
$wgJsMimeType
Definition Setup.php:436
$wgUseEnotif
Definition Setup.php:361
$wgEnotifRevealEditorAddress
Definition Setup.php:356
$wgInitialSessionId
Definition Setup.php:730
$wgEnotifImpersonal
Definition Setup.php:353
$wgUsersNotifiedOnAllChanges
Definition Setup.php:363
$wgUserEmailUseReplyTo
Definition Setup.php:362
$wgLang
Definition Setup.php:799
$ps_default2
Definition Setup.php:571
$wgContLang
Definition Setup.php:701
$ps_default
Definition Setup.php:50
if($wgLocalInterwiki) if( $wgSharedPrefix===false) if($wgSharedSchema===false) if(! $wgCookiePrefix) $wgCookiePrefix
Definition Setup.php:342
if( $wgServerName !==false) $wgServerName
Definition Setup.php:583
if(is_array( $wgExtraNamespaces)) $wgContLanguageCode
Definition Setup.php:424
$wgEnotifMinorEdits
Definition Setup.php:355
$ps_setup
Definition Setup.php:36
$ps_globals
Definition Setup.php:696
if(is_null($wgLocalTZoffset)) if(! $wgDBerrorLogTZ) $wgRequest
Definition Setup.php:657
$wgXhtmlDefaultNamespace
Definition Setup.php:435
$wgLockManagers[]
Initialise $wgLockManagers to include basic FS version.
Definition Setup.php:167
$wgEmailAuthentication
Definition Setup.php:350
$wgNamespaceAliases['Image']
The canonical names of namespaces 6 and 7 are, as of v1.14, "File" and "File_talk".
Definition Setup.php:161
if(! $wgEmergencyContact) if(! $wgPasswordSender) if(! $wgNoReplyAddress) if( $wgSecureLogin &&substr( $wgServer, 0, 2) !=='//') $wgVirtualRestConfig['global']['domain']
Definition Setup.php:605
if( $wgCanonicalServer===false) $serverParts
Definition Setup.php:578
$ps_misc
Definition Setup.php:631
$wgSkipSkins[]
Definition Setup.php:314
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:154
$wgEnotifUseRealName
Definition Setup.php:357
$wgFullyInitialised
Definition Setup.php:864
if($wgMetaNamespace===false) if( $wgResourceLoaderMaxQueryLength===false) $wgMinUploadChunkSize
Definition Setup.php:383
Exception class which takes an HTML error message, and does not produce a backtrace.
Show an error that looks like an HTTP server error.
Definition HttpError.php:30
static installHandler()
Install handlers with PHP.
Backwards-compatibility wrapper for AuthManager via $wgAuth.
static getInstance( $id)
Get a cached instance of the specified type of cache object.
static instance()
Singleton.
Definition Profiler.php:60
static getMain()
Static methods.
SkinTemplate class for API output.
Definition SkinApi.php:33
static getDefaultInstance()
SkinTemplate class for the fallback skin.
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
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition deferred.txt:11
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:82
const NS_USER
Definition Defines.php:72
const NS_FILE
Definition Defines.php:76
const CACHE_NONE
Definition Defines.php:103
const NS_MEDIAWIKI_TALK
Definition Defines.php:79
const NS_PROJECT_TALK
Definition Defines.php:75
const NS_MEDIAWIKI
Definition Defines.php:78
const NS_TEMPLATE
Definition Defines.php:80
const NS_SPECIAL
Definition Defines.php:59
const DBO_DEFAULT
Definition Defines.php:34
const NS_FILE_TALK
Definition Defines.php:77
const NS_HELP_TALK
Definition Defines.php:83
const NS_CATEGORY_TALK
Definition Defines.php:85
const PROTO_HTTP
Definition Defines.php:262
const NS_MEDIA
Definition Defines.php:58
const NS_TALK
Definition Defines.php:71
const NS_USER_TALK
Definition Defines.php:73
const NS_PROJECT
Definition Defines.php:74
const DBO_DEBUG
Definition Defines.php:30
const NS_CATEGORY
Definition Defines.php:84
const NS_TEMPLATE_TALK
Definition Defines.php:81
$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.