if ( !$unix ) {
$unix = wfTimestamp( TS_UNIX, $ts );
}
- $num = date( 'o', $unix );
+ $num = gmdate( 'o', $unix );
break;
case 'Y':
$num = substr( $ts, 0, 4 );
*/
function commafy( $_ ) {
$digitGroupingPattern = $this->digitGroupingPattern();
+ if ( $_ === null ) {
+ return '';
+ }
if ( !$digitGroupingPattern || $digitGroupingPattern === "###,###,###" ) {
// default grouping is at thousands, use the same for ###,###,### pattern too.
if ( intval( $_ ) < 0 ) {
// For negative numbers apply the algorithm like positive number and add sign.
$sign = "-";
- $_ = substr( $_,1 );
+ $_ = substr( $_, 1 );
}
$numberpart = array();
$decimalpart = array();
}
/**
+ * Format a bitrate for output, using an appropriate
+ * unit (bps, kbps, Mbps, Gbps, Tbps, Pbps, Ebps, Zbps or Ybps) according to the magnitude in question
+ *
* @param $bps int
* @return string
*/
function formatBitrate( $bps ) {
- $units = array( 'bps', 'kbps', 'Mbps', 'Gbps' );
+ $units = array( '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' );
if ( $bps <= 0 ) {
- return $this->formatNum( $bps ) . $units[0];
+ return str_replace( '$1', $this->formatNum( $bps ), $this->getMessageFromDB( 'bitrate-bits' ) );
}
$unitIndex = (int)floor( log10( $bps ) / 3 );
$mantissa = $bps / pow( 1000, $unitIndex );
+
+ $maxIndex = count( $units ) - 1;
+
+ if ( $unitIndex > $maxIndex ) {
+ // Prevent code falling off end of $units array
+ $mantissa *= ( $unitIndex - $maxIndex ) * 1000;
+ $unitIndex = $maxIndex;
+ }
if ( $mantissa < 10 ) {
$mantissa = round( $mantissa, 1 );
} else {
$mantissa = round( $mantissa );
}
- return $this->formatNum( $mantissa ) . $units[$unitIndex];
+ $msg = "bitrate-{$units[$unitIndex]}bits";
+ $text = $this->getMessageFromDB( $msg );
+ return str_replace( '$1', $this->formatNum( $mantissa ), $text );
}
/**
* Format a size in bytes for output, using an appropriate
- * unit (B, KB, MB or GB) according to the magnitude in question
+ * unit (B, KB, MB, GB, TB, PB, EB, ZB or YB) according to the magnitude in question
*
* @param $size int Size to format
* @return string Plain text (not HTML)
*/
function formatSize( $size ) {
+ $sizes = array( '', 'kilo', 'mega', 'giga', 'tera', 'peta', 'exa', 'zeta', 'yotta' );
+ $index = 0;
+
+ $maxIndex = count( $sizes ) - 1;
+ while ( $size >= 1024 && $index < $maxIndex ) {
+ $index++;
+ $size /= 1024;
+ }
+
// For small sizes no decimal places necessary
$round = 0;
- if ( $size > 1024 ) {
- $size = $size / 1024;
- if ( $size > 1024 ) {
- $size = $size / 1024;
- // For MB and bigger two decimal places are smarter
- $round = 2;
- if ( $size > 1024 ) {
- $size = $size / 1024;
- $msg = 'size-gigabytes';
- } else {
- $msg = 'size-megabytes';
- }
- } else {
- $msg = 'size-kilobytes';
- }
- } else {
- $msg = 'size-bytes';
+ if ( $index > 1 ) {
+ // For MB and bigger two decimal places are smarter
+ $round = 2;
}
+ $msg = "size-{$sizes[$index]}bytes";
+
$size = round( $size, $round );
$text = $this->getMessageFromDB( $msg );
return str_replace( '$1', $this->formatNum( $size ), $text );
# Make 'previous' link
$prev = wfMessage( 'prevn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text();
- if( $offset > 0 ) {
+ if ( $offset > 0 ) {
$plink = $this->numLink( $title, max( $offset - $limit, 0 ), $limit,
$query, $prev, 'prevn-title', 'mw-prevlink' );
} else {
# Make 'next' link
$next = wfMessage( 'nextn' )->inLanguage( $this )->title( $title )->numParams( $limit )->text();
- if( $atend ) {
+ if ( $atend ) {
$nlink = htmlspecialchars( $next );
} else {
$nlink = $this->numLink( $title, $offset + $limit, $limit,
# Make links to set number of items per page
$numLinks = array();
- foreach( array( 20, 50, 100, 250, 500 ) as $num ) {
+ foreach ( array( 20, 50, 100, 250, 500 ) as $num ) {
$numLinks[] = $this->numLink( $title, $offset, $num,
$query, $this->formatNum( $num ), 'shown-title', 'mw-numlink' );
}