Page MenuHomePhabricator

CoreParserFunctions::formatRaw needs to use page language
Closed, ResolvedPublic

Description

The parser function {{#expr: }} appears to produce different results on Translations: pages than it does in other namespaces.

This was first brought to our attention on Wikimedia Commons with this edit[1]; after some playing around, I managed to isolate the problem to {{#expr:}} with this edit[2], and confirmed the different behaviour by adding the same code to a page in my own user space[3] and then testing it again using preview at a different page in the Commons: namespace[4].

References


Version: unspecified
Severity: normal

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 2:55 AM
bzimport added a project: MediaWiki-Parser.
bzimport set Reference to bz60604.
bzimport added a subscriber: Unknown Object (MLST).

Please provide more detail. What is the actual value? What is expected value.

"{{#expr:{{formatnum:{{PAGESINCATEGORY:Quality images}}|R}} - 100}}" is too complex example to understand what is going on.

I doubt this is a Translate bug: as I already told Odder, he/we need to verify whether #expr wants formatted or unformatted numbers and what assumptions it makes on content language...

As demonstrated in [3], the expected value of that function is 61390; the output on that Translations: page is -38.465.

(In reply to comment #2)

I doubt this is a Translate bug: as I already told Odder, he/we need to

The function behaves the same way on regular MediaWiki: pages (tested in NS_USER and NS_PROJECT, see above), but produces different results in Translations: — hence the assumption the bug lies in the latter.

There are at least four places where something can go wrong in that example. Please narrow it down.

(In reply to comment #3)

The function behaves the same way on regular MediaWiki: pages (tested in
NS_USER and NS_PROJECT, see above), but produces different results in
Translations: — hence the assumption the bug lies in the latter.

I don't see any MediaWiki:/ns8 page in the examples. You can see the page language in action=info.

(In reply to comment #5)

I don't see any MediaWiki:/ns8 page in the examples. You can see the page
language in action=info.

Ignore the colon, I meant MediaWiki pages irrespective of their namespaces.

(In reply to comment #4)

There are at least four places where something can go wrong in that example.
Please narrow it down.

OK, it appears the problem lies within {{formatnum: }} and not in {{#expr:}}: compare https://commons.wikimedia.org/w/index.php?diff=115117520&oldid=115094092 and https://commons.wikimedia.org/w/index.php?diff=115117560&oldid=115092667

That's expected behaviour, formatnum is trying to unformat according to Polish rules but you provided it with an English-formatted numbers. This is a core issue, invalid for Translate and duplicate of bug 35922 for core.

https://www.mediawiki.org/wiki/Help:Magic_words#Formatting suggests that the numbers are formatted according to the wiki's default locale, which in Commons's example is, I think, English.

The problem is that CoreParserFunctions::formatRaw uses content language and not page language while formatnum raw excepts page language.

[Is this bug still invalid or duplicate?]

Change 110342 had a related patch set uploaded by Nikerabbit:
Parser functions now format numbers according to page language

https://gerrit.wikimedia.org/r/110342

21:34 +logmsgbot: !log bsitu synchronized wmf-config/InitialiseSettings.php 'Enable Flow on two enwiki WikiProject pages'

Not this bug, obviously; please ignore comment 13.

Change 110342 had a related patch set uploaded (by Nikerabbit):
Parser functions now format numbers according to page language

https://gerrit.wikimedia.org/r/110342

Change 110342 merged by jenkins-bot:
Parser functions now format numbers according to page language

https://gerrit.wikimedia.org/r/110342

Change 318012 had a related patch set uploaded (by Legoktm):
Parser functions now format numbers according to page language

https://gerrit.wikimedia.org/r/318012

Change 318012 merged by jenkins-bot:
Parser functions now format numbers according to page language

https://gerrit.wikimedia.org/r/318012

Change 319528 had a related patch set uploaded (by Nikerabbit):
Parser functions now format numbers according to page language (2nd attempt)

https://gerrit.wikimedia.org/r/319528

Change 319528 merged by Nikerabbit:
Parser functions now format numbers according to page language (2nd attempt)

https://gerrit.wikimedia.org/r/319528