Manual:Hooks/LanguageGetMagic

From MediaWiki.org
Jump to navigation Jump to search
LanguageGetMagic
Available from version 1.6.0
Removed in version 1.33
Use this to define synonyms of magic words depending of the language.
Define function:
public static function onLanguageGetMagic( array &$magicWords, $langCode ) { ... }
Attach hook:

In extension.json:

{
	"Hooks": {
		"LanguageGetMagic": "MyExtensionHooks::onLanguageGetMagic"
	}
}

For MediaWiki ≤1.25:

$wgHooks['LanguageGetMagic'][] = 'MyExtensionHooks::onLanguageGetMagic';
Called from:File(s): Language.php

For more information about attaching hooks, see Manual:Hooks.
For examples of extensions using this hook, see Category:LanguageGetMagic extensions.

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[edit]

Prior to MW 1.7, there was only one argument, which contained the array of magic words for the current language.

See also[edit]