66use MediaWiki\MainConfigSchema;
82use Psr\Log\LoggerInterface;
84use Wikimedia\RequestTimeout\RequestTimeout;
96if ( !defined(
'MEDIAWIKI' ) ) {
103if ( !defined(
'MW_ENTRY_POINT' ) ) {
109 define(
'MW_ENTRY_POINT',
'unknown' );
124require_once MW_INSTALL_PATH .
'/includes/AutoLoader.php';
125require_once MW_INSTALL_PATH .
'/includes/Defines.php';
128if ( !interface_exists( LoggerInterface::class ) ) {
130 '<strong>Error: Missing external libraries.</strong> ' .
131 'MediaWiki depends on external libraries bundled with most MediaWiki distributions. ' .
132 "When installing MediaWiki from its Git reposistory, these must be installed separately.\n\n" .
133 'Please see the <a href="https://www.mediawiki.org/wiki/Download_from_Git' .
134 '#Fetch_external_libraries">instructions for installing libraries</a> on mediawiki.org ' .
135 'for help on installing the required libraries.'
137 http_response_code( 500 );
139 error_log( $message );
158if ( defined(
'MW_USE_CONFIG_SCHEMA_CLASS' ) ) {
167require_once MW_INSTALL_PATH .
'/includes/GlobalFunctions.php';
170HeaderCallback::register();
174HttpStatus::registerHeadersSentCallback(
175 [ HeaderCallback::class,
'warnIfHeadersSent' ]
180mb_internal_encoding(
'UTF-8' );
189 MainConfigNames::ExtensionDirectory => MW_INSTALL_PATH .
'/extensions',
190 MainConfigNames::StyleDirectory => MW_INSTALL_PATH .
'/skins',
191 MainConfigNames::UploadDirectory => MW_INSTALL_PATH .
'/images',
192 MainConfigNames::ServiceWiringFiles => [ MW_INSTALL_PATH .
'/includes/ServiceWiring.php' ],
201if ( !isset( $GLOBALS[
'wgScopeTest'] ) || $GLOBALS[
'wgScopeTest'] !==
$wgScopeTest ) {
202 foreach (
$wgSettings->getConfigSchema()->getDefinedKeys() as $key ) {
212 if ( defined(
'MW_CONFIG_CALLBACK' ) ) {
217 if ( getenv(
'MW_USE_LOCAL_SETTINGS_LOADER' ) ) {
221 $localSettingsLoader->loadLocalSettingsFile( MW_CONFIG_FILE );
222 unset( $localSettingsLoader );
224 if ( str_ends_with( MW_CONFIG_FILE,
'.php' ) ) {
227 require_once MW_CONFIG_FILE;
242if (
$wgSettings->getConfig()->get( MainConfigNames::WikiFarmSettingsDirectory ) ) {
244 $wikiFarmSettingsLoader->loadWikiFarmSettings();
245 unset( $wikiFarmSettingsLoader );
258if ( defined(
'MW_SETUP_CALLBACK' ) ) {
274require __DIR__ .
'/SetupDynamicConfig.php';
276if ( defined(
'MW_AUTOLOAD_TEST_CLASSES' ) ) {
277 require_once __DIR__ .
'/../tests/common/TestsAutoLoader.php';
288if ( defined(
'MW_AUTOLOAD_TEST_CLASSES' ) ) {
289 ExtensionRegistry::getInstance()->setLoadTestClassesAndNamespaces(
true );
292ExtensionRegistry::getInstance()->setSettingsBuilder(
$wgSettings );
293ExtensionRegistry::getInstance()->loadFromQueue();
295ExtensionRegistry::getInstance()->finish();
302if ( defined(
'MW_FINAL_SETUP_CALLBACK' ) ) {
303 call_user_func( MW_FINAL_SETUP_CALLBACK,
$wgSettings );
317putenv(
"LC_ALL=" . setlocale( LC_ALL,
'C.UTF-8',
'C' ) );
327MediaWikiServices::allowGlobalInstance();
331define(
'MW_SERVICE_BOOTSTRAP_COMPLETE', 1 );
334if ( !defined(
'MW_PHPUNIT_TEST' ) ) {
344call_user_func(
static function (): void {
349 $tracer = MediaWikiServices::getInstance()->getTracer();
350 $request = RequestContext::getMain()->getRequest();
352 $startTimeNanos = (int)( 1e9 * $_SERVER[
'REQUEST_TIME_FLOAT'] );
355 $spanName =
"EntryPoint " .
MW_ENTRY_POINT .
".php HTTP {$request->getMethod()}";
357 $rootSpan = $tracer->createRootSpanFromCarrier( $spanName,
$wgAllowExternalReqID ? $request->getAllHeaders() : [] );
358 $rootSpan->setSpanKind( SpanInterface::SPAN_KIND_SERVER )
359 ->setAttributes( array_filter( [
360 'http.request.method' => $request->getMethod(),
361 'url.path' => $request->getRequestURL(),
362 'server.name' => $_SERVER[
'SERVER_NAME'] ??
null,
364 ->start( $startTimeNanos );
365 $rootSpan->activate();
367 TracerState::getInstance()->setRootSpan( $rootSpan );
375 '$wgServer must be set in LocalSettings.php. ' .
376 'See <a href="https://www.mediawiki.org/wiki/Manual:$wgServer">' .
377 'https://www.mediawiki.org/wiki/Manual:$wgServer</a>.'
385 $wgCanonicalServer = MediaWikiServices::getInstance()->getUrlUtils()->getCanonicalServer();
390 wfWarn(
'$wgServerName should be derived from $wgCanonicalServer, '
391 .
'not customized. Overwriting $wgServerName.' );
410 wfWarn(
'Secure login was enabled on a server that only supports '
411 .
'HTTP or HTTPS. Disabling secure login.' );
421 MediaWikiServices::getInstance()->getDBLoadBalancer()->setTableAliases(
441$wgRequest = RequestContext::getMain()->getRequest();
444if (
$wgRequest->getCookie(
'UseDC',
'' ) ===
'master' ) {
448 MediaWikiServices::getInstance()->getMainWANObjectCache()->useInterimHoldOffCaching(
false );
452(
static function () {
455 $logger = LoggerFactory::getInstance(
'wfDebug' );
457 $self = $_SERVER[
'PHP_SELF'] ??
'';
458 $logger->debug(
"\n\nStart command line script $self" );
460 $debug =
"\n\nStart request {$wgRequest->getMethod()} {$wgRequest->getRequestURL()}\n";
461 $debug .=
"IP: " .
$wgRequest->getIP() .
"\n";
462 $debug .=
"HTTP HEADERS:\n";
463 foreach (
$wgRequest->getAllHeaders() as $name => $value ) {
464 $debug .=
"$name: $value\n";
466 $debug .=
"(end headers)";
467 $logger->debug( $debug );
472(
new HookRunner( MediaWikiServices::getInstance()->getHookContainer() ) )->onSetupAfterCache();
494 HeaderCallback::warnIfHeadersSent();
500 if ( !defined(
'MW_NO_SESSION_HANDLER' ) ) {
501 MediaWiki\Session\PHPSessionHandler::install(
502 MediaWiki\Session\SessionManager::singleton()
506 $contLang = MediaWikiServices::getInstance()->getContentLanguage();
510 $session = MediaWiki\Session\SessionManager::getGlobalSession();
511 }
catch (
MediaWiki\Session\SessionOverflowException $ex ) {
515 foreach ( $ex->getSessionInfos() as $info ) {
516 $list[] = $info->getProvider()->describe( $contLang );
518 $list = $contLang->listToText( $list );
520 Message::newFromKey(
'sessionmanager-tie', $list )->inLanguage( $contLang )
526 if ( $session->isPersistent() ) {
531 if (
MediaWiki\Session\PHPSessionHandler::isEnabled() &&
532 ( $session->isPersistent() || $session->shouldRememberUser() ) &&
533 session_id() !== $session->getId()
536 if ( session_id() !==
'' ) {
537 wfDebugLog(
'session',
'PHP session {old_id} was already started, changing to {new_id}',
'all', [
538 'old_id' => session_id(),
539 'new_id' => $session->getId(),
541 session_write_close();
543 session_id( $session->getId() );
551 if ( !defined(
'MW_NO_SESSION_HANDLER' ) ) {
552 MediaWiki\Session\PHPSessionHandler::install(
553 MediaWiki\Session\SessionManager::singleton()
567register_shutdown_function(
static function () {
568 StubGlobalUser::$destructorDeprecationDisarmed =
true;
579$wgOut = RequestContext::getMain()->getOutput();
601 $sessionUser = MediaWiki\Session\SessionManager::getGlobalSession()->getUser();
602 if ( $sessionUser->getId() === 0 &&
603 MediaWikiServices::getInstance()->getUserNameUtils()->isValid( $sessionUser->getName() )
605 MediaWikiServices::getInstance()->getAuthManager()->autoCreateUser(
607 MediaWiki\Auth\AuthManager::AUTOCREATE_SOURCE_SESSION,
613 unset( $sessionUser );
624 DeferredUpdates::addCallableUpdate(
static function () {
625 MediaWikiServices::getInstance()->getPingback()->run();
631 $logger = LoggerFactory::getInstance(
'Settings' );
633 $logger->warning( $msg );
646 MediaWiki\Session\SessionManager::singleton()->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)
global $wgInitialSessionId
if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang
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(!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.