extension.json is the manifest file read by ExtensionRegistry when an extension is loaded via wfLoadExtension(). It declares all metadata, PHP autoloading, hook registrations, i18n directories, ResourceLoader modules, services, and entry points for your extension.
The file must contain at minimum manifest_version and name. The current schema version is 2.
Comprehensive example
The following example covers the most commonly used fields:extension.json
Identity fields
manifest_version
manifest_version
Required. Integer version of the extension.json schema. Must be
2 for new extensions. The oldest supported version is 1, supported since MediaWiki 1.25. Version 2 is supported since MediaWiki 1.29.name
name
Required. The extension’s canonical name as a string. This is used as the directory name and in
Special:Version.version
version
Semantic version string for this release of the extension.
author
author
url
url
URL to the extension’s homepage. Must be a valid URI reference.
descriptionmsg
descriptionmsg
i18n message key for the extension description shown in
Special:Version. Preferred over the raw description field because it allows translation.license-name
license-name
SPDX identifier for the extension’s license.
type
type
The extension’s functional category. Defaults to
"other". Valid values include: api, antispam, editor, media, parserhook, semantic, skin, specialpage, variable, wikibase, other.Dependency requirements
Therequires object declares version constraints that MediaWiki checks before loading the extension. If constraints are not satisfied, the extension is not loaded and an error is shown.
| Key | Description |
|---|---|
MediaWiki | Version constraint string against MediaWiki core. |
platform.php | Version constraint string against PHP. |
platform.ext-* | Required PHP extension. Value must be "*". |
platform.ability-shell | Boolean; true if shell access is required. |
extensions | Map of extension name to version constraint. |
skins | Map of skin name to version constraint. |
suggests for optional dependencies that enhance but are not required by the extension. Use dev-requires for development-only dependencies.
Autoloading
- AutoloadNamespaces (PSR-4)
- AutoloadClasses (legacy)
- TestAutoloadNamespaces
Maps a PHP namespace to a directory path relative to the extension root. All classes under that namespace are resolved to the corresponding file path automatically.With this mapping,
MediaWiki\Extension\FoodProcessor\HookHandler maps to src/HookHandler.php. The trailing backslash in the namespace key and trailing slash in the path are required by the schema.Hook registration
Hooks are registered in two coordinated fields:HookHandlers defines handler objects, and Hooks maps hook names to those objects.
HookHandlers
HookHandlers is a map of handler names to ObjectFactory specifications. The class key is the fully-qualified class name; services lists MediaWiki services to inject into the constructor.
Hooks
Hooks maps hook names to handler names defined in HookHandlers. The value can be a plain string (shorthand), an object with a handler key, or an array of such values.
DeprecatedHooks
Declares hooks that your extension defines and has deprecated. This activates call filtering so that extensions that acknowledge the deprecation have their handlers skipped.| Field | Description |
|---|---|
deprecatedVersion | Required. Version in which the hook was deprecated. |
component | The component name shown in warnings. Defaults to the extension name. |
silent | If true, no deprecation warning is raised but call filtering is still activated. |
Localisation
MessagesDirs
Maps a name to one or more directory paths containing JSON i18n files. Each locale file (e.g.en.json, fr.json) in those directories is registered with the MediaWiki localisation system.
{language-code}.json and a qqq.json for documentation.
ResourceLoader modules
ResourceFileModulePaths
Sets default base paths for allResourceModules in this extension, avoiding repetition.
ResourceModules
Registers ResourceLoader file modules. Module names must match^[a-zA-Z0-9-\.]+$. Each module supports the following common fields:
| Field | Description |
|---|---|
scripts | JavaScript files to always include. |
styles | CSS/Less files to always load. |
messages | i18n message keys to make available in JavaScript via mw.msg(). |
dependencies | Other ResourceLoader modules that must be loaded first. |
packageFiles | Files that can be require()d from other scripts in the module. |
skinStyles | Per-skin CSS overrides. |
group | Loading group for the module. |
noflip | If true, skips CSSJanus RTL flipping. |
Services
ServiceWiringFiles
Lists PHP files that return service factory arrays. These are loaded by the defaultMediaWikiServices instance. See the Extension Services page for a full guide.
Entry points
SpecialPages
Registers special pages. Values are class names or ObjectFactory specifications.APIModules
Registers action API modules (forapi.php?action=...). Values are class names.
| Field | API query type |
|---|---|
APIPropModules | prop= query submodules |
APIListModules | list= query submodules |
APIMetaModules | meta= query submodules |
APIFormatModules | Output format modules |
ContentHandlers
Maps content model IDs to handler class names or ObjectFactory specifications. The key is the model ID (a string matching^[A-Za-z]+$).
Configuration variables
Extension configuration is declared in theconfig object. Each key becomes a global variable prefixed with wg (or a custom prefix set by config_prefix).
$wgFoodProcessorMaxItems and $wgFoodProcessorAllowedTypes globals. The merge_strategy field controls how LocalSettings.php overrides interact with the default value:
| Strategy | Behaviour |
|---|---|
provide_default | The config value is only used if not already set. |
array_merge | Arrays are merged with array_merge(). Default. |
array_plus | Arrays are merged with +. |
array_plus_2d | Two-dimensional arrays are merged with +. |
array_replace_recursive | Deep merge using array_replace_recursive(). |
