Index: trunk/extensions/FormatNum/FormatNum.hooks.php |
— | — | @@ -0,0 +1,29 @@ |
| 2 | +<?php |
| 3 | +class FormatNumHooks { |
| 4 | + function efFormatNumParserFunction_Setup( $parser ) { |
| 5 | + # Set a function hook associating the "example" magic word with our function |
| 6 | + $parser->setFunctionHook( 'formatnum', 'efFormatNumParserFunction_Render' ); |
| 7 | + return true; |
| 8 | + } |
| 9 | + |
| 10 | + function efFormatNumParserFunction_Render( $parser, $param1 = 0, $param2 = 0, $param3 = '.', $param4 = ',' ) { |
| 11 | + # The parser function itself |
| 12 | + # The input parameters are wikitext with templates expanded |
| 13 | + # The output should be wikitext too |
| 14 | + if ( $param4 == '_' ){ |
| 15 | + $param4 = ' '; |
| 16 | + } |
| 17 | + $param1 = intval($param1); |
| 18 | + $param2 = intval($param2); |
| 19 | + $output = number_format( $param1, $param2, $param3, $param4 ); |
| 20 | + switch ($param4) { |
| 21 | + case 't': |
| 22 | + $output = str_replace ( 't', ' ', $output ); |
| 23 | + break; |
| 24 | + case 'n': |
| 25 | + $output = str_replace ( 'n', ' ', $output ); |
| 26 | + break; |
| 27 | + } |
| 28 | + return $output; |
| 29 | + } |
| 30 | +} |
Property changes on: trunk/extensions/FormatNum/FormatNum.hooks.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 31 | + native |
Index: trunk/extensions/FormatNum/FormatNum.php |
— | — | @@ -26,30 +26,5 @@ |
27 | 27 | $wgExtensionMessagesFiles['FormatNumMagic'] = $dir . 'FormatNum.i18n.magic.php'; |
28 | 28 | |
29 | 29 | # Define a setup function |
30 | | -$wgHooks['ParserFirstCallInit'][] = 'efFormatNumParserFunction_Setup'; |
31 | | - |
32 | | -function efFormatNumParserFunction_Setup( $parser ) { |
33 | | - # Set a function hook associating the "example" magic word with our function |
34 | | - $parser->setFunctionHook( 'formatnum', 'efFormatNumParserFunction_Render' ); |
35 | | - return true; |
36 | | -} |
37 | | - |
38 | | -function efFormatNumParserFunction_Render( $parser, $param1 = 0, $param2 = 0, $param3 = '.', $param4 = ',' ) { |
39 | | - # The parser function itself |
40 | | - # The input parameters are wikitext with templates expanded |
41 | | - # The output should be wikitext too |
42 | | - if ( $param4 == '_' ){ |
43 | | - $param4 = ' '; |
44 | | - } |
45 | | - $param2 = intval($param2); |
46 | | - $output = number_format( $param1, $param2, $param3, $param4 ); |
47 | | - switch ($param4) { |
48 | | - case 't': |
49 | | - $output = str_replace ( 't', ' ', $output ); |
50 | | - break; |
51 | | - case 'n': |
52 | | - $output = str_replace ( 'n', ' ', $output ); |
53 | | - break; |
54 | | - } |
55 | | - return $output; |
56 | | -} |
| 30 | +$wgAutoloadClasses['FormatNumHooks'] = "$dir/FormatNum.hooks.php"; |
| 31 | +$wgHooks['ParserFirstCallInit'][] = 'FormatNumHooks::efFormatNumParserFunction_Setup'; |
\ No newline at end of file |