52use MediaWiki\MainConfigSchema;
69use Psr\Log\LoggerInterface;
71use Wikimedia\RequestTimeout\RequestTimeout;
83if ( !defined(
'MEDIAWIKI' ) ) {
90if ( !defined(
'MW_ENTRY_POINT' ) ) {
96 define(
'MW_ENTRY_POINT',
'unknown' );
111require_once MW_INSTALL_PATH .
'/includes/AutoLoader.php';
112require_once MW_INSTALL_PATH .
'/includes/Defines.php';
115if ( !interface_exists( LoggerInterface::class ) ) {
117 '<strong>Error: Missing external libraries.</strong> ' .
118 'MediaWiki depends on external libraries bundled with most MediaWiki distributions. ' .
119 "When installing MediaWiki from its Git reposistory, these must be installed separately.\n\n" .
120 'Please see the <a href="https://www.mediawiki.org/wiki/Download_from_Git' .
121 '#Fetch_external_libraries">instructions for installing libraries</a> on mediawiki.org ' .
122 'for help on installing the required libraries.'
124 http_response_code( 500 );
126 error_log( $message );
145if ( defined(
'MW_USE_CONFIG_SCHEMA_CLASS' ) ) {
154require_once MW_INSTALL_PATH .
'/includes/GlobalFunctions.php';
157HeaderCallback::register();
161HttpStatus::registerHeadersSentCallback(
162 HeaderCallback::warnIfHeadersSent( ... )
167mb_internal_encoding(
'UTF-8' );
176 MainConfigNames::ExtensionDirectory => MW_INSTALL_PATH .
'/extensions',
177 MainConfigNames::StyleDirectory => MW_INSTALL_PATH .
'/skins',
178 MainConfigNames::UploadDirectory => MW_INSTALL_PATH .
'/images',
179 MainConfigNames::ServiceWiringFiles => [ MW_INSTALL_PATH .
'/includes/ServiceWiring.php' ],
188if ( !isset( $GLOBALS[
'wgScopeTest'] ) || $GLOBALS[
'wgScopeTest'] !==
$wgScopeTest ) {
189 foreach (
$wgSettings->getConfigSchema()->getDefinedKeys() as $key ) {
199 if ( defined(
'MW_CONFIG_CALLBACK' ) ) {
204 if ( getenv(
'MW_USE_LOCAL_SETTINGS_LOADER' ) ) {
208 $localSettingsLoader->loadLocalSettingsFile( MW_CONFIG_FILE );
209 unset( $localSettingsLoader );
211 if ( str_ends_with( MW_CONFIG_FILE,
'.php' ) ) {
214 require_once MW_CONFIG_FILE;
229if (
$wgSettings->getConfig()->get( MainConfigNames::WikiFarmSettingsDirectory ) ) {
231 $wikiFarmSettingsLoader->loadWikiFarmSettings();
232 unset( $wikiFarmSettingsLoader );
245if ( defined(
'MW_SETUP_CALLBACK' ) ) {
261require __DIR__ .
'/SetupDynamicConfig.php';
263if ( defined(
'MW_AUTOLOAD_TEST_CLASSES' ) ) {
264 require_once __DIR__ .
'/../tests/Common/TestsAutoLoader.php';
275if ( defined(
'MW_AUTOLOAD_TEST_CLASSES' ) ) {
276 ExtensionRegistry::getInstance()->setLoadTestClassesAndNamespaces(
true );
279ExtensionRegistry::getInstance()->setSettingsBuilder(
$wgSettings );
280ExtensionRegistry::getInstance()->loadFromQueue();
282ExtensionRegistry::getInstance()->finish();
289if ( defined(
'MW_FINAL_SETUP_CALLBACK' ) ) {
290 call_user_func( MW_FINAL_SETUP_CALLBACK,
$wgSettings );
303if ( PHP_OS_FAMILY !==
'Darwin' && setlocale( LC_ALL,
'C.UTF-8' ) ) {
312putenv(
"LC_ALL={$locale}" );
323MediaWikiServices::allowGlobalInstance();
327define(
'MW_SERVICE_BOOTSTRAP_COMPLETE', 1 );
330if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
340call_user_func(
static function (): void {
345 $tracer = MediaWikiServices::getInstance()->getTracer();
346 $request = RequestContext::getMain()->getRequest();
348 $startTimeNanos = (int)( 1e9 * $_SERVER[
'REQUEST_TIME_FLOAT'] );
351 $spanName =
"EntryPoint " .
MW_ENTRY_POINT .
".php HTTP {$request->getMethod()}";
353 $rootSpan = $tracer->createRootSpanFromCarrier( $spanName,
$wgAllowExternalReqID ? $request->getAllHeaders() : [] );
354 $rootSpan->setSpanKind( SpanInterface::SPAN_KIND_SERVER )
355 ->setAttributes( array_filter( [
356 'http.request.method' => $request->getMethod(),
357 'url.path' => $request->getRequestURL(),
358 'server.name' => $_SERVER[
'SERVER_NAME'] ??
null,
360 ->start( $startTimeNanos );
361 $rootSpan->activate();
363 TracerState::getInstance()->setRootSpan( $rootSpan );
371 '$wgServer must be set in LocalSettings.php. ' .
372 'See <a href="https://www.mediawiki.org/wiki/Manual:$wgServer">' .
373 'https://www.mediawiki.org/wiki/Manual:$wgServer</a>.'
381 $wgCanonicalServer = MediaWikiServices::getInstance()->getUrlUtils()->getCanonicalServer();
386 wfWarn(
'$wgServerName should be derived from $wgCanonicalServer, '
387 .
'not customized. Overwriting $wgServerName.' );
406 wfWarn(
'Secure login was enabled on a server that only supports '
407 .
'HTTP or HTTPS. Disabling secure login.' );
417 MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
437$wgRequest = RequestContext::getMain()->getRequest();
440if (
$wgRequest->getCookie(
'UseDC',
'' ) ===
'master' ) {
444 MediaWikiServices::getInstance()->getMainWANObjectCache()->useInterimHoldOffCaching(
false );
448(
static function () {
451 $logger = LoggerFactory::getInstance(
'wfDebug' );
453 $self = $_SERVER[
'PHP_SELF'] ??
'';
454 $logger->debug(
"\n\nStart command line script $self" );
456 $debug =
"\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
457 $debug .=
"IP: " .
$wgRequest->getIP() .
"\n";
458 $debug .=
"HTTP HEADERS:\n";
459 foreach (
$wgRequest->getAllHeaders() as $name => $value ) {
460 $debug .=
"$name: $value\n";
462 $debug .=
"(end headers)";
468(
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onSetupAfterCache();
486 HeaderCallback::warnIfHeadersSent();
492 if ( !defined(
'MW_NO_SESSION_HANDLER' ) ) {
493 MediaWiki\Session\PHPSessionHandler::install(
494 MediaWikiServices::getInstance()->getSessionManager()
497 register_shutdown_function( MediaWikiServices::getInstance()->getSessionManager()->shutdown( ... ) );
500 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
504 $session = RequestContext::getMain()->getRequest()->getSession();
505 }
catch (
MediaWiki\Session\SessionOverflowException $ex ) {
509 foreach ( $ex->getSessionInfos() as $info ) {
510 $list[] = $info->getProvider()->describe( $contLang );
512 $list = $contLang->listToText( $list );
514 Message::newFromKey(
'sessionmanager-tie', $list )->inLanguage( $contLang )
521 if (
MediaWiki\Session\PHPSessionHandler::isEnabled() &&
522 ( $session->isPersistent() || $session->shouldRememberUser() ) &&
523 session_id() !== $session->getId()
526 if ( session_id() !==
'' ) {
527 wfDebugLog(
'session',
'PHP session {old_id} was already started, changing to {new_id}',
'all', [
528 'old_id' => session_id(),
529 'new_id' => $session->getId(),
531 session_write_close();
533 session_id( $session->getId() );
541 if ( !defined(
'MW_NO_SESSION_HANDLER' ) ) {
542 MediaWiki\Session\PHPSessionHandler::install(
543 MediaWikiServices::getInstance()->getSessionManager()
546 register_shutdown_function( MediaWikiServices::getInstance()->getSessionManager()->shutdown( ... ) );
559register_shutdown_function(
static function () {
560 StubGlobalUser::$destructorDeprecationDisarmed =
true;
571$wgOut = RequestContext::getMain()->getOutput();
593 $sessionUser = RequestContext::getMain()->getRequest()->getSession()->getUser();
594 if ( $sessionUser->getId() === 0 &&
595 MediaWikiServices::getInstance()->getUserNameUtils()->isValid( $sessionUser->getName() )
597 MediaWikiServices::getInstance()->getAuthManager()->autoCreateUser(
599 MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_SESSION
602 unset( $sessionUser );
613 DeferredUpdates::addCallableUpdate(
static function () {
614 MediaWikiServices::getInstance()->getPingback()->run();
620 $logger = LoggerFactory::getInstance(
'Settings' );
622 $logger->warning( $msg );
635 $manager = MediaWikiServices::getInstance()->getSessionManager();
637 $manager->logPotentialSessionLeakage();
wfDetectLocalSettingsFile(?string $installationPath=null)
Decide and remember where to load LocalSettings from.
wfDetectInstallPath()
Decide and remember where mediawiki is installed.
wfIsCLI()
Check if we are running from the commandline.
const MW_VERSION
The running version of MediaWiki.
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.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
if(!defined('MEDIAWIKI')) if(!defined( 'MW_ENTRY_POINT')) global $IP
Environment checks.
if(defined( 'MW_SETUP_CALLBACK')) $dynamicDefaults
Customization point after most things are loaded (constants, functions, classes, LocalSettings.
if(!defined('MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli') if(MW_ENTRY_POINT !=='cli' && $wgPingback $settingsWarnings)
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgOut
$wgConf
$wgConf hold the site configuration.
if( $wgServerName !==false) $wgServerName
if(!interface_exists(LoggerInterface::class)) $wgCommandLineMode
Pre-config setup: Before loading LocalSettings.php.
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgTitle
if($wgServer===false) if( $wgCanonicalServer===false) $wgVirtualRestConfig['global']['domain']
global $wgFullyInitialised
global $wgExtensionFunctions
if(!defined('MW_SETUP_CALLBACK'))
Group all the pieces relevant to the context of a request into one instance.
A class containing constants representing the names of configuration variables.
static init(array $profilerConf)
$wgMemoryLimit
Config variable stub for the MemoryLimit setting, for use by phpdoc and IDEs.
$wgEmergencyContact
Config variable stub for the EmergencyContact setting, for use by phpdoc and IDEs.
$wgSharedTables
Config variable stub for the SharedTables setting, for use by phpdoc and IDEs.
$wgSessionName
Config variable stub for the SessionName setting, for use by phpdoc and IDEs.
$wgLogExceptionBacktrace
Config variable stub for the LogExceptionBacktrace setting, for use by phpdoc and IDEs.
$wgTmpDirectory
Config variable stub for the TmpDirectory setting, for use by phpdoc and IDEs.
$wgNoReplyAddress
Config variable stub for the NoReplyAddress setting, for use by phpdoc and IDEs.
$wgProfiler
Config variable stub for the Profiler setting, for use by phpdoc and IDEs.
$wgSecureLogin
Config variable stub for the SecureLogin setting, for use by phpdoc and IDEs.
$wgLocaltimezone
Config variable stub for the Localtimezone setting, for use by phpdoc and IDEs.
$wgShowExceptionDetails
Config variable stub for the ShowExceptionDetails setting, for use by phpdoc and IDEs.
$wgAllowExternalReqID
Config variable stub for the AllowExternalReqID setting, for use by phpdoc and IDEs.
$wgRequestTimeLimit
Config variable stub for the RequestTimeLimit setting, for use by phpdoc and IDEs.
$wgSharedDB
Config variable stub for the SharedDB setting, for use by phpdoc and IDEs.
$wgCanonicalServer
Config variable stub for the CanonicalServer setting, for use by phpdoc and IDEs.
$wgServer
Config variable stub for the Server setting, for use by phpdoc and IDEs.
$wgPropagateErrors
Config variable stub for the PropagateErrors setting, for use by phpdoc and IDEs.
$wgSharedSchema
Config variable stub for the SharedSchema setting, for use by phpdoc and IDEs.
$wgPasswordSender
Config variable stub for the PasswordSender setting, for use by phpdoc and IDEs.
$wgPingback
Config variable stub for the Pingback setting, for use by phpdoc and IDEs.
$wgCookiePrefix
Config variable stub for the CookiePrefix setting, for use by phpdoc and IDEs.
$wgSharedPrefix
Config variable stub for the SharedPrefix setting, for use by phpdoc and IDEs.
$wgPHPSessionHandling
Config variable stub for the PHPSessionHandling setting, for use by phpdoc and IDEs.