2011-09-07 21:39:33 +00:00
|
|
|
!! functionhooks
|
|
|
|
convert
|
|
|
|
!! endfunctionhooks
|
|
|
|
|
(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
|
|
|
!! test
|
|
|
|
Simple conversion
|
|
|
|
!! input
|
|
|
|
{{#convert: 10 m | km }}
|
|
|
|
!!result
|
2011-09-07 21:39:33 +00:00
|
|
|
<p>0.01 kilometres
|
(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
|
|
|
</p>
|
|
|
|
!! end
|
|
|
|
|
|
|
|
!! test
|
|
|
|
Position and formatting of numbers and units
|
|
|
|
!! input
|
|
|
|
*{{#convert: 10 m | km }}
|
|
|
|
*{{#convert: 10m | km }}
|
|
|
|
*{{#convert: 10 km | m }}
|
|
|
|
*{{#convert: 10-km | m }}
|
|
|
|
*{{#convert: 10E2 km | m }}
|
|
|
|
*{{#convert: 10E-2 km | m }}
|
|
|
|
*{{#convert: 10.0E2 km | m }}
|
|
|
|
*{{#convert: 10.0E2.5 km | m }}
|
|
|
|
!! result
|
2011-09-07 21:39:33 +00:00
|
|
|
<ul><li>0.01 kilometres
|
|
|
|
</li><li>0.01kilometres
|
|
|
|
</li><li>10,000 metres
|
|
|
|
</li><li>10,000-metres
|
|
|
|
</li><li>1,000,000 metres
|
|
|
|
</li><li>100 metres
|
|
|
|
</li><li>1,000,000 metres
|
|
|
|
</li><li>1,000,000.5,000 metres
|
(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
|
|
|
</li></ul>
|
|
|
|
|
|
|
|
!! end
|
|
|
|
|
|
|
|
!! test
|
|
|
|
Precision 1
|
|
|
|
!! input
|
|
|
|
*{{#convert: 10 m | km }}
|
|
|
|
*{{#convert: 11 m | km }}
|
|
|
|
*{{#convert: 12 m | km }}
|
|
|
|
*{{#convert: 13 m | km }}
|
|
|
|
*{{#convert: 14 m | km }}
|
|
|
|
*{{#convert: 15 m | km }}
|
|
|
|
*{{#convert: 16 m | km }}
|
|
|
|
*{{#convert: 17 m | km }}
|
|
|
|
*{{#convert: 18 m | km }}
|
|
|
|
*{{#convert: 19 m | km }}
|
|
|
|
*{{#convert: 20 m | km }}
|
|
|
|
!! result
|
2011-09-07 21:39:33 +00:00
|
|
|
<ul><li>0.01 kilometres
|
|
|
|
</li><li>0.011 kilometres
|
|
|
|
</li><li>0.012 kilometres
|
|
|
|
</li><li>0.013 kilometres
|
|
|
|
</li><li>0.014 kilometres
|
|
|
|
</li><li>0.015 kilometres
|
|
|
|
</li><li>0.016 kilometres
|
|
|
|
</li><li>0.017 kilometres
|
|
|
|
</li><li>0.018 kilometres
|
|
|
|
</li><li>0.019 kilometres
|
|
|
|
</li><li>0.02 kilometres
|
(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
|
|
|
</li></ul>
|
|
|
|
|
|
|
|
!! end
|
|
|
|
|
|
|
|
!! test
|
|
|
|
Precision 2
|
|
|
|
!! input
|
|
|
|
*{{#convert: 10.0 m | km }}
|
|
|
|
*{{#convert: 10.1 m | km }}
|
|
|
|
*{{#convert: 10.2 m | km }}
|
|
|
|
*{{#convert: 10.3 m | km }}
|
|
|
|
*{{#convert: 10.4 m | km }}
|
|
|
|
*{{#convert: 10.5 m | km }}
|
|
|
|
*{{#convert: 10.6 m | km }}
|
|
|
|
*{{#convert: 10.7 m | km }}
|
|
|
|
!! result
|
2011-09-07 21:39:33 +00:00
|
|
|
<ul><li>0.0100 kilometres
|
|
|
|
</li><li>0.0101 kilometres
|
|
|
|
</li><li>0.0102 kilometres
|
|
|
|
</li><li>0.0103 kilometres
|
|
|
|
</li><li>0.0104 kilometres
|
|
|
|
</li><li>0.0105 kilometres
|
|
|
|
</li><li>0.0106 kilometres
|
|
|
|
</li><li>0.0107 kilometres
|
(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
|
|
|
</li></ul>
|
|
|
|
|
|
|
|
!! end
|
|
|
|
|
|
|
|
!! test
|
|
|
|
String interpolation
|
|
|
|
!! input
|
|
|
|
{{#convert: 25, 26, 27, 28, 29, and 30 km }}
|
|
|
|
!! result
|
2011-09-07 21:39:33 +00:00
|
|
|
<p>25,000, 26,000, 27,000, 28,000, 29,000, and 30,000 metres
|
(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
|
|
|
</p>
|
|
|
|
!! end
|
|
|
|
|
|
|
|
!! test
|
|
|
|
Precision 3
|
|
|
|
!! input
|
|
|
|
{{#convert: 25, 26, 27, 28, 29, and 30 miles }}
|
|
|
|
!! result
|
2011-09-07 21:39:33 +00:00
|
|
|
<p>40,000, 42,000, 43,000, 45,000, 47,000, and 50,000 metres
|
(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
|
|
|
</p>
|
|
|
|
!! end
|
|
|
|
|
|
|
|
!! test
|
|
|
|
Precision 4
|
|
|
|
!! input
|
|
|
|
{{#convert:35000, 35E3, 35.0E3, 350E2, 3.500E4, 35000E0, 350000E-1 m | km }}
|
|
|
|
!! result
|
2011-09-07 21:39:33 +00:00
|
|
|
<p>35, 35, 35.0, 35, 35.00, 35, 35 kilometres
|
(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
|
|
|
</p>
|
|
|
|
!! end
|
|
|
|
|
|
|
|
!! test
|
|
|
|
#sourceunit
|
|
|
|
!!input
|
|
|
|
*{{#convert: 25 | #sourceunit = km }}
|
|
|
|
*{{#convert: 25 | #sourceunit=km }}
|
|
|
|
*{{#convert: 25 | #sourceunit = km | #sourceunit = mm }}
|
|
|
|
*{{#convert: 25 | #sourceunit = km | cm }}
|
|
|
|
!! result
|
2011-09-07 21:39:33 +00:00
|
|
|
<ul><li>25,000 metres
|
|
|
|
</li><li>25,000 metres
|
|
|
|
</li><li>0.025 metres
|
|
|
|
</li><li>2,500,000 centimetres
|
(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
|
|
|
</li></ul>
|
|
|
|
|
|
|
|
!! end
|
|
|
|
|
|
|
|
!! test
|
|
|
|
Precision overrides
|
|
|
|
!!input
|
|
|
|
*{{#convert: 1 mi | #dp = 0 }}
|
|
|
|
*{{#convert: 1 mi | #dp=1 }}
|
|
|
|
*{{#convert: 1 mi | #dp = -2 }}
|
|
|
|
*{{#convert: 1 mi | #dp = 5 }}
|
|
|
|
*{{#convert: 1 mi | #dp = -8 }}
|
|
|
|
*{{#convert: 1 mi | #sf = 0 }}
|
|
|
|
*{{#convert: 1 mi | #sf=1 }}
|
|
|
|
*{{#convert: 1 mi | #sf = 3 }}
|
|
|
|
*{{#convert: 1 mi | #sf = 5 }}
|
|
|
|
*{{#convert: 1 mi | #sf = -8 }}
|
|
|
|
!! result
|
2011-09-07 21:39:33 +00:00
|
|
|
<ul><li>1,609 metres
|
|
|
|
</li><li>1,609.3 metres
|
|
|
|
</li><li>1,600 metres
|
|
|
|
</li><li>1,609.344 metres
|
|
|
|
</li><li>0 metres
|
|
|
|
</li><li>2,000 metres
|
|
|
|
</li><li>2,000 metres
|
|
|
|
</li><li>1,610 metres
|
|
|
|
</li><li>1,609.3 metres
|
|
|
|
</li><li>2,000 metres
|
(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
|
|
|
</li></ul>
|
|
|
|
|
|
|
|
!! end
|
|
|
|
|
|
|
|
|
|
|
|
!! test
|
|
|
|
Errors
|
|
|
|
!! input
|
|
|
|
*{{#convert: 25 | km }}
|
|
|
|
*{{#convert: 25 foobars | mi }}
|
|
|
|
*{{#convert: 25 mi | #sourceunit = foobar }}
|
|
|
|
*{{#convert: 25 km | s }}
|
|
|
|
*{{#convert: 25 km/Pa | m/Pa }}
|
|
|
|
*{{#convert: 25 km/s/l }}
|
|
|
|
*{{#convert: 25 km/m3 }}
|
|
|
|
!! result
|
2011-08-17 12:04:51 +00:00
|
|
|
<ul><li><strong class="error">Error: No source unit given.</strong>
|
|
|
|
</li><li><strong class="error">Error: Unknown unit "foobars".</strong>
|
|
|
|
</li><li><strong class="error">Error: Unknown unit "foobar".</strong>
|
|
|
|
</li><li><strong class="error">Error: Cannot convert between units of "length" and "time".</strong>
|
|
|
|
</li><li><strong class="error">Error: Invalid compound unit "length/pressure".</strong>
|
|
|
|
</li><li><strong class="error">Error: Cannot parse double compound units like "km/s/l".</strong>
|
|
|
|
</li><li><strong class="error">Error: Invalid compound unit "length/volume".</strong>
|
(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
|
|
|
</li></ul>
|
|
|
|
|
|
|
|
!! end
|
|
|
|
|
|
|
|
|
|
|
|
!! test
|
|
|
|
#sourceunit = #targetunit
|
|
|
|
!! input
|
|
|
|
*{{#convert: 25 km | #targetunit = #sourceunit }}
|
|
|
|
*{{#convert: 25 km | #sourceunit = #targetunit }}
|
|
|
|
!! result
|
2011-09-07 21:39:33 +00:00
|
|
|
<ul><li>25 kilometres
|
|
|
|
</li><li>25 kilometres
|
2011-01-29 15:45:07 +00:00
|
|
|
</li></ul>
|
|
|
|
|
|
|
|
!! end
|
|
|
|
|
|
|
|
!! test
|
|
|
|
#language
|
|
|
|
!! input
|
|
|
|
*{{#convert: 10 m | km | #language=en-gb }}
|
2011-09-07 21:39:33 +00:00
|
|
|
*{{#convert: 10m | km | #language = en }}
|
|
|
|
*{{#convert: 10 km | m |#language=en}}
|
|
|
|
*{{#convert: 10 Pa | mmHg | #language = fr }}
|
2011-01-29 15:45:07 +00:00
|
|
|
!! result
|
2011-01-29 15:59:17 +00:00
|
|
|
<ul><li>0.01 kilometres
|
2011-09-07 21:39:33 +00:00
|
|
|
</li><li>0.01kilometers
|
|
|
|
</li><li>10,000 meters
|
|
|
|
</li><li>0.1 millimètre de mercure
|
2011-02-04 14:28:37 +00:00
|
|
|
</li></ul>
|
|
|
|
|
|
|
|
!! end
|
|
|
|
|
|
|
|
!! test
|
|
|
|
Case sensitivity
|
|
|
|
!! input
|
|
|
|
*{{#convert: 10 mm | m }}
|
|
|
|
*{{#convert: 10 Mm | m }}
|
|
|
|
*{{#convert: 10 km | Mm }}
|
|
|
|
*{{#convert: 10 Pa | mmHg }}
|
|
|
|
*{{#convert: 10 pa | mmHg }}
|
|
|
|
!! result
|
2011-09-07 21:39:33 +00:00
|
|
|
<ul><li>0.01 metres
|
|
|
|
</li><li>10,000,000 metres
|
|
|
|
</li><li>0.01 megametres
|
|
|
|
</li><li>0.1 millimetres of mercury
|
2011-08-17 12:04:51 +00:00
|
|
|
</li><li><strong class="error">Error: Unknown unit "pa".</strong>
|
(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
|
|
|
</li></ul>
|
|
|
|
|
|
|
|
!! end
|