From 921f3a7d11f7e2d205a8a790b476db948c043899 Mon Sep 17 00:00:00 2001 From: Aaron Schulz Date: Sun, 19 Jun 2011 07:25:55 +0000 Subject: [PATCH] * Added (and use) $format param to formatTimePeriod() to make output less verbose for ValidationStatistics_body.php * Small w/s changes to FlaggedRevsStats.php --- languages/Language.php | 45 +++++++++++++++++---------- languages/messages/MessagesEn.php | 1 + maintenance/language/messageTypes.inc | 1 + 3 files changed, 31 insertions(+), 16 deletions(-) diff --git a/languages/Language.php b/languages/Language.php index 68cd578985..00efc44be1 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3410,14 +3410,19 @@ class Language { /** * @todo Document - * @param $seconds String + * @param $seconds int|float + * @param $format String Optional, one of ("avoidseconds","avoidseconds"): + * If "avoidminutes" don't mention minutes if $seconds >= 1 hour + * If "avoidseconds" don't mention seconds/minutes if $seconds > 2 days * @return string */ - function formatTimePeriod( $seconds ) { + function formatTimePeriod( $seconds, $format = false ) { if ( round( $seconds * 10 ) < 100 ) { - return $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ) . $this->getMessageFromDB( 'seconds-abbrev' ); + return $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ) . + $this->getMessageFromDB( 'seconds-abbrev' ); } elseif ( round( $seconds ) < 60 ) { - return $this->formatNum( round( $seconds ) ) . $this->getMessageFromDB( 'seconds-abbrev' ); + return $this->formatNum( round( $seconds ) ) . + $this->getMessageFromDB( 'seconds-abbrev' ); } elseif ( round( $seconds ) < 3600 ) { $minutes = floor( $seconds / 60 ); $secondsPart = round( fmod( $seconds, 60 ) ); @@ -3425,23 +3430,31 @@ class Language { $secondsPart = 0; $minutes++; } - return $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ) . ' ' . + return $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ) . + ' ' . $this->formatNum( $secondsPart ) . $this->getMessageFromDB( 'seconds-abbrev' ); - } else { + } elseif ( round( $seconds ) <= 2*86400 ) { $hours = floor( $seconds / 3600 ); $minutes = floor( ( $seconds - $hours * 3600 ) / 60 ); - $secondsPart = round( $seconds - $hours * 3600 - $minutes * 60 ); - if ( $secondsPart == 60 ) { - $secondsPart = 0; - $minutes++; + $secondsPart = floor( $seconds - $hours * 3600 - $minutes * 60 ); + $s = $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ) . + ' ' . + $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ); + if ( $format !== 'avoidseconds' ) { + $s .= ' ' . $this->formatNum( $secondsPart ) . + $this->getMessageFromDB( 'seconds-abbrev' ); } - if ( $minutes == 60 ) { - $minutes = 0; - $hours++; + return $s; + } else { + $days = floor( $seconds / 86400 ); + $s = $this->formatNum( $days ) . $this->getMessageFromDB( 'days-abbrev' ) . ' '; + if ( $format === 'avoidminutes' ) { + $hours = floor( ( $seconds - $days * 86400 ) / 3600 ); + $s .= $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ); + } else { + $s .= $this->formatTimePeriod( $seconds - $days * 86400, $format ); } - return $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ) . ' ' . - $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ) . ' ' . - $this->formatNum( $secondsPart ) . $this->getMessageFromDB( 'seconds-abbrev' ); + return $s; } } diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index c37d7436dc..d83749988f 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -3658,6 +3658,7 @@ By executing it, your system may be compromised.", 'seconds-abbrev' => 's', # only translate this message to other languages if you have to change it 'minutes-abbrev' => 'm', # only translate this message to other languages if you have to change it 'hours-abbrev' => 'h', # only translate this message to other languages if you have to change it +'days-abbrev' => 'd', # only translate this message to other languages if you have to change it # Bad image list 'bad_image_list' => 'The format is as follows: diff --git a/maintenance/language/messageTypes.inc b/maintenance/language/messageTypes.inc index f6b6008c51..454dfc7b01 100644 --- a/maintenance/language/messageTypes.inc +++ b/maintenance/language/messageTypes.inc @@ -311,6 +311,7 @@ $wgOptionalMessages = array( 'seconds-abbrev', 'minutes-abbrev', 'hours-abbrev', + 'days-abbrev', 'filerevert-backlink', 'filedelete-backlink', 'delete-backlink', -- 2.20.1