r98138 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98137‎ | r98138 | r98139 >
Date:15:22, 26 September 2011
Author:catrope
Status:ok
Tags:
Comment:
1.17wmf1: MFT r97962, r98006, basically copies formatTimePeriod() from trunk
Modified paths:
  • /branches/wmf/1.17wmf1/languages/Language.php (modified) (history)
  • /branches/wmf/1.17wmf1/languages/messages/MessagesEn.php (modified) (history)

Diff [purge]

Index: branches/wmf/1.17wmf1/languages/messages/MessagesEn.php
@@ -3592,9 +3592,15 @@
35933593
35943594 # Video information, used by Language::formatTimePeriod() to format lengths in the above messages
35953595 'video-dims' => '$1, $2×$3', # only translate this message to other languages if you have to change it
3596 -'seconds-abbrev' => 's', # only translate this message to other languages if you have to change it
3597 -'minutes-abbrev' => 'm', # only translate this message to other languages if you have to change it
3598 -'hours-abbrev' => 'h', # only translate this message to other languages if you have to change it
 3596+'seconds-abbrev' => '$1s', # only translate this message to other languages if you have to change it
 3597+'minutes-abbrev' => '$1m', # only translate this message to other languages if you have to change it
 3598+'hours-abbrev' => '$1h', # only translate this message to other languages if you have to change it
 3599+'days-abbrev' => '$1d', # only translate this message to other languages if you have to change it
 3600+'seconds' => '{{PLURAL:$1|$1 second|$1 seconds}}',
 3601+'minutes' => '{{PLURAL:$1|$1 minute|$1 minutes}}',
 3602+'hours' => '{{PLURAL:$1|$1 hour|$1 hours}}',
 3603+'days' => '{{PLURAL:$1|$1 day|$1 days}}',
 3604+'ago' => '$1 ago',
35993605
36003606 # Bad image list
36013607 'bad_image_list' => 'The format is as follows:
Property changes on: branches/wmf/1.17wmf1/languages/messages/MessagesEn.php
___________________________________________________________________
Modified: svn:mergeinfo
36023608 Merged /trunk/phase3/languages/messages/MessagesEn.php:r95318,97962,98006
Index: branches/wmf/1.17wmf1/languages/Language.php
@@ -2904,11 +2904,37 @@
29052905 return array( $wikiUpperChars, $wikiLowerChars );
29062906 }
29072907
2908 - function formatTimePeriod( $seconds ) {
 2908+ /**
 2909+ * @todo Document
 2910+ * @param $seconds int|float
 2911+ * @param $format Array Optional
 2912+ * If $format['avoid'] == 'avoidseconds' - don't mention seconds if $seconds >= 1 hour
 2913+ * If $format['avoid'] == 'avoidminutes' - don't mention seconds/minutes if $seconds > 48 hours
 2914+ * If $format['noabbrevs'] is true - use 'seconds' and friends instead of 'seconds-abbrev' and friends
 2915+ * For backwards compatibility, $format may also be one of the strings 'avoidseconds' or 'avoidminutes'
 2916+ * @return string
 2917+ */
 2918+ function formatTimePeriod( $seconds, $format = array() ) {
 2919+ if ( !is_array( $format ) ) {
 2920+ $format = array( 'avoid' => $format, 'noabbrevs' => false ); // For backwards compatibility
 2921+ }
 2922+ if ( !isset( $format['avoid'] ) ) {
 2923+ $format['avoid'] = false;
 2924+ }
 2925+ if ( !isset( $format['noabbrevs' ] ) ) {
 2926+ $format['noabbrevs'] = false;
 2927+ }
 2928+ $secondsMsg = wfMessage( $format['noabbrevs'] ? 'seconds' : 'seconds-abbrev' )->inLanguage( $this );
 2929+ $minutesMsg = wfMessage( $format['noabbrevs'] ? 'minutes' : 'minutes-abbrev' )->inLanguage( $this );
 2930+ $hoursMsg = wfMessage( $format['noabbrevs'] ? 'hours' : 'hours-abbrev' )->inLanguage( $this );
 2931+ $daysMsg = wfMessage( $format['noabbrevs'] ? 'days' : 'days-abbrev' )->inLanguage( $this );
 2932+
29092933 if ( round( $seconds * 10 ) < 100 ) {
2910 - return $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) ) . $this->getMessageFromDB( 'seconds-abbrev' );
 2934+ $s = $this->formatNum( sprintf( "%.1f", round( $seconds * 10 ) / 10 ) );
 2935+ $s = $secondsMsg->params( $s )->text();
29112936 } elseif ( round( $seconds ) < 60 ) {
2912 - return $this->formatNum( round( $seconds ) ) . $this->getMessageFromDB( 'seconds-abbrev' );
 2937+ $s = $this->formatNum( round( $seconds ) );
 2938+ $s = $secondsMsg->params( $s )->text();
29132939 } elseif ( round( $seconds ) < 3600 ) {
29142940 $minutes = floor( $seconds / 60 );
29152941 $secondsPart = round( fmod( $seconds, 60 ) );
@@ -2916,9 +2942,10 @@
29172943 $secondsPart = 0;
29182944 $minutes++;
29192945 }
2920 - return $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ) . ' ' .
2921 - $this->formatNum( $secondsPart ) . $this->getMessageFromDB( 'seconds-abbrev' );
2922 - } else {
 2946+ $s = $minutesMsg->params( $this->formatNum( $minutes ) )->text();
 2947+ $s .= ' ';
 2948+ $s .= $secondsMsg->params( $this->formatNum( $secondsPart ) )->text();
 2949+ } elseif ( round( $seconds ) <= 2 * 86400 ) {
29232950 $hours = floor( $seconds / 3600 );
29242951 $minutes = floor( ( $seconds - $hours * 3600 ) / 60 );
29252952 $secondsPart = round( $seconds - $hours * 3600 - $minutes * 60 );
@@ -2930,10 +2957,46 @@
29312958 $minutes = 0;
29322959 $hours++;
29332960 }
2934 - return $this->formatNum( $hours ) . $this->getMessageFromDB( 'hours-abbrev' ) . ' ' .
2935 - $this->formatNum( $minutes ) . $this->getMessageFromDB( 'minutes-abbrev' ) . ' ' .
2936 - $this->formatNum( $secondsPart ) . $this->getMessageFromDB( 'seconds-abbrev' );
 2961+ $s = $hoursMsg->params( $this->formatNum( $hours ) )->text();
 2962+ $s .= ' ';
 2963+ $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text();
 2964+ if ( !in_array( $format['avoid'], array( 'avoidseconds', 'avoidminutes' ) ) ) {
 2965+ $s .= ' ' . $secondsMsg->params( $this->formatNum( $secondsPart ) )->text();
 2966+ }
 2967+ } else {
 2968+ $days = floor( $seconds / 86400 );
 2969+ if ( $format['avoid'] === 'avoidminutes' ) {
 2970+ $hours = round( ( $seconds - $days * 86400 ) / 3600 );
 2971+ if ( $hours == 24 ) {
 2972+ $hours = 0;
 2973+ $days++;
 2974+ }
 2975+ $s = $daysMsg->params( $this->formatNum( $days ) )->text();
 2976+ $s .= ' ';
 2977+ $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text();
 2978+ } elseif ( $format['avoid'] === 'avoidseconds' ) {
 2979+ $hours = floor( ( $seconds - $days * 86400 ) / 3600 );
 2980+ $minutes = round( ( $seconds - $days * 86400 - $hours * 3600 ) / 60 );
 2981+ if ( $minutes == 60 ) {
 2982+ $minutes = 0;
 2983+ $hours++;
 2984+ }
 2985+ if ( $hours == 24 ) {
 2986+ $hours = 0;
 2987+ $days++;
 2988+ }
 2989+ $s = $daysMsg->params( $this->formatNum( $days ) )->text();
 2990+ $s .= ' ';
 2991+ $s .= $hoursMsg->params( $this->formatNum( $hours ) )->text();
 2992+ $s .= ' ';
 2993+ $s .= $minutesMsg->params( $this->formatNum( $minutes ) )->text();
 2994+ } else {
 2995+ $s = $daysMsg->params( $this->formatNum( $days ) )->text();
 2996+ $s .= ' ';
 2997+ $s .= $this->formatTimePeriod( $seconds - $days * 86400, $format );
 2998+ }
29372999 }
 3000+ return $s;
29383001 }
29393002
29403003 function formatBitrate( $bps ) {
Property changes on: branches/wmf/1.17wmf1/languages/Language.php
___________________________________________________________________
Modified: svn:mergeinfo
29413004 Merged /trunk/phase3/languages/Language.php:r95318,97962,98006

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r97962Make Language::formatTimePeriod() more flexible so it can produce stuff like ...catrope22:17, 23 September 2011
r98006Per CR on r97962, introduce an array parameter for formatTimePeriod() rather ...catrope15:44, 24 September 2011

Status & tagging log