Index: trunk/phase3/docs/magicword.txt |
— | — | @@ -12,9 +12,6 @@ |
13 | 13 | should include #REDIRECT. |
14 | 14 | |
15 | 15 | They can be added in several arrays: |
16 | | -* LanguageGetMagic hook, by adding a new key in $magicWords array. You can get |
17 | | - language code in the $lang parameter. Use both the localized name and the |
18 | | - English name. |
19 | 16 | * By adding a file to $wgExtensionMessagesFiles and defining there $magicWords. |
20 | 17 | This array is associative with the language code in the first dimension key |
21 | 18 | and then a "normal" array of magic words. |
— | — | @@ -27,8 +24,24 @@ |
28 | 25 | |
29 | 26 | For example to add a new variable: |
30 | 27 | |
| 28 | +Create a file called ExtensionName.i18n.magic.php with the following contents: |
| 29 | +---- |
| 30 | +<?php |
| 31 | + |
| 32 | +$magicWords = array(); |
| 33 | + |
| 34 | +$magicWords['en'] = array( |
| 35 | + // Case sensitive. |
| 36 | + 'mag_custom' => array( 1, 'CUSTOM' ), |
| 37 | +); |
| 38 | + |
| 39 | +$magicWords['es'] = array( |
| 40 | + 'mag_custom' => array( 1, 'ADUANERO' ), |
| 41 | +); |
| 42 | +---- |
| 43 | + |
| 44 | +$wgExtensionMessagesFiles['ExtensionNameMagic'] = dirname( __FILE__ ) . '/ExtensionName.i18n.magic.php'; |
31 | 45 | $wgHooks['MagicWordwgVariableIDs'][] = 'wfAddCustomMagicWordID'; |
32 | | -$wgHooks['LanguageGetMagic'][] = 'wfAddCustomMagicWordLang'; |
33 | 46 | $wgHooks['ParserGetVariableValueSwitch'][] = 'wfGetCustomMagicWordValue'; |
34 | 47 | |
35 | 48 | function wfAddCustomMagicWordID( &$magicWords ) { |
— | — | @@ -36,17 +49,6 @@ |
37 | 50 | return true; |
38 | 51 | } |
39 | 52 | |
40 | | -function wfAddCustomMagicWordLang( &$magicWords, $langCode ) { |
41 | | - switch ( $langCode ) { |
42 | | - case 'es': |
43 | | - $magicWords['mag_custom'] = array( 1, "ADUANERO", "CUSTOM" ); |
44 | | - break; |
45 | | - default: |
46 | | - $magicWords['mag_custom'] = array( 1, "CUSTOM" ); |
47 | | - } |
48 | | - return true; |
49 | | -} |
50 | | - |
51 | 53 | function wfGetCustomMagicWordValue( &$parser, &$varCache, &$index, &$ret ){ |
52 | 54 | if( $index == 'mag_custom' ){ |
53 | 55 | $ret = $varCache['mag_custom'] = "Custom value"; |
— | — | @@ -56,20 +58,25 @@ |
57 | 59 | |
58 | 60 | And to add a new parser function: |
59 | 61 | |
60 | | -$wgHooks['LanguageGetMagic'][] = 'wfAddCustomMagicWordLang'; |
| 62 | +Create a file called ExtensionName.i18n.magic.php with the following contents: |
| 63 | +---- |
| 64 | +<?php |
| 65 | + |
| 66 | +$magicWords = array(); |
| 67 | + |
| 68 | +$magicWords['en'] = array( |
| 69 | + // Case insensitive. |
| 70 | + 'mag_custom' => array( 0, 'custom' ), |
| 71 | +); |
| 72 | + |
| 73 | +$magicWords['es'] = array( |
| 74 | + 'mag_custom' => array( 0, 'aduanero' ), |
| 75 | +); |
| 76 | +---- |
| 77 | + |
| 78 | +$wgExtensionMessagesFiles['ExtensionNameMagic'] = dirname( __FILE__ ) . '/ExtensionName.i18n.magic.php'; |
61 | 79 | $wgHooks['ParserFirstCallInit'][] = 'wfRegisterCustomMagicWord'; |
62 | 80 | |
63 | | -function wfAddCustomMagicWordLang( &$magicWords, $langCode ) { |
64 | | - switch ( $langCode ) { |
65 | | - case 'es': |
66 | | - $magicWords['mag_custom'] = array( 0, "aduanero", "custom" ); |
67 | | - break; |
68 | | - default: |
69 | | - $magicWords['mag_custom'] = array( 0, "custom" ); |
70 | | - } |
71 | | - return true; |
72 | | -} |
73 | | - |
74 | 81 | function wfRegisterCustomMagicWord( &$parser ){ |
75 | 82 | $parser->setFunctionHook( 'mag_custom', 'wfGetCustomMagicWordValue' ); |
76 | 83 | return true; |