[Mediawiki-l] non-utc time variables

Simon Wagner wagner.sim88_mw at web.de
Wed Aug 23 12:15:16 UTC 2006


Well, here comes a patch. It's my first, so be patient ;-).
For the moment i have only changed {{CURRENTTIME}} and {{CURRENTTIMESTAMP}}. 
They are based now on the local time.
I have added two new Magic Words: {{CURRENTTIMEUTC}}and 
{{CURRENTTIMESTAMPUTC}}. They are based on UTC time.

I think it's better than using {{LOCALTIME}}, because, the first thing I 
would use as Magic Words to display the time would be {{CURRENTTIME}} and I 
would expect it to be based on the local time.
For the rare time, UTC is really needed there are the new Magic Words.
Change it if you don't agree.

The patch is based on Mediawiki 1.7 revision 16181. So depending on your 
wiki version cohesion, you will have to change the patch.
So would you try to test it? I have at the moment no MediaWiki by hand where 
i am allowed to play around ;-), so the patch is UNTESTED. But i think it 
should work. (The only thing i am not sure are typos).

And here comes the patch:
--------------BEGIN patch_localtime.diff-----------------
diff -Naur Kopie von phase3/includes/MagicWord.php 
phase3/includes/MagicWord.php
--- Kopie von phase3/includes/MagicWord.php 2006-08-22 20:32:41.968750000 
+0200
+++ phase3/includes/MagicWord.php 2006-08-23 13:40:36.953125000 +0200
@@ -25,6 +25,7 @@
  'MAG_CURRENTDAYNAME',
  'MAG_CURRENTYEAR',
  'MAG_CURRENTTIME',
+ 'MAG_CURRENTTIMEUTC'
  'MAG_NUMBEROFARTICLES',
  'MAG_SUBST',
  'MAG_MSG',
@@ -90,6 +91,7 @@
  'MAG_BASEPAGENAMEE',
  'MAG_URLENCODE',
  'MAG_CURRENTTIMESTAMP',
+ 'MAG_CURRENTTIMESTAMPUTC',
  'MAG_DIRECTIONMARK',
  'MAG_LANGUAGE',
  'MAG_CONTENTLANGUAGE',
@@ -114,6 +116,7 @@
  MAG_CURRENTDAYNAME,
  MAG_CURRENTYEAR,
  MAG_CURRENTTIME,
+ MAG_CURRENTTIMEUTC,
  MAG_NUMBEROFARTICLES,
  MAG_NUMBEROFFILES,
  MAG_SITENAME,
@@ -149,6 +152,7 @@
  MAG_BASEPAGENAMEE,
  MAG_URLENCODE,
  MAG_CURRENTTIMESTAMP,
+ MAG_CURRENTTIMESTAMPUTC,
  MAG_DIRECTIONMARK,
  MAG_LANGUAGE,
  MAG_CONTENTLANGUAGE,
diff -Naur Kopie von phase3/includes/Parser.php phase3/includes/Parser.php
--- Kopie von phase3/includes/Parser.php 2006-08-22 20:32:41.359375000 +0200
+++ phase3/includes/Parser.php 2006-08-23 13:39:12.312500000 +0200
@@ -2221,7 +2221,18 @@

   $ts = time();
   wfRunHooks( 'ParserGetVariableValueTs', array( &$this, &$ts ) );
+  # Use the time zone
+  global $wgLocaltimezone;
+  if ( isset( $wgLocaltimezone ) ) {
+          $oldtz = getenv( 'TZ' );
+          putenv( 'TZ='.$wgLocaltimezone ); #set TZ to wgLocaltimezone
+  }
+  $local_timestamp = date( 'YmdHis', $ts ); #save the local timestamp

+  if ( isset( $wgLocaltimezone ) ) {
+   putenv( 'TZ='.$oldtz ); #set TZ back to the original value
+  }
+
   switch ( $index ) {
    case MAG_CURRENTMONTH:
     return $varCache[$index] = $wgContLang->formatNum( date( 'm', $ts ) );
@@ -2289,7 +2300,9 @@
     return $varCache[$index] = $wgContLang->getWeekdayName( date( 'w', 
$ts ) + 1 );
    case MAG_CURRENTYEAR:
     return $varCache[$index] = $wgContLang->formatNum( date( 'Y', $ts ), 
true );
-   case MAG_CURRENTTIME:
+   case MAG_CURRENTTIME: //returns local time
+    return $varCache[$index] = $wgContLang->time( $local_timestamp, false, 
false );
+   case MAG_CURRENTTIMEUTC: //returns UTC time
     return $varCache[$index] = $wgContLang->time( wfTimestamp( TS_MW, 
$ts ), false, false );
    case MAG_CURRENTWEEK:
     // @bug 4594 PHP5 has it zero padded, PHP4 does not, cast to
@@ -2307,7 +2320,9 @@
     return $varCache[$index] = $wgContLang->formatNum( wfNumberOfPages() );
    case MAG_NUMBEROFADMINS:
     return $varCache[$index]  = $wgContLang->formatNum( 
wfNumberOfAdmins() );
-   case MAG_CURRENTTIMESTAMP:
+   case MAG_CURRENTTIMESTAMP: //returns local timestamp
+    return $varCache[$index] = $local_timestamp
+   case MAG_CURRENTTIMESTAMPUTC: //returns UTC timestamp
     return $varCache[$index] = wfTimestampNow();
    case MAG_CURRENTVERSION:
     global $wgVersion;
------------------------END patch_localtime.diff-----------------------

Hope it will work!
Simon

----- Original Message ----- 
From: "cohesion" <cohesion at sleepyhead.org>
To: <mediawiki-l at wikimedia.org>
Sent: Monday, August 21, 2006 6:34 PM
Subject: Re: [Mediawiki-l] non-utc time variables


> On 8/21/06, Brion Vibber <brion at pobox.com> wrote:
>> cohesion wrote:
>> > It seems like it would be a common request, but I can't seem to find
>> > the solution. How can I set the time offset so that time variables
>> > like {{CURRENTDAYNAME}} are based on something other than UTC. I am
>> > running mediawiki for a small group of geographically homogeneous
>> > users and having things be based on UTC is very confusing for them.
>>
>> What I've recommended is adding a {{LOCALTIME}}, {{LOCALDAY}} etc set of
>> parallel variables which will use the site-defined local time. This will 
>> avoid
>> breaking compatibility.
>>
>> You could probably hack it in pretty easily in Parser.php; if you do 
>> please
>> submit a patch. ;)
>
>
> Thanks, {{LOCALTIME}} etc would be great, in the meantime I did a
> super hacky thing just manually offsetting the $ts variable with what
> I want, which works, but probably isn't nice. I am not great at php :)
>
> It doesn't seem to do anything horrible or unexpected.
> _______________________________________________
> MediaWiki-l mailing list
> MediaWiki-l at Wikimedia.org
> http://mail.wikipedia.org/mailman/listinfo/mediawiki-l 




More information about the MediaWiki-l mailing list