r109414 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109413‎ | r109414 | r109415 >
Date:17:53, 18 January 2012
Author:siebrand
Status:ok
Tags:languagegetmagic 
Comment:
Update documentation.
Modified paths:
  • /trunk/phase3/docs/magicword.txt (modified) (history)

Diff [purge]

Index: trunk/phase3/docs/magicword.txt
@@ -12,9 +12,6 @@
1313 should include #REDIRECT.
1414
1515 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.
1916 * By adding a file to $wgExtensionMessagesFiles and defining there $magicWords.
2017 This array is associative with the language code in the first dimension key
2118 and then a "normal" array of magic words.
@@ -27,8 +24,24 @@
2825
2926 For example to add a new variable:
3027
 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';
3145 $wgHooks['MagicWordwgVariableIDs'][] = 'wfAddCustomMagicWordID';
32 -$wgHooks['LanguageGetMagic'][] = 'wfAddCustomMagicWordLang';
3346 $wgHooks['ParserGetVariableValueSwitch'][] = 'wfGetCustomMagicWordValue';
3447
3548 function wfAddCustomMagicWordID( &$magicWords ) {
@@ -36,17 +49,6 @@
3750 return true;
3851 }
3952
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 -
5153 function wfGetCustomMagicWordValue( &$parser, &$varCache, &$index, &$ret ){
5254 if( $index == 'mag_custom' ){
5355 $ret = $varCache['mag_custom'] = "Custom value";
@@ -56,20 +58,25 @@
5759
5860 And to add a new parser function:
5961
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';
6179 $wgHooks['ParserFirstCallInit'][] = 'wfRegisterCustomMagicWord';
6280
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 -
7481 function wfRegisterCustomMagicWord( &$parser ){
7582 $parser->setFunctionHook( 'mag_custom', 'wfGetCustomMagicWordValue' );
7683 return true;

Sign-offs

UserFlagDate
Nikerabbitinspected08:57, 19 January 2012

Status & tagging log