From: Bartosz DziewoƄski Date: Wed, 18 Jan 2017 13:08:28 +0000 (+0100) Subject: BlockLogFormatter: Durations are relative to block's timestamp, not Unix epoch X-Git-Tag: 1.31.0-rc.0~4263^2 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_aide%28?a=commitdiff_plain;h=01936fa994fa79946d090b5caddbb737c77677c9;p=lhc%2Fweb%2Fwiklou.git BlockLogFormatter: Durations are relative to block's timestamp, not Unix epoch Also fixed legacy code in LogFormatter producing messages for IRC feed. Bug: T55907 Change-Id: I0df19574f74210a91ce72c79188b6618f04ef9a2 --- diff --git a/includes/logging/BlockLogFormatter.php b/includes/logging/BlockLogFormatter.php index c3902326c6..a0bfb59345 100644 --- a/includes/logging/BlockLogFormatter.php +++ b/includes/logging/BlockLogFormatter.php @@ -59,9 +59,15 @@ class BlockLogFormatter extends LogFormatter { // The lrm is needed to make sure that the number // is shown on the correct side of the tooltip text. $durationTooltip = '‎' . htmlspecialchars( $params[4] ); - $params[4] = Message::rawParam( "" . - $this->context->getLanguage()->translateBlockExpiry( $params[4], - $this->context->getUser() ) . '' ); + $params[4] = Message::rawParam( + "" . + $this->context->getLanguage()->translateBlockExpiry( + $params[4], + $this->context->getUser(), + wfTimestamp( TS_UNIX, $this->entry->getTimestamp() ) + ) . + '' + ); $params[5] = isset( $params[5] ) ? self::formatBlockFlags( $params[5], $this->context->getLanguage() ) : ''; } diff --git a/includes/logging/LogFormatter.php b/includes/logging/LogFormatter.php index a64fee1e50..b5af7836ca 100644 --- a/includes/logging/LogFormatter.php +++ b/includes/logging/LogFormatter.php @@ -353,7 +353,11 @@ class LogFormatter { $rawDuration = $parameters['5::duration']; $rawFlags = $parameters['6::flags']; } - $duration = $wgContLang->translateBlockExpiry( $rawDuration ); + $duration = $wgContLang->translateBlockExpiry( + $rawDuration, + null, + wfTimestamp( TS_UNIX, $entry->getTimestamp() ) + ); $flags = BlockLogFormatter::formatBlockFlags( $rawFlags, $wgContLang ); $text = wfMessage( 'blocklogentry' ) ->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped(); @@ -363,7 +367,11 @@ class LogFormatter { ->rawParams( $target )->inContentLanguage()->escaped(); break; case 'reblock': - $duration = $wgContLang->translateBlockExpiry( $parameters['5::duration'] ); + $duration = $wgContLang->translateBlockExpiry( + $parameters['5::duration'], + null, + wfTimestamp( TS_UNIX, $entry->getTimestamp() ) + ); $flags = BlockLogFormatter::formatBlockFlags( $parameters['6::flags'], $wgContLang ); $text = wfMessage( 'reblock-logentry' ) ->rawParams( $target, $duration, $flags )->inContentLanguage()->escaped(); diff --git a/languages/Language.php b/languages/Language.php index 5bce76bfcc..8c7ce31629 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -3975,10 +3975,11 @@ class Language { * * @param string $str The validated block duration in English * @param User $user User object to use timezone from or null for $wgUser + * @param int $now Current timestamp, for formatting relative block durations * @return string Somehow translated block duration * @see LanguageFi.php for example implementation */ - function translateBlockExpiry( $str, User $user = null ) { + function translateBlockExpiry( $str, User $user = null, $now = 0 ) { $duration = SpecialBlock::getSuggestedDurations( $this ); foreach ( $duration as $show => $value ) { if ( strcmp( $str, $value ) == 0 ) { @@ -3995,11 +3996,11 @@ class Language { } // If all else fails, return a standard duration or timestamp description. - $time = strtotime( $str, 0 ); + $time = strtotime( $str, $now ); if ( $time === false ) { // Unknown format. Return it as-is in case. return $str; - } elseif ( $time !== strtotime( $str, 1 ) ) { // It's a relative timestamp. - // $time is relative to 0 so it's a duration length. + } elseif ( $time !== strtotime( $str, $now + 1 ) ) { // It's a relative timestamp. + // The result differs based on current time, so it's a duration length. return $this->formatDuration( $time ); } else { // It's an absolute timestamp. if ( $time === 0 ) { diff --git a/languages/classes/LanguageFi.php b/languages/classes/LanguageFi.php index 338853683c..54ff421634 100644 --- a/languages/classes/LanguageFi.php +++ b/languages/classes/LanguageFi.php @@ -85,9 +85,10 @@ class LanguageFi extends Language { /** * @param string $str * @param User $user User object to use timezone from or null for $wgUser + * @param int $now Current timestamp, for formatting relative block durations * @return string */ - function translateBlockExpiry( $str, User $user = null ) { + function translateBlockExpiry( $str, User $user = null, $now = 0 ) { /* 'ago', 'now', 'today', 'this', 'next', 'first', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',