r98351 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98350‎ | r98351 | r98352 >
Date:19:06, 28 September 2011
Author:dasch
Status:fixme (Comments)
Tags:nodeploy 
Comment:
Adding Extensions FormatNum and ThumbParser
Modified paths:
  • /trunk/extensions/FormatNum (added) (history)
  • /trunk/extensions/FormatNum/FormatNum.i18n.php (added) (history)
  • /trunk/extensions/FormatNum/FormatNum.php (added) (history)
  • /trunk/extensions/ThumbParser (added) (history)
  • /trunk/extensions/ThumbParser/ThumbParser.i18n.php (added) (history)
  • /trunk/extensions/ThumbParser/ThumbParser.php (added) (history)

Diff [purge]

Index: trunk/extensions/FormatNum/FormatNum.i18n.php
@@ -0,0 +1,27 @@
 2+<?php
 3+
 4+/**
 5+ * Messages file for the FormatNum extension
 6+ *
 7+ * @addtogroup Extensions
 8+ */
 9+
 10+/**
 11+ * Get all extension messages
 12+ *
 13+ * @return array
 14+ */
 15+$messages = array();
 16+
 17+$messages['qqq'] = array(
 18+ 'formatnum-desc' => 'Description for Special:Version',
 19+);
 20+
 21+$messages['en'] = array(
 22+ 'formatnum-desc' => 'Passes formatnum to php number_format',
 23+);
 24+
 25+$messages['de'] = array(
 26+ 'formatnum-desc' => 'Ermöglicht das formatieren von Zahel mit php number_format',
 27+);
 28+
Property changes on: trunk/extensions/FormatNum/FormatNum.i18n.php
___________________________________________________________________
Added: svn:eol-style
129 + native
Index: trunk/extensions/FormatNum/FormatNum.php
@@ -0,0 +1,57 @@
 2+<?php
 3+/**
 4+* @addtogroup Extensions
 5+*/
 6+// Check environment
 7+if ( !defined( 'MEDIAWIKI' ) ) {
 8+ echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
 9+ die( -1 );
 10+}
 11+
 12+/* Configuration */
 13+
 14+// Credits
 15+$wgExtensionCredits['parserhook'][] = array (
 16+ 'path'=> __FILE__ ,
 17+ 'name'=>'FormatNum',
 18+ 'url'=>'http://www.mediawiki.org/wiki/Extension:FormatNum',
 19+ 'description'=>'Passes formatnum to php number_format',
 20+ 'descriptionmsg' => 'formatnum-desc',
 21+ 'author'=>'[http://www.dasch-tour.de DaSch]',
 22+ 'version'=>'0.1.1',
 23+);
 24+$dir = dirname( __FILE__ ) . '/';
 25+
 26+// Internationalization
 27+$wgExtensionMessagesFiles['FormatNum'] = $dir . 'FormatNum.i18n.php';
 28+
 29+# Define a setup function
 30+$wgHooks['ParserFirstCallInit'][] = 'efFormatNumParserFunction_Setup';
 31+# Add a hook to initialise the magic word
 32+$wgHooks['LanguageGetMagic'][] = 'efFormatNumParserFunction_Magic';
 33+
 34+function efFormatNumParserFunction_Setup( $parser ) {
 35+ # Set a function hook associating the "example" magic word with our function
 36+ $parser->setFunctionHook( 'formatnum', 'efFormatNumParserFunction_Render' );
 37+ return true;
 38+}
 39+
 40+function efFormatNumParserFunction_Magic( &$magicWords, $langCode ) {
 41+ # Add the magic word
 42+ # The first array element is case sensitive, in this case it is not case sensitive
 43+ # All remaining elements are synonyms for our parser function
 44+ $magicWords['formatnum'] = array( 0, 'formatnum' );
 45+ # unless we return true, other parser functions extensions won't get loaded.
 46+ return true;
 47+}
 48+
 49+function efFormatNumParserFunction_Render( $parser, $param1 = 0, $param2 = 0, $param3 = '.', $param4 = ',' ) {
 50+ # The parser function itself
 51+ # The input parameters are wikitext with templates expanded
 52+ # The output should be wikitext too
 53+ if ($param4 == '_') {
 54+ $param4 = ' ';
 55+ }
 56+ $output = number_format($param1, $param2, $param3, $param4);
 57+ return $output;
 58+}
\ No newline at end of file
Property changes on: trunk/extensions/FormatNum/FormatNum.php
___________________________________________________________________
Added: svn:eol-style
159 + native
Property changes on: trunk/extensions/FormatNum
___________________________________________________________________
Added: bugtraq:number
260 + true
Index: trunk/extensions/ThumbParser/ThumbParser.i18n.php
@@ -0,0 +1,27 @@
 2+<?php
 3+
 4+/**
 5+ * Messages file for the ThumbParser extension
 6+ *
 7+ * @addtogroup Extensions
 8+ */
 9+
 10+/**
 11+ * Get all extension messages
 12+ *
 13+ * @return array
 14+ */
 15+$messages = array();
 16+
 17+$messages['qqq'] = array(
 18+ 'thumbparser-desc' => 'Description for Special:Version',
 19+);
 20+
 21+$messages['en'] = array(
 22+ 'thumbparser-desc' => 'Prints users Thumb size',
 23+);
 24+
 25+$messages['de'] = array(
 26+ 'thumbparser-desc' => 'Gibt die vom Benutzer definierte Größe für Vorschaubilder aus',
 27+);
 28+
Property changes on: trunk/extensions/ThumbParser/ThumbParser.i18n.php
___________________________________________________________________
Added: svn:eol-style
129 + native
Index: trunk/extensions/ThumbParser/ThumbParser.php
@@ -0,0 +1,72 @@
 2+<?php
 3+/**
 4+* @addtogroup Extensions
 5+*/
 6+// Check environment
 7+if ( !defined( 'MEDIAWIKI' ) ) {
 8+ echo( "This is an extension to the MediaWiki package and cannot be run standalone.\n" );
 9+ die( -1 );
 10+}
 11+
 12+/* Configuration */
 13+
 14+// Credits
 15+$wgExtensionCredits['parserhook'][] = array (
 16+ 'path'=> __FILE__ ,
 17+ 'name'=>'ThumbParser',
 18+ 'url'=>'http://www.mediawiki.org/wiki/Extension:ThumbParser',
 19+ 'description'=>'Prints users Thumb size',
 20+ 'descriptionmsg' => 'thumbparser-desc',
 21+ 'author'=>'[http://www.dasch-tour.de DaSch]',
 22+ 'version'=>'0.1',
 23+);
 24+$dir = dirname( __FILE__ ) . '/';
 25+
 26+// Internationalization
 27+$wgExtensionMessagesFiles['ThumbParser'] = $dir . 'ThumbParser.i18n.php';
 28+
 29+# Define a setup function
 30+$wgHooks['ParserFirstCallInit'][] = 'efThumbParserFunction_Setup';
 31+# Add a hook to initialise the magic word
 32+$wgHooks['LanguageGetMagic'][] = 'efThumbParserFunction_Magic';
 33+
 34+function efThumbParserFunction_Setup( $parser ) {
 35+ # Set a function hook associating the "example" magic word with our function
 36+ $parser->setFunctionHook( 'thumb', 'efThumbParserFunction_Render' );
 37+ return true;
 38+}
 39+
 40+function efThumbParserFunction_Magic( &$magicWords, $langCode ) {
 41+ # Add the magic word
 42+ # The first array element is case sensitive, in this case it is not case sensitive
 43+ # All remaining elements are synonyms for our parser function
 44+ $magicWords['thumb'] = array( 0, 'thumb' );
 45+ # unless we return true, other parser functions extensions won't get loaded.
 46+ return true;
 47+}
 48+
 49+function efThumbParserFunction_Render( $parser, $param1 = '') {
 50+ # The parser function itself
 51+ # The input parameters are wikitext with templates expanded
 52+ # The output should be wikitext too
 53+ global $wgThumbLimits, $wgUser;
 54+ $param1 = strtolower($param1);
 55+ $parser->disableCache(); # Mark this content as uncacheable
 56+ $wopt = $wgUser->getOption('thumbsize');
 57+ switch ($param1) {
 58+ case 'size':
 59+ $output = $wgThumbLimits[$wopt];
 60+ break;
 61+ case 'px':
 62+ $output = $wgThumbLimits[$wopt].'px';
 63+ break;
 64+ case 'width':
 65+ $size = intval($wgThumbLimits[$wopt])+10;
 66+ $strsize = strval($size);
 67+ $output = $strsize."px";
 68+ break;
 69+ default:
 70+ $output = $wgThumbLimits[$wopt];
 71+ }
 72+ return $output;
 73+}
\ No newline at end of file
Property changes on: trunk/extensions/ThumbParser/ThumbParser.php
___________________________________________________________________
Added: svn:eol-style
174 + native
Property changes on: trunk/extensions/ThumbParser
___________________________________________________________________
Added: bugtraq:number
275 + true

Follow-up revisions

RevisionCommit summaryAuthorDate
r98887r98351: Sort languages: 1. 'en, 2. 'qqq', 3. all other by alphabet...raymond19:41, 4 October 2011
r98888r98351: Add extension to translatewiki.netraymond19:41, 4 October 2011
r115609FormatNum - moved hooks like wished in r98351dasch11:57, 15 July 2012
r115610ThumbParser - moved hooks like wished in r98351dasch11:57, 15 July 2012

Comments

#Comment by Nikerabbit (talk | contribs)   22:03, 28 September 2011

Mixed tab and spaces indentation. What is the use case for FormatNum extension?

#Comment by DaSch (talk | contribs)   22:13, 28 September 2011

The use for the FormatNum extension is, that I was not satisfied with how the core function works and so you can simply define a format that is not available

#Comment by Nikerabbit (talk | contribs)   22:29, 28 September 2011

number_format is very inflexible compared to what MediaWiki can do.

#Comment by DaSch (talk | contribs)   22:45, 28 September 2011

yes, but I can override the false format the is used for example in the german localisation and when once definiting a template for my wiki with this parser I can get the example I want and I'm not binded to what is happening through localisation. Just take a look at https://bugzilla.wikimedia.org/show_bug.cgi?id=18957 It's some kind of "workaround" for someone how is not happy with the existing possibilites

#Comment by Siebrand (talk | contribs)   23:29, 28 September 2011

Please put the hook methods in a separate class file.

#Comment by DaSch (talk | contribs)   23:51, 28 September 2011

even more files for such a small extension? what's the benefit?

#Comment by Siebrand (talk | contribs)   04:35, 29 September 2011

That the code is not loaded until the class is needed for the hook.

#Comment by DaSch (talk | contribs)   11:59, 15 July 2012

should be fixed now!

Status & tagging log