r115609 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r115608‎ | r115609 | r115610 >
Date:11:57, 15 July 2012
Author:dasch
Status:deferred
Tags:
Comment:
FormatNum - moved hooks like wished in r98351
Modified paths:
  • /trunk/extensions/FormatNum/FormatNum.hooks.php (added) (history)
  • /trunk/extensions/FormatNum/FormatNum.php (modified) (history)

Diff [purge]

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', '&thinsp;', $output );
 23+ break;
 24+ case 'n':
 25+ $output = str_replace ( 'n', '&nbsp;', $output );
 26+ break;
 27+ }
 28+ return $output;
 29+ }
 30+}
Property changes on: trunk/extensions/FormatNum/FormatNum.hooks.php
___________________________________________________________________
Added: svn:eol-style
131 + native
Index: trunk/extensions/FormatNum/FormatNum.php
@@ -26,30 +26,5 @@
2727 $wgExtensionMessagesFiles['FormatNumMagic'] = $dir . 'FormatNum.i18n.magic.php';
2828
2929 # 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', '&thinsp;', $output );
50 - break;
51 - case 'n':
52 - $output = str_replace ( 'n', '&nbsp;', $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

Follow-up revisions

RevisionCommit summaryAuthorDate
r115611fix for r115609dasch12:36, 15 July 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r98351Adding Extensions FormatNum and ThumbParserdasch19:06, 28 September 2011

Status & tagging log