Manual:Hooks/LanguageGetMagic
File:OOjs UI icon alert-destructive.svg | <translate> This feature was removed completely in version <tvar name=ver>1.33.0</tvar> (after being deprecated in <tvar name=4>1.16.0</tvar>).</translate> |
LanguageGetMagic | |
---|---|
<translate> Available from <tvar name=1><translate> version <tvar </tvar></translate> <translate> Removed in <tvar name=1><translate> version <tvar (Gerrit change 439793)</tvar></translate> Use this to define synonyms of magic words depending of the language. | |
<translate> Define function:</translate> | public static function onLanguageGetMagic( array &$magicWords, $langCode ) { ... }
|
<translate> Attach hook:</translate> | <translate> In <tvar name=1>extension.json</tvar>:</translate>
{
"Hooks": {
"LanguageGetMagic": "MediaWiki\\Extension\\MyExtension\\Hooks::onLanguageGetMagic"
}
}
|
<translate> Called from:</translate> | <translate> File(s):</translate> ../languages/Language.php |
<translate> Interface:</translate> | LanguageGetMagicHook.php |
<translate> For more information about attaching hooks, see <tvar name=1>Manual:Hooks </tvar>.</translate>
<translate> For examples of extensions using this hook, see <tvar name=cat>Category:LanguageGetMagic extensions</tvar>.</translate>
See Magic Words for current implementations.
LanguageGetMagic was an event for which a hook was available. Correspondingly it is an index of the array $wgHooks . The array value is an array of function names. To add a function name, a parser function extension can use a statement like:
$wgHooks['LanguageGetMagic'][] = "function_defining_magic_words";
These functions provide for each parser function, optionally depending on $Langcode, a list of names that can be used in the wikitext for the parser function, and whether these names are case-sensitive (0=no, 1=yes):
$magicWords['magic_word_ID'] = array( case_sensitivity_code, comma-separated_list_of_magic_words );
Thus in the simplest case it defines a single name for a single function, independent of language:
function ''function_defining_magic_words''( &$magicWords, $langCode ) {
$magicWords['magic_word_id'] = array( 0, 'function_name_in_wikitext' );
return true; // unless we return true, other parser function extensions won't get loaded.
}
Function setFunctionHook in Parser.php fills array mFunctionSynonyms with magic word IDs for all synonyms in the applicable language of all functions:
$this->mFunctionSynonyms[$sensitive][$syn] = $id;
and uses this in function braceSubstitution to convert a function synonym to a function ID.
In MediaWiki 1.6.x
Prior to MW 1.7, there was only one argument, which contained the array of magic words for the current language.