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