Go to file
Happy-melon 65e9e69202 (bug 235) parser function for conversion of units of measurement.
[[Template:Convert]] on enwiki is a behemoth of a construction that just about manages to do this sort of conversion, taking {{convert|5|mi|km}} and outputting "5 miles (8 km)", etc.  To port this to another wiki requires copying over three and a half thousand subtemplates.  The additional load produced by including numerous copies of this template is measurable on large pages on enwiki, and it eats voraciously into the template limits.

This revision introduces {{#convert: 5 mi | km }}, outputting "8 km" or thereabouts.  See http://www.mediawiki.org/wiki/User:Happy-melon/Convert for more details, or look at the examples in the parser tests.  

In a very rough profile, comparing 50 calls to {{convert}} verses the same 50 calls to the wrapper template shown at the link above, the parser function implementation reduces page load time by 72%, preprocessor node count by 83%, post-expand include size by 86% and template argument size by 97%.  More detailed profiling would probably reveal places where extra caching could improve performance further.

The primary reason for putting it in ParserFunctions instead of its own extension is availability: PFs are already available across the cluster, and it's accepted as an essential extension for any wiki wishing to emulate or mirror WMF content.  One less separate extension installed on the cluster is one less extension which has to be matched by reusers.  

It's still missing a lot of units, which I ran out of patience to copy from {{convert}}; I thought I'd get some feedback on the infrastructure first.
2011-01-27 00:13:10 +00:00
Convert.php (bug 235) parser function for conversion of units of measurement. 2011-01-27 00:13:10 +00:00
convertTests.txt (bug 235) parser function for conversion of units of measurement. 2011-01-27 00:13:10 +00:00
COPYING * remove MediaWiki pre-1.8 compatibility and remove SprintfDateCompat.php 2010-10-02 22:36:34 +00:00
Expr.php Start removing/fixing calls to deprecated methods in WMF used extensions 2010-10-29 15:14:44 +00:00
exprTests.txt Revert "Adds explicit round-off checking to operations that are sensitive to floating point vs. integer round-off errors.", et al. ( r46683, r46671 ) 2009-02-12 22:29:32 +00:00
funcsParserTests.txt Follow-up to r67044: moved string function tests to a separate file protected by conditional, tweaked test runner to skip instead of exploding when required function hook is not found. 2010-07-09 21:11:54 +00:00
ParserFunctions.i18n.magic.php (bug 235) parser function for conversion of units of measurement. 2011-01-27 00:13:10 +00:00
ParserFunctions.i18n.php (bug 235) parser function for conversion of units of measurement. 2011-01-27 00:13:10 +00:00
ParserFunctions.php (bug 235) parser function for conversion of units of measurement. 2011-01-27 00:13:10 +00:00
ParserFunctions_body.php (bug 235) parser function for conversion of units of measurement. 2011-01-27 00:13:10 +00:00
README Update README a bit 2011-01-10 05:24:36 +00:00
stringFunctionTests.txt Follow-up to r67044: moved string function tests to a separate file protected by conditional, tweaked test runner to skip instead of exploding when required function hook is not found. 2010-07-09 21:11:54 +00:00
testExpr.php * remove MediaWiki pre-1.8 compatibility and remove SprintfDateCompat.php 2010-10-02 22:36:34 +00:00

ParserFunctions v1.4.0

1. Licensing
2. How to install
3. Tests

1. Licensing
Licensed under GNU GPL. See COPYING for more license information.

2. How to install
   a. Download this tarbell and extract the contents to $IP/extensions/ParserFunctions/
      where $IP is your root wiki install
   b. Add 'require_once( "$IP/extensions/ParserFunctions/ParserFunctions.php");' to the 
      end of your LocalSettings (without the single quotes)
   c. Enjoy

3. Tests
ParserFunctions ships with two tests
- Parser tests. These get added to the main parser tests, see there for docs
- Expression tests. These are designed to test the math-related functions
  See testExpr.php