Commit graph

7 commits

Author SHA1 Message Date
Happy-melon 026ea6a6be FU 96499, r81074: fix parser tests to reflect the change in default dialect, and make them not run (and die) when {{#convert}} is disabled. 2011-09-07 21:39:33 +00:00
Sam Reed d94d4d1407 Followup r95525, fix failing parser tests
Failure:
ConvertTests::testParserTest with data set #11 ('#language', '*{{#convert: 10  m | km | #language=en-gb }}
*{{#convert: 10m | km | #language = en-gb }}
*{{#convert: 10 km | m |#language=en-gb}}
*{{#convert: 10 Pa | mmHg | #language = en-gb }}', '<ul><li>0.01  kilometres
</li><li>0.01kilometres
</li><li>10,000 metres
</li><li>0.1 milimetres of mercury
</li></ul>
', '', '')
#language
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 <ul><li>0.01  kilometres
 </li><li>0.01kilometres
 </li><li>10,000 metres
-</li><li>0.1 milimetres of mercury
+</li><li>0.1 millimetres of mercury
 </li></ul>

/home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/includes/parser/NewParserTest.php:539
/home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/MediaWikiTestCase.php:60
/home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/MediaWikiPHPUnitCommand.php:31
/home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/phpunit.php:60

ConvertTests::testParserTest with data set #12 ('Case sensitivity', '*{{#convert: 10 mm | m }}
*{{#convert: 10 Mm | m }}
*{{#convert: 10 km | Mm }}
*{{#convert: 10 Pa | mmHg }}
*{{#convert: 10 pa | mmHg  }}', '<ul><li>0.01 meters
</li><li>10,000,000 meters
</li><li>0.01 megameters
</li><li>0.1 milimeters of mercury
</li><li><strong class="error">Error: Unknown unit "pa".</strong>
</li></ul>
', '', '')
Case sensitivity
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
 <ul><li>0.01 meters
 </li><li>10,000,000 meters
 </li><li>0.01 megameters
-</li><li>0.1 milimeters of mercury
+</li><li>0.1 millimeters of mercury
 </li><li><strong class="error">Error: Unknown unit "pa".</strong>
 </li></ul>

/home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/includes/parser/NewParserTest.php:539
/home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/MediaWikiTestCase.php:60
/home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/MediaWikiPHPUnitCommand.php:31
/home/ci/cruisecontrol-bin-2.8.3/projects/mw/source/tests/phpunit/phpunit.php:60
2011-08-25 22:28:28 +00:00
Siebrand Mazeland 91abad7b58 Follow-up r94734. Should fix broken tests 10 and 13 for ParserFunctions because of changes in message content. 2011-08-17 12:04:51 +00:00
Happy-melon b3d240bdba Follow-up r81074: turns out {{convert}} is (mostly) case-sensitive after all, so reclaim case-sensitivity here. Will work on abstracting out SI prefixes later. 2011-02-04 14:28:37 +00:00
Happy-melon d316c140e9 Follow-up r81074: better handling of whitespace, or lack thereof, between the digit and unit. 2011-01-29 15:59:17 +00:00
Happy-melon c65d2f8bbc Follow-up r81074: succumb, though it breaks my heart to do so (:P), to American linguistic imperialism... 2011-01-29 15:45:07 +00:00
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