Request lifecycle
Every web request to MediaWiki passes through one of four entry points, each a thin PHP file that sets anMW_ENTRY_POINT constant and then bootstraps the full application via includes/WebStart.php → includes/Setup.php:
Entry points
| File | Class | Handles |
|---|---|---|
index.php | ActionEntryPoint | Page views, actions (edit, history, delete…), special pages |
api.php | ApiEntryPoint | All Action API (?action=…) queries |
rest.php | Rest\EntryPoint | REST API (/rest.php/v1/…) requests |
load.php | ResourceLoaderEntryPoint | CSS/JS asset bundles via ResourceLoader |
MW_ENTRY_POINT before including WebStart.php:
Bootstrap sequence (Setup.php)
includes/Setup.php is the single file responsible for bootstrapping all MediaWiki processes, both web and CLI. Its sequence is documented in its own file header:
- Runtime environment checks — PHP version, required extensions
- Define
MW_INSTALL_PATHand$IP— the install path constants - Load
AutoLoader.php,Defines.php— class autoloading and constants - Assert Composer dependencies — fails fast with a helpful message if
vendor/is missing - Load
LocalSettings.php— site configuration viaSettingsBuilder - Load extensions —
ExtensionRegistryreads allextension.jsonfiles - Initialize
MediaWikiServices— the DI service container - Initialize
MWExceptionHandler— installs the global exception handler - Initialize
SessionManager— sets up the PHP session - Apply dynamic config defaults — settings that depend on other resolved settings
Setup.php must be included from a valid entry point that has defined the MEDIAWIKI constant. Accessing it directly from a browser will exit immediately. This is a deliberate security constraint.The service container
MediaWikiServices is the central service locator for all of MediaWiki core. It extends Wikimedia\Services\ServiceContainer (from wikimedia/services) and exposes typed accessor methods for every core service.
includes/ServiceWiring.php. Extensions can add their own services by declaring a ServiceWiringFiles entry in extension.json.
Accessing services
The recommended approach for code in MediaWiki core is to receive services via constructor injection:MediaWikiServices::getInstance() is only available after Setup.php has called MediaWikiServices::allowGlobalInstance(). Calling it before that point (e.g., at class-load time) will throw a LogicException. Always inject dependencies via constructors in new code.The hook system
MediaWiki’s hook system allows extensions to observe and modify core behavior without patching core files. The system is implemented through two classes:HookContainer— Manages hook handler registration and dispatch. Extensions register handlers inextension.jsonunder the"Hooks"key.HookRunner— A generated class that provides typed methods for calling every core hook, replacing the oldHooks::run()string-based dispatch.
Major subsystems
Parser
The
Parser class (and the newer Parsoid-based ParsoidParserFactory) converts wikitext markup into HTML. The ParserCache stores parsed output keyed by page revision and options. Parser functions and tag hooks registered by extensions are called during parsing. Services: ParserFactory, ParserCache, ParsoidParserFactory.ResourceLoader
ResourceLoader (
load.php → ResourceLoaderEntryPoint) bundles and delivers JavaScript and CSS modules to the browser. It handles dependency resolution, language-specific variants, minification via wikimedia/minify, LESS compilation via wikimedia/less.php, and cache busting. Modules are registered in extension.json under "ResourceModules".Auth
The
AuthManager service handles all login, account creation, and session management flows through a pluggable provider system (AuthenticationProvider). Session state is managed by SessionManager. Password hashing uses PasswordFactory, which supports multiple algorithms including Argon2. Permissions checks go through PermissionManager.Database
Database access uses the
IConnectionProvider interface backed by LBFactory (load balancer factory from wikimedia/rdbms). Core supports MariaDB/MySQL, PostgreSQL, and SQLite. The abstraction layer normalizes SQL across backends and handles primary/replica routing. Schema changes are managed by DatabaseUpdater in maintenance/update.php.JobQueue
Deferred work (link updates, HTML cache purges, notifications) is dispatched through
JobQueueGroup and processed asynchronously by job runners. In the Docker setup, a dedicated mediawiki-jobrunner container handles this. In the manual setup, jobs run inline or via maintenance/runJobs.php. Job classes are registered in extension.json under "JobClasses".ObjectCache
ObjectCacheFactory provides access to caching backends — APCu (local), Memcached, or Redis — through a unified BagOStuff interface. WANObjectCache adds a write-around layer with cross-datacenter invalidation support. The ParserCache and MessageCache are built on top of these primitives.Extension loading
Extensions are discovered and loaded byExtensionRegistry during Setup.php. Each extension ships an extension.json manifest declaring its metadata, class autoloading, hook handlers, service wiring files, ResourceLoader modules, and database schema changes.
wfLoadExtension() call to LocalSettings.php:
ExtensionRegistry reads all extension.json files, merges their configurations, and triggers the MediaWiki\Registration\ExtensionProcessor to register hooks, autoloaders, and services before MediaWikiServices is finalized.
Extensions must never modify core MediaWiki files. All extension-to-core integration points go through
extension.json declarations and the hook system. This ensures that core can be upgraded without losing extension changes.Configuration
Site configuration is loaded fromLocalSettings.php via SettingsBuilder. Configuration keys are declared with types and defaults in includes/MainConfigSchema.php (or the compiled includes/config-schema.php). Settings are accessed throughout the codebase as $wgSomeConfigKey globals (legacy) or via the Config service interface (preferred in new code).
