From: gladoscc Date: Fri, 26 Dec 2014 01:57:14 +0000 (+1100) Subject: Add MWTimestamp::getTimezoneString(), use it in file revert message X-Git-Tag: 1.31.0-rc.0~9879^2 X-Git-Url: http://git.heureux-cyclage.org/?a=commitdiff_plain;h=90e1b22166b00e096930d90029bd9826843298b2;p=lhc%2Fweb%2Fwiklou.git Add MWTimestamp::getTimezoneString(), use it in file revert message MWTimestamp::getTimezoneString() returns the timezone name as a message, that supports wiki localization. The code is moved from Parser::pstPass2. The default file revert message is currently always in UTC. This patch sets the default timestamp to be in the wiki timezone (similar to ~~~~). The timezone is passed as a new parameter to the message, with the date / time parameters being merged and handled by $wgContentLang->timeanddate Bug: T36948 Change-Id: I48772f5f3b1635d33b6185776cedfc4ee1882494 --- diff --git a/RELEASE-NOTES-1.26 b/RELEASE-NOTES-1.26 index d5b521e67f..281168eb16 100644 --- a/RELEASE-NOTES-1.26 +++ b/RELEASE-NOTES-1.26 @@ -70,6 +70,9 @@ production. * Caches that need purging ability now use the WANObjectCache interface. This corresponds to a new $wgMainWANCache setting, which defaults to using the $wgMainCacheType settings. +* Added MWTimestamp::getTimezoneString() which returns the localized timezone + string, if available. To localize this string, see the comments of + $wgLocaltimezone in includes/DefaultSettings.php. * Callers needing fast light-weight data stores use $wgMainStash to select the store type from $wgObjectCaches. The default is the local database. * Interface message overrides in the MediaWiki namespace will now be cached in @@ -198,6 +201,8 @@ changes to languages because of Phabricator reports. * Watchlist tokens, SpecialResetTokens, and User::getTokenFromOption() are deprecated. Applications using those can work via the OAuth extension instead. New tokens types should not be added. +* (T36948) The default file revert message's timestamp is now in $wgLocaltimezone, + instead of UTC. * DatabaseBase::errorCount() was removed (unused). * $wgDeferredUpdateList was removed. * DeferredUpdates::addHTMLCacheUpdate() was removed. diff --git a/includes/MWTimestamp.php b/includes/MWTimestamp.php index d28f88e504..6f3be73f4d 100644 --- a/includes/MWTimestamp.php +++ b/includes/MWTimestamp.php @@ -367,6 +367,26 @@ class MWTimestamp { return $this->timestamp->getTimezone(); } + /** + * Get the localized timezone message, if available. + * + * Premade translations are not shipped as format() may return whatever the + * system uses, localized or not, so translation must be done through wiki. + * + * @since 1.25 + * @return Message The localized timezone message + */ + public function getTimezoneMessage() { + $tzMsg = $this->format( 'T' ); // might vary on DST changeover! + $key = 'timezone-' . strtolower( trim( $tzMsg ) ); + $msg = wfMessage( $key ); + if ( $msg->exists() ) { + return $msg; + } else { + return new RawMessage( $tzMsg ); + } + } + /** * Format the timestamp in a given format. * diff --git a/includes/actions/RevertAction.php b/includes/actions/RevertAction.php index c7f33463f5..4885a31ec1 100644 --- a/includes/actions/RevertAction.php +++ b/includes/actions/RevertAction.php @@ -82,8 +82,11 @@ class RevertAction extends FormAction { $lang = $this->getLanguage(); $userDate = $lang->userDate( $timestamp, $user ); $userTime = $lang->userTime( $timestamp, $user ); - $siteDate = $wgContLang->date( $timestamp, false, false ); - $siteTime = $wgContLang->time( $timestamp, false, false ); + $siteTs = MWTimestamp::getLocalInstance( $timestamp ); + $ts = $siteTs->format( 'YmdHis' ); + $siteDate = $wgContLang->date( $ts, false, false ); + $siteTime = $wgContLang->time( $ts, false, false ); + $tzMsg = $siteTs->getTimezoneMessage()->inContentLanguage()->text(); return array( 'intro' => array( @@ -100,8 +103,8 @@ class RevertAction extends FormAction { 'comment' => array( 'type' => 'text', 'label-message' => 'filerevert-comment', - 'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime - )->inContentLanguage()->text() + 'default' => $this->msg( 'filerevert-defaultcomment', $siteDate, $siteTime, + $tzMsg )->inContentLanguage()->text() ) ); } diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 677da63bd7..86197512db 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4842,16 +4842,7 @@ class Parser { $ts = $this->mOptions->getTimestamp(); $timestamp = MWTimestamp::getLocalInstance( $ts ); $ts = $timestamp->format( 'YmdHis' ); - $tzMsg = $timestamp->format( 'T' ); # might vary on DST changeover! - - # Allow translation of timezones through wiki. format() can return - # whatever crap the system uses, localised or not, so we cannot - # ship premade translations. - $key = 'timezone-' . strtolower( trim( $tzMsg ) ); - $msg = wfMessage( $key )->inContentLanguage(); - if ( $msg->exists() ) { - $tzMsg = $msg->text(); - } + $tzMsg = $timestamp->getTimezoneMessage()->inContentLanguage()->text(); $d = $wgContLang->timeanddate( $ts, false, false ) . " ($tzMsg)"; diff --git a/languages/i18n/en.json b/languages/i18n/en.json index 970f8abec8..2819dfb753 100644 --- a/languages/i18n/en.json +++ b/languages/i18n/en.json @@ -1550,7 +1550,7 @@ "filerevert-legend": "Revert file", "filerevert-intro": "You are about to revert the file [[Media:$1|$1]] to the [$4 version as of $3, $2].", "filerevert-comment": "Reason:", - "filerevert-defaultcomment": "Reverted to version as of $2, $1", + "filerevert-defaultcomment": "Reverted to version as of $2, $1 ($3)", "filerevert-submit": "Revert", "filerevert-success": "[[Media:$1|$1]] has been reverted to the [$4 version as of $3, $2].", "filerevert-badversion": "There is no previous local version of this file with the provided timestamp.", diff --git a/languages/i18n/qqq.json b/languages/i18n/qqq.json index 762dcbb906..4474ec47d8 100644 --- a/languages/i18n/qqq.json +++ b/languages/i18n/qqq.json @@ -1723,7 +1723,7 @@ "filerevert-legend": "{{Identical|Revert}}", "filerevert-intro": "Message displayed when you try to revert a version of a file.\n* $1 is the name of the media\n* $2 is a date\n* $3 is a time\n* $4 is a URL and must follow square bracket: [$4\n{{Identical|Revert}}", "filerevert-comment": "{{Identical|Reason}}", - "filerevert-defaultcomment": "Parameters:\n* $1 - a date\n* $2 - a time\n{{Identical|Revert}}", + "filerevert-defaultcomment": "Parameters:\n* $1 - a date\n* $2 - a time\n* $3 - a timezone\n{{Identical|Revert}}", "filerevert-submit": "{{Identical|Revert}}", "filerevert-success": "Message displayed when you succeed in reverting a version of a file.\n* $1 is the name of the media\n* $2 is a date\n* $3 is a time\n* $4 is an URL and must follow square bracket: [$4\n{{Identical|Revert}}", "filerevert-badversion": "Used as error message.",