User "Tim Starling" changed the status of MediaWiki.r81074.

Old Status: new
New Status: fixme

User "Tim Starling" also posted a comment on MediaWiki.r81074.

Full URL: http://www.mediawiki.org/wiki/Special:Code/MediaWiki/81074#c21955
Commit summary:

(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.

Comment:

Actually the measure of tyre pressure is pounds-force per square inch, not 
foot-pounds per square inch. See [[w:Pounds per square inch]]. Dimensional 
analysis is a useful technique, it would have identified your error here. 
Dimensional analysis can cope with reciprocals. 

Spelling differences are best dealt with by using abbreviations, which are 
consistent and international. A style guide I once read recommended that 
abbreviations should always be used in preference to the unit names, since this 
convention avoids an unfortunate ambiguity between rad as an abbreviation for 
radians, and rad the unit name which is abbreviated to rd. Also they are 
shorter. However <nowiki>{{convert}}</nowiki> on Wikipedia uses full names by 
default so I suppose we should follow suit here.

It seems kind of strange to adopt the spelling conventions for metric units 
from the most obstinate anti-metric country in the world as our default. The 
Wikipedia templates do not take this approach, they use the British spelling by 
default, and allow an "sp=us" parameter to access the American spelling. 

I suggest adding a method for configuring the language variant to be used on a 
wiki for unit name display. This would allow the new parser function to match 
the style used on Wikipedia and avoid the need for #language=en-gb to be added 
to every invocation. Setting "fixme" status for this feature request.

Ideally it should provide a map of base languages to sensible defaults, to 
provide Wikipedia-like functionality to small wikis without configuration, e.g.:

<pre>
$wgPFUnitLanguageVariants = array(
   'en' => 'en-gb'
);
</pre>

If $wgContLang is present as a key in the array, the language in the value of 
that element would be used by default for ConvertParser::$language.

_______________________________________________
MediaWiki-CodeReview mailing list
mediawiki-coderev...@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-codereview

Reply via email to