Magic words are localizable keywords in wikitext that the parser recognizes and replaces with dynamic values or that control parser behavior. FromDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/wikimedia/mediawiki/llms.txt
Use this file to discover all available pages before exploring further.
magicword.md:
Magic words are localizable keywords used in wikitext. They are used for many small fragments of text, including the names of parser functions, the names of variables, double-underscore behavior switches, and image link parameter names.Each magic word has a unique ID, a case-sensitivity flag, and a list of synonyms. The
MagicWord class matches wikitext against these synonyms by compiling them into a regular expression.
Types of magic words
Behavior switches
Double-underscore keywords that toggle parser behavior. Examples:
__TOC__, __NOTOC__, __NOINDEX__, __FORCETOC__. They produce no output but modify how the page is rendered.Variables
Transclusion-style keywords that expand to dynamic values. Examples:
{{PAGENAME}}, {{CURRENTDAY}}, {{NUMBEROFARTICLES}}. They take no arguments.Parser functions
Variable-style keywords that accept arguments:
{{urlencode:foo bar}}, {{#if: condition | then | else }}. The #-prefixed form is conventional for extension-defined functions.Image parameters
Keywords used inside
[[File:...]] syntax to control image rendering: thumb, right, left, center, frameless.Core variables
Core magic variables are implemented inCoreMagicVariables. Some variables have cache TTL hints because their values change over time:
# prefix (registered via Parser::SFH_NO_HASH) include:
Registering magic words in an extension
Step 1: create the i18n magic words file
Create a file namedExtensionName.i18n.magic.php. The array is keyed by language code, then by magic word ID. Index 0 is the case sensitivity flag (0 = case-insensitive, 1 = case-sensitive); subsequent indices are synonyms.
Step 2: register the file in extension.json
Step 3: implement the parser function hook
{{custom: arg1 | arg2 }} (English) and {{aduanero: arg1 | arg2 }} (Spanish) as equivalent.
Behavior switches
Behavior switches use double-underscore syntax and are matched by theMagicWord class. To add a custom behavior switch:
Register the behavior switch ID
Use the In
GetDoubleUnderscoreIDs hook to add your ID to the list of recognized behavior switches:extension.json:Variables (magic variables)
To register a custom variable that expands to a dynamic value, use theGetMagicVariableIDs hook plus ParserGetVariableValueSwitch:
extension.json:
{{CUSTOMVAR}}.
MagicWord matching API
TheMagicWord class provides methods for matching text against a magic word:
