52use MediaWiki\MainConfigSchema;
67use Psr\Log\LoggerInterface;
69use Wikimedia\RequestTimeout\RequestTimeout;
81if ( !defined(
'MEDIAWIKI' ) ) {
88if ( !defined(
'MW_ENTRY_POINT' ) ) {
94 define(
'MW_ENTRY_POINT',
'unknown' );
109require_once MW_INSTALL_PATH .
'/includes/AutoLoader.php';
110require_once MW_INSTALL_PATH .
'/includes/Defines.php';
113if ( !interface_exists( LoggerInterface::class ) ) {
115 '<strong>Error: Missing external libraries.</strong> ' .
116 'MediaWiki depends on external libraries bundled with most MediaWiki distributions. ' .
117 "When installing MediaWiki from its Git reposistory, these must be installed separately.\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 libraries.'
122 http_response_code( 500 );
124 error_log( $message );
143if ( defined(
'MW_USE_CONFIG_SCHEMA_CLASS' ) ) {
152require_once MW_INSTALL_PATH .
'/includes/GlobalFunctions.php';
155HeaderCallback::register();
159HttpStatus::registerHeadersSentCallback(
160 HeaderCallback::warnIfHeadersSent( ... )
165mb_internal_encoding(
'UTF-8' );
174 MainConfigNames::ExtensionDirectory => MW_INSTALL_PATH .
'/extensions',
175 MainConfigNames::StyleDirectory => MW_INSTALL_PATH .
'/skins',
176 MainConfigNames::UploadDirectory => MW_INSTALL_PATH .
'/images',
177 MainConfigNames::ServiceWiringFiles => [ MW_INSTALL_PATH .
'/includes/ServiceWiring.php' ],
186if ( !isset( $GLOBALS[
'wgScopeTest'] ) || $GLOBALS[
'wgScopeTest'] !==
$wgScopeTest ) {
187 foreach (
$wgSettings->getConfigSchema()->getDefinedKeys() as $key ) {
197 if ( defined(
'MW_CONFIG_CALLBACK' ) ) {
202 if ( getenv(
'MW_USE_LOCAL_SETTINGS_LOADER' ) ) {
206 $localSettingsLoader->loadLocalSettingsFile( MW_CONFIG_FILE );
207 unset( $localSettingsLoader );
209 if ( str_ends_with( MW_CONFIG_FILE,
'.php' ) ) {
212 require_once MW_CONFIG_FILE;
227if (
$wgSettings->getConfig()->get( MainConfigNames::WikiFarmSettingsDirectory ) ) {
229 $wikiFarmSettingsLoader->loadWikiFarmSettings();
230 unset( $wikiFarmSettingsLoader );
243if ( defined(
'MW_SETUP_CALLBACK' ) ) {
259require __DIR__ .
'/SetupDynamicConfig.php';
261if ( defined(
'MW_AUTOLOAD_TEST_CLASSES' ) ) {
262 require_once __DIR__ .
'/../tests/Common/TestsAutoLoader.php';
273if ( defined(
'MW_AUTOLOAD_TEST_CLASSES' ) ) {
274 ExtensionRegistry::getInstance()->setLoadTestClassesAndNamespaces(
true );
277ExtensionRegistry::getInstance()->setSettingsBuilder(
$wgSettings );
278ExtensionRegistry::getInstance()->loadFromQueue();
280ExtensionRegistry::getInstance()->finish();
287if ( defined(
'MW_FINAL_SETUP_CALLBACK' ) ) {
288 call_user_func( MW_FINAL_SETUP_CALLBACK,
$wgSettings );
301if ( PHP_OS_FAMILY !==
'Darwin' && setlocale( LC_ALL,
'C.UTF-8' ) ) {
310putenv(
"LC_ALL={$locale}" );
321MediaWikiServices::allowGlobalInstance();
325define(
'MW_SERVICE_BOOTSTRAP_COMPLETE', 1 );
328if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
338call_user_func(
static function (): void {
343 $tracer = MediaWikiServices::getInstance()->getTracer();
344 $request = RequestContext::getMain()->getRequest();
346 $startTimeNanos = (int)( 1e9 * $_SERVER[
'REQUEST_TIME_FLOAT'] );
349 $spanName =
"EntryPoint " .
MW_ENTRY_POINT .
".php HTTP {$request->getMethod()}";
351 $rootSpan = $tracer->createRootSpanFromCarrier( $spanName,
$wgAllowExternalReqID ? $request->getAllHeaders() : [] );
352 $rootSpan->setSpanKind( SpanInterface::SPAN_KIND_SERVER )
353 ->setAttributes( array_filter( [
354 'http.request.method' => $request->getMethod(),
355 'url.path' => $request->getRequestURL(),
356 'server.name' => $_SERVER[
'SERVER_NAME'] ??
null,
358 ->start( $startTimeNanos );
359 $rootSpan->activate();
361 TracerState::getInstance()->setRootSpan( $rootSpan );
369 '$wgServer must be set in LocalSettings.php. ' .
370 'See <a href="https://www.mediawiki.org/wiki/Manual:$wgServer">' .
371 'https://www.mediawiki.org/wiki/Manual:$wgServer</a>.'
379 $wgCanonicalServer = MediaWikiServices::getInstance()->getUrlUtils()->getCanonicalServer();
384 wfWarn(
'$wgServerName should be derived from $wgCanonicalServer, '
385 .
'not customized. Overwriting $wgServerName.' );
404 wfWarn(
'Secure login was enabled on a server that only supports '
405 .
'HTTP or HTTPS. Disabling secure login.' );
415 MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
435$wgRequest = RequestContext::getMain()->getRequest();
438if (
$wgRequest->getCookie(
'UseDC',
'' ) ===
'master' ) {
442 MediaWikiServices::getInstance()->getMainWANObjectCache()->useInterimHoldOffCaching(
false );
446(
static function () {
449 $logger = LoggerFactory::getInstance(
'wfDebug' );
451 $self = $_SERVER[
'PHP_SELF'] ??
'';
452 $logger->debug(
"\n\nStart command line script $self" );
454 $debug =
"\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
455 $debug .=
"IP: " .
$wgRequest->getIP() .
"\n";
456 $debug .=
"HTTP HEADERS:\n";
457 foreach (
$wgRequest->getAllHeaders() as $name => $value ) {
458 $debug .=
"$name: $value\n";
460 $debug .=
"(end headers)";
466(
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onSetupAfterCache();
484 HeaderCallback::warnIfHeadersSent();
490 if ( !defined(
'MW_NO_SESSION_HANDLER' ) ) {
491 MediaWiki\Session\PHPSessionHandler::install(
492 MediaWikiServices::getInstance()->getSessionManager()
495 register_shutdown_function( MediaWikiServices::getInstance()->getSessionManager()->shutdown( ... ) );
498 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
502 $session = RequestContext::getMain()->getRequest()->getSession();
503 }
catch (
MediaWiki\Session\SessionOverflowException $ex ) {
507 foreach ( $ex->getSessionInfos() as $info ) {
508 $list[] = $info->getProvider()->describe( $contLang );
510 $list = $contLang->listToText( $list );
512 Message::newFromKey(
'sessionmanager-tie', $list )->inLanguage( $contLang )
519 if (
MediaWiki\Session\PHPSessionHandler::isEnabled() &&
520 ( $session->isPersistent() || $session->shouldRememberUser() ) &&
521 session_id() !== $session->getId()
524 if ( session_id() !==
'' ) {
525 wfDebugLog(
'session',
'PHP session {old_id} was already started, changing to {new_id}',
'all', [
526 'old_id' => session_id(),
527 'new_id' => $session->getId(),
529 session_write_close();
531 session_id( $session->getId() );
539 if ( !defined(
'MW_NO_SESSION_HANDLER' ) ) {
540 MediaWiki\Session\PHPSessionHandler::install(
541 MediaWikiServices::getInstance()->getSessionManager()
544 register_shutdown_function( MediaWikiServices::getInstance()->getSessionManager()->shutdown( ... ) );
559$wgOut = RequestContext::getMain()->getOutput();
581 $sessionUser = RequestContext::getMain()->getRequest()->getSession()->getUser();
582 if ( $sessionUser->getId() === 0 &&
583 MediaWikiServices::getInstance()->getUserNameUtils()->isValid( $sessionUser->getName() )
585 MediaWikiServices::getInstance()->getAuthManager()->autoCreateUser(
587 MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_SESSION
590 unset( $sessionUser );
601 DeferredUpdates::addCallableUpdate(
static function () {
602 MediaWikiServices::getInstance()->getPingback()->run();
608 $logger = LoggerFactory::getInstance(
'Settings' );
610 $logger->warning( $msg );
623 $manager = MediaWikiServices::getInstance()->getSessionManager();
625 $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( '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(!defined('MEDIAWIKI')) if(!defined( 'MW_ENTRY_POINT')) $IP
Environment checks.
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.
$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.