Page MenuHomePhabricator

Deprecate and remove wfPercent()
Open, Needs TriagePublic

Description

wfPercent() has been in MediaWiki since 2005 (rSVN10163 / be977a75d7b3fd55), and I think it makes sense to deprecate and remove it for several reasons.

It is hardly ever used, with only one current use within Wikimedia maintained code: in ParserTestPrinter, since rSVN10164 (68871fa25dbe1aa3). The other known uses are in:

It is not internationalized. In user-visible output such as that generated by the extensions, users likely expect the percent sign to be used as is customary in their language (after or before the number, with or without a space, or even a different form of the symbol, as in Persian). This is in addition to issues with number formatting in general.

Its valid use cases are not documented. Different use cases may support or justify different rounding methods. As an example, a setup utility might always round down the completion percentage, to not show 100% until completely done, or might scale values in (0%, 100%) to [0.5%, 99.5%] before rounding to nearest, ties to odd, to indicate progress earlier. They may also justify different sets of parameters in the API, with separate parameters for numerator and denominator of a fraction being one alternative choice.

The few remaining uses are trivial to replace while maintaining existing levels of functionality. All known callers use the defaults of acc: 2, round: true. If the percent sign is added separately, round() would likely suffice. There is a rounding difference: sprintf() with %f rounds the exact value, including any floating-point error, ties to even, while round() pre-rounds to 15 significant digits (according to a 2008 RFC) and rounds ties away from zero by default. However, it probably doesn't matter in these instances.

Event Timeline

Change #1240042 had a related patch set uploaded (by PleaseStand; author: PleaseStand):

[mediawiki/core@master] GlobalFunctions: Deprecate wfPercent()

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

It will need to be determined whether the example replacement added to the RELEASE-NOTES file would be acceptable. For example, can the existing "percent" message be used in extensions, or should extension developers create their own? Should the messages system even be used for this, or should MediaWiki transition to using the number formatting routines in ICU or a similar library?

Change #1240042 merged by jenkins-bot:

[mediawiki/core@master] GlobalFunctions: Deprecate wfPercent()

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

Change #1279826 had a related patch set uploaded (by PleaseStand; author: PleaseStand):

[mediawiki/extensions/Editcount@master] Stop using deprecated wfPercent()

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