Fix special case at Special:MediaStatistics
authorMormegil <mormegil@centrum.cz>
Sat, 20 Sep 2014 23:20:56 +0000 (23:20 +0000)
committerMormegil <mormegil@centrum.cz>
Sat, 20 Sep 2014 23:20:56 +0000 (23:20 +0000)
When a percentage was equal to 100 %, makePercentPretty
determined it should have zero decimal places, and the
resulting string "100" had "trailing 0's" removed, resulting
in a completely wrong "1".

We might either check if the number contains the decimal dot
prior to trimming, or spare the hassle for the special case
completely.

Change-Id: I15ac5caa275d72909adba27b6b88824a830bd574

includes/specials/SpecialMediaStatistics.php

index 681c332..3fd8413 100644 (file)
@@ -185,6 +185,9 @@ class MediaStatisticsPage extends QueryPage {
                if ( $decimal == 0 ) {
                        return '0';
                }
+               if ( $decimal >= 100 ) {
+                       return '100';
+               }
                $percent = sprintf( "%." . max( 0, 2 - floor( log10( $decimal ) ) ) . "f", $decimal );
                // Then remove any trailing 0's
                return preg_replace( '/\.?0*$/', '', $percent );