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
This commit is contained in:
parent
c186988a83
commit
01936fa994
4 changed files with 26 additions and 10 deletions
|
|
@ -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( "<span class='blockExpiry' title='$durationTooltip'>" .
|
||||
$this->context->getLanguage()->translateBlockExpiry( $params[4],
|
||||
$this->context->getUser() ) . '</span>' );
|
||||
$params[4] = Message::rawParam(
|
||||
"<span class='blockExpiry' title='$durationTooltip'>" .
|
||||
$this->context->getLanguage()->translateBlockExpiry(
|
||||
$params[4],
|
||||
$this->context->getUser(),
|
||||
wfTimestamp( TS_UNIX, $this->entry->getTimestamp() )
|
||||
) .
|
||||
'</span>'
|
||||
);
|
||||
$params[5] = isset( $params[5] ) ?
|
||||
self::formatBlockFlags( $params[5], $this->context->getLanguage() ) : '';
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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 ) {
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
Loading…
Reference in a new issue