r87460 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87459‎ | r87460 | r87461 >
Date:21:54, 4 May 2011
Author:tparscal
Status:reverted (Comments)
Tags:
Comment:
Modified number formatting method to use number_format instead of $wgLang->formatNum and round so we can get leading zeros. If there's a way to get leading zeros with $wgLang, I don't know what it is.
Modified paths:
  • /trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php
@@ -341,9 +341,11 @@
342342 /* Protected Static Methods */
343343
344344 protected function formatNumber( $number ) {
345 - global $wgLang;
346 -
347 - return $wgLang->formatNum( round( $number, 2 ) );
 345+ //global $wgLang;
 346+ //return $wgLang->formatNum( round( $number, 2 ) );
 347+
 348+ // This may not be locale aware, but it's what we actually want (2 decimals and leading 0s)
 349+ return number_format( $number, 2 );
348350 }
349351
350352 protected function getCategories() {

Follow-up revisions

RevisionCommit summaryAuthorDate
r87471Improves on r87460 - allthough the documentation seems unclear, we can pass a...tparscal23:17, 4 May 2011

Comments

#Comment by 😂 (talk | contribs)   21:57, 4 May 2011

I'm gonna go out on a limb and say formatNum() should be changed to allow this, but of course we can't let a proper fix get in the way of deployment.

#Comment by Trevor Parscal (WMF) (talk | contribs)   22:05, 4 May 2011

Agreed on both points.

#Comment by 😂 (talk | contribs)   22:07, 4 May 2011

The second point was sarcastic...

#Comment by Bawolff (talk | contribs)   22:24, 4 May 2011

Its not really formatNum's fault. Its php's builtin round function's fault. (btw, I assume you mean trailing 0's, not leading 0's. I was rather confused for a second).

The following should work i believe if I understand correctly what you want:

$wgLang->formatNum( number_format($number, 2, '.', ) );
#Comment by Bawolff (talk | contribs)   22:25, 4 May 2011

ich of all the characters to mean italics...

$wgLang->formatNum( number_format($number, 2, '.', '' ) );

is what i meant.

#Comment by Trevor Parscal (WMF) (talk | contribs)   22:28, 4 May 2011

Yeah, I mean trailing - sorry. The documentation of formatNum says to pass it an integer or float, not a string, which number_format returns.

#Comment by Bawolff (talk | contribs)   22:31, 4 May 2011

I always took the docs to mean it can have a string argument that should contain an integer or floating point value. In any case I think there are a couple places in mediawiki passing it strings. Perhaps we should just change the docs.

Status & tagging log