51use 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 );
246if ( !defined(
'MW_NO_SESSION_HANDLER' ) ) {
247 define(
'MW_NO_SESSION_HANDLER', 1 );
250if ( defined(
'MW_SETUP_CALLBACK' ) ) {
266require __DIR__ .
'/SetupDynamicConfig.php';
268if ( defined(
'MW_AUTOLOAD_TEST_CLASSES' ) ) {
269 require_once __DIR__ .
'/../tests/Common/TestsAutoLoader.php';
280if ( defined(
'MW_AUTOLOAD_TEST_CLASSES' ) ) {
281 ExtensionRegistry::getInstance()->setLoadTestClassesAndNamespaces(
true );
284ExtensionRegistry::getInstance()->setSettingsBuilder(
$wgSettings );
285ExtensionRegistry::getInstance()->loadFromQueue();
287ExtensionRegistry::getInstance()->finish();
294if ( defined(
'MW_FINAL_SETUP_CALLBACK' ) ) {
295 call_user_func( MW_FINAL_SETUP_CALLBACK,
$wgSettings );
308if ( PHP_OS_FAMILY !==
'Darwin' && setlocale( LC_ALL,
'C.UTF-8' ) ) {
317putenv(
"LC_ALL={$locale}" );
328MediaWikiServices::allowGlobalInstance();
332define(
'MW_SERVICE_BOOTSTRAP_COMPLETE', 1 );
335if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
345call_user_func(
static function (): void {
350 $tracer = MediaWikiServices::getInstance()->getTracer();
351 $request = RequestContext::getMain()->getRequest();
353 $startTimeNanos = (int)( 1e9 * $_SERVER[
'REQUEST_TIME_FLOAT'] );
356 $spanName =
"EntryPoint " .
MW_ENTRY_POINT .
".php HTTP {$request->getMethod()}";
359 $rootSpan->setSpanKind( SpanInterface::SPAN_KIND_SERVER )
360 ->setAttributes( array_filter( [
361 'http.request.method' =>
$request->getMethod(),
362 'url.path' =>
$request->getRequestURL(),
363 'server.name' => $_SERVER[
'SERVER_NAME'] ??
null,
365 ->start( $startTimeNanos );
366 $rootSpan->activate();
368 TracerState::getInstance()->setRootSpan( $rootSpan );
376 '$wgServer must be set in LocalSettings.php. ' .
377 'See <a href="https://www.mediawiki.org/wiki/Manual:$wgServer">' .
378 'https://www.mediawiki.org/wiki/Manual:$wgServer</a>.'
386 $wgCanonicalServer = MediaWikiServices::getInstance()->getUrlUtils()->getCanonicalServer();
391 wfWarn(
'$wgServerName should be derived from $wgCanonicalServer, '
392 .
'not customized. Overwriting $wgServerName.' );
411 wfWarn(
'Secure login was enabled on a server that only supports '
412 .
'HTTP or HTTPS. Disabling secure login.' );
422 MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
442$wgRequest = RequestContext::getMain()->getRequest();
445if ( RequestContext::getMain()->getRequest()->getCookie(
'UseDC',
'' ) ===
'master' ) {
449 MediaWikiServices::getInstance()->getMainWANObjectCache()->useInterimHoldOffCaching(
false );
453(
static function () {
454 $logger = LoggerFactory::getInstance(
'wfDebug' );
456 $self = $_SERVER[
'PHP_SELF'] ??
'';
457 $logger->debug(
"\n\nStart command line script $self" );
459 $request = RequestContext::getMain()->getRequest();
460 $debug =
"\n\nStart request {$request->getMethod()} {$request->getRequestURL()}\n";
461 $debug .=
"IP: " .
$request->getIP() .
"\n";
462 $debug .=
"HTTP HEADERS:\n";
463 foreach (
$request->getAllHeaders() as $name => $value ) {
464 $debug .=
"$name: $value\n";
466 $debug .=
"(end headers)";
473 $logger = LoggerFactory::getInstance(
'Settings' );
475 $logger->warning( $msg );
483(
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onSetupAfterCache();
495 RequestContext::getMain()->getRequest()->interpolateTitle();
500 register_shutdown_function( MediaWikiServices::getInstance()->getSessionManager()->shutdown( ... ) );
502 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
506 $session = RequestContext::getMain()->getRequest()->getSession();
507 }
catch (
MediaWiki\Session\SessionOverflowException $ex ) {
511 foreach ( $ex->getSessionInfos() as $info ) {
512 $list[] = $info->getProvider()->describe( $contLang );
514 $list = $contLang->listToText( $list );
516 Message::newFromKey(
'sessionmanager-tie', $list )->inLanguage( $contLang )
539$wgOut = RequestContext::getMain()->getOutput();
563 $sessionUser = RequestContext::getMain()->getRequest()->getSession()->getUser();
564 $autocreateStatus =
null;
565 if ( !$sessionUser->isRegistered() &&
566 MediaWikiServices::getInstance()->getUserNameUtils()->isValid( $sessionUser->getName() )
568 $autocreateStatus = MediaWikiServices::getInstance()->getAuthManager()->autoCreateUser(
570 MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_SESSION
578 $manager = MediaWikiServices::getInstance()->getSessionManager();
580 $manager->logPotentialSessionLeakage();
584 if ( $autocreateStatus ) {
587 if ( $autocreateStatus->isOK() ) {
588 if ( !$sessionUser->isRegistered() ) {
589 throw new LogicException(
"Session user should be registered, but it's not" );
591 if ( !RequestContext::getMain()->getUser()->isRegistered() ) {
592 throw new LogicException(
"Global context user should be registered, but it's not" );
595 if ( $sessionUser->isRegistered() ) {
596 throw new LogicException(
"Session user should not be registered, but it is" );
598 if ( RequestContext::getMain()->getUser()->isRegistered() ) {
599 throw new LogicException(
"Global context user should not be registered, but it is" );
603 unset( $sessionUser );
604 unset( $autocreateStatus );
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).
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli') global $wgLang
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') global $wgOut
$wgConf
$wgConf hold the site configuration.
if( $wgServerName !==false) $wgServerName
if(!defined('MW_NO_SESSION_HANDLER')) if(defined( 'MW_SETUP_CALLBACK')) $dynamicDefaults
Customization point after most things are loaded (constants, functions, classes, LocalSettings.
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') global $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.
$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.
$wgSharedPrefix
Config variable stub for the SharedPrefix setting, for use by phpdoc and IDEs.