Page MenuHomePhabricator

{{formatnum:}} formats all numbers in the input if the input itself is not numerical, even numbers inside links
Open, LowPublic

Description

Author: robert.ribnitz

Description:
The {{fact}} template on Simple English wikipedia will add a category "Articles with unsourced statements since {{date}}". date is commonly set to values like "February 2009". The problem with that is that if the facr template is used inside another (eg. infobox) that uses number formatting, the year of the "date" will also be formatted, before it is passed to the template fact. We end up with a caegory: "Articles with unsourced statements since February 2,009", instead of the expected "Articles with unsourced statements since February 2009". What is probably needed is a way to tell the system that arguments to inner templates should not be parsed (and treated like "Text").

http://simple.wikipedia.org/w/index.php?title=Skopje&oldid=2642872 gives an example of this. Fact is used inside an {{Infobox Settlement}} which formats numbers like population in the settlement and metro area.


Version: unspecified
Severity: normal

Details

Reference
bz28582

Event Timeline

bzimport raised the priority of this task from to Low.Nov 21 2014, 11:30 PM
bzimport set Reference to bz28582.
bzimport added a subscriber: Unknown Object (MLST).

The best description I can give of what's actually going on here is that {{formatnum:750000 [[Category:Articles with unsourced statements since January 2009]]}} formats both the number and the year in the category tag, resulting in "750,000 [[Category:Articles with unsourced statements since January 2,009]]". I've changed the bug summary accordingly, but I'm not entirely sure that this is a bug. Maybe it's reasonable to expect formatnum to leave things in link brackets alone.

robert.ribnitz wrote:

Yes, that is basically what is occurring. Making formatnum ignore things in link brackets (perhaps guided with an additional parameter) would probably be a suitable workaround.

I think the current behavior is acceptable given that only numbers are valid input for formatnum.

robert.ribnitz wrote:

While this is certainly true, it does not solve the problem. The problem is that the fact-template can also be added to "numbers", or "cells with formatted numbers" (in other templates). We therefore either need a replacement that can be used in such cases, or we need to fix the behaviour to be able to generate correct (ie. unformatted) references/categories.

It sounds like what you want to end up with is this:

{{formatnum:750000}} [[Category:Articles with unsourced statements since January 2009]]

instead of this:

{{formatnum:750000 [[Category:Articles with unsourced statements since January 2009]]}}

The use of {{formatnum}} where it is on those templates sounds like it's simply not leaving room for additional annotations -- the entire field is expected to be a number. This then fails to create the expected result when you pass in something other than a number -- such as a number and some other text which also includes numbers. It would be similarly broken if this wasn't a link and just said "{{formatnum:750000 as of year 2010 US Census}}".

Either the template should add a second parameter for annotations, or only the numbers should be given the number format wrapper, eg by applying it on the number in the template invocation.