This function is similar to getDirMark(), but it adds HTML entities
instead of invisible Unicode characters.
It's based on MaxSem's suggestion in
https://gerrit.wikimedia.org/r/#change,3929
Change-Id: I5bd362d6e6a56478bf9f58b2b81fcad31be12d35
This reverts the SpecialCachedPage and formatDuration sagas, with some collateral damage here and there. All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
* Add @since, fix indentation.
* Change default from 'all' to 'mw' as it's the most used (so default fetchLanguageNames() is equivalent to default getLanguageNames()).
* Add the include parameter also to fetchLanguageName() as it's needed in Parser: interlanguage links should only take into account mediawiki names. (Doesn't make a difference with how the functions are now, but could have been later.)
* Reduces the overly long code in r107002, and reduces code for {{#language:}}
* Fixes the language list in Special:Translate which contained languages that gave "invalid code" when selecting
Since we're here: nothing uses $namespaceNames, $mNamespaceIds or $namespaceAliases
outside of this class (core or extensions) so lets make it protected.
Problem was caused by inexact floating-point comparisons with values returned from
log10(); worked around by simply duplicating the very similar code in the function
immediately below, which does the same thing with 1024 instead of 1000 unit sizes,
uses only simple division, and passes the test cases.
Language::formatBitrate() uses log10() to makes a long number human readeable.
There is a nasty rounding error on Mac OS X for log10():
log10(pow(10,15)) => gives 15
floor( log10(pow(10,15)) ) => gives 14 (should be 15)
The end result is that pow(10,15) is formatted as 1,000Tbps instead of 1Pbps
log( $foo, 10) does not suffer from this:
php -r 'print floor(log(pow(10,15),10)) ."\n";'
PHP Version used:
$ php -v
PHP 5.3.6 with Suhosin-Patch (cli) (built: Sep 8 2011 19:34:00)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with Xdebug v2.1.2, Copyright (c) 2002-2011, by Derick Rethans
$
TEST PLAN:
BEFORE
======
$ php phpunit.php ./languages/LanguageTest.php
PHPUnit 3.6.3 by Sebastian Bergmann.
............................................................... 63 / 170 ( 37%)
............................................................... 126 / 170 ( 74%)
.......................................F....
Time: 2 seconds, Memory: 32.25Mb
There was 1 failure:
1) LanguageTest::testFormatBitrate with data set #5 (1000000000000000, '1Pbps', '1 petabit per second')
formatBitrate('1000000000000000'): 1 petabit per second
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'1Pbps'
+'1,000Tbps'
FAILURES!
Tests: 170, Assertions: 174, Failures: 1.
AFTER
=====
PHPUnit 3.6.3 by Sebastian Bergmann.
............................................................... 63 / 170 ( 37%)
............................................................... 126 / 170 ( 74%)
............................................
Time: 1 second, Memory: 32.25Mb
OK (170 tests, 174 assertions)
Make Language::formatNum() handle TB through YB
Rewrote code to be simpler and less indenty
Though, something like formatBitrate might be be better in future... We'll see!