Add MWTimestamp::getTimezoneString(), use it in file revert message
authorgladoscc <admin@glados.cc>
Fri, 26 Dec 2014 01:57:14 +0000 (12:57 +1100)
committerErik Bernhardson <ebernhardson@wikimedia.org>
Wed, 23 Sep 2015 20:38:16 +0000 (13:38 -0700)
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

RELEASE-NOTES-1.26
includes/MWTimestamp.php
includes/actions/RevertAction.php
includes/parser/Parser.php
languages/i18n/en.json
languages/i18n/qqq.json

index d5b521e..281168e 100644 (file)
@@ -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.
index d28f88e..6f3be73 100644 (file)
@@ -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.
         *
index c7f3346..4885a31 100644 (file)
@@ -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()
                        )
                );
        }
index 677da63..8619751 100644 (file)
@@ -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)";
 
index 970f8ab..2819dfb 100644 (file)
        "filerevert-legend": "Revert file",
        "filerevert-intro": "You are about to revert the file <strong>[[Media:$1|$1]]</strong> 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": "<strong>[[Media:$1|$1]]</strong> 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.",
index 762dcbb..4474ec4 100644 (file)
        "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.",