* Fixed the issue of all date functions throwing E_STRICT on their first call due...
authorTim Starling <tstarling@users.mediawiki.org>
Fri, 8 Jan 2010 01:48:53 +0000 (01:48 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Fri, 8 Jan 2010 01:48:53 +0000 (01:48 +0000)
* (bug 2658) Don't use the TZ environment variable at all. Setting it throws an error in some restricted setups. But using it in PHP 5.1+ doesn't make sense anyway, since you'll get the E_STRICT notice described above whenever PHP tries to access it, because Derick hates environment variables. Use date_default_timezone_set().
* If $wgLocaltimezone is null, use the server's timezone as the default for signatures. This was always the behaviour documented in DefaultSettings.php but has not been the actual behaviour for some time: instead, UTC was used by default.

RELEASE-NOTES
includes/DefaultSettings.php
includes/Setup.php
includes/parser/Parser.php

index 87b87fa..a4f4e26 100644 (file)
@@ -84,7 +84,12 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * $wgUploadNavigationUrl now also affects images inline images that do not 
   exist. In that case the URL will get (?|&)wpDestFile=<filename> appended to 
   it as appropriate.
-  
+* If $wgLocaltimezone is null, use the server's timezone as the default for
+  signatures. This was always the behaviour documented in DefaultSettings.php
+  but has not been the actual behaviour for some time: instead, UTC was used 
+  by default.
+
+
 === New features in 1.16 ===
 
 * Add CSS defintion of the 'wikitable' class to shared.css
@@ -683,6 +688,7 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   type selector on Special:Log
 * (bug 20115) Special:Userlogin title says "Log in / create account" even if the
   user can't create an account
+* (bug 2658) Don't attempt to set the TZ environment variable.
 
 == API changes in 1.16 ==
 
index 29b83f7..fb50b72 100644 (file)
@@ -3080,10 +3080,10 @@ $wgBrowserBlackList = array(
 /**
  * Fake out the timezone that the server thinks it's in. This will be used for
  * date display and not for what's stored in the DB. Leave to null to retain
- * your server's OS-based timezone value. This is the same as the timezone.
+ * your server's OS-based timezone value. 
  *
- * This variable is currently used ONLY for signature formatting, not for
- * anything else.
+ * This variable is currently used only for signature formatting and for local 
+ * time/date parser variables ({{LOCALTIME}} etc.)
  *
  * Timezones can be translated by editing MediaWiki messages of type
  * timezone-nameinlowercase like timezone-utc.
@@ -3105,10 +3105,10 @@ $wgLocaltimezone = null;
  *   $wgLocalTZoffset = date("Z") / 60;
  *
  * If your server is not configured for the timezone you want, you can set
- * this in conjunction with the signature timezone and override the TZ
- * environment variable like so:
+ * this in conjunction with the signature timezone and override the PHP default
+ * timezone like so:
  *   $wgLocaltimezone="Europe/Berlin";
- *   putenv("TZ=$wgLocaltimezone");
+ *   date_default_timezone_set( $wgLocaltimezone );
  *   $wgLocalTZoffset = date("Z") / 60;
  *
  * Leave at NULL to show times in universal time (UTC/GMT).
index 62e7b0a..1bc2dba 100644 (file)
@@ -140,7 +140,6 @@ if( $wgUseInstantCommons ) {
        );
 }
 
-
 if ( !class_exists( 'AutoLoader' ) ) {
        require_once( "$IP/includes/AutoLoader.php" );
 }
@@ -160,9 +159,19 @@ require_once( "$IP/includes/ImageFunctions.php" );
 require_once( "$IP/includes/StubObject.php" );
 wfProfileOut( $fname.'-includes' );
 wfProfileIn( $fname.'-misc1' );
+
 # Raise the memory limit if it's too low
 wfMemoryLimit();
 
+/**
+ * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+ 
+ * that happens whenever you use a date function without the timezone being
+ * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
+ */
+wfSuppressWarnings();
+date_default_timezone_set( date_default_timezone_get() );
+wfRestoreWarnings();
+
 $wgIP = false; # Load on demand
 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
 $wgRequest = new WebRequest;
index 334021a..dad1cca 100644 (file)
@@ -2332,11 +2332,10 @@ class Parser
                # Use the time zone
                global $wgLocaltimezone;
                if ( isset( $wgLocaltimezone ) ) {
-                       $oldtz = getenv( 'TZ' );
-                       putenv( 'TZ='.$wgLocaltimezone );
+                       $oldtz = date_default_timezone_get();
+                       date_default_timezone_set( $wgLocaltimezone );
                }
 
-               wfSuppressWarnings(); // E_STRICT system time bitching
                $localTimestamp = date( 'YmdHis', $ts );
                $localMonth = date( 'm', $ts );
                $localMonth1 = date( 'n', $ts );
@@ -2348,9 +2347,8 @@ class Parser
                $localYear = date( 'Y', $ts );
                $localHour = date( 'H', $ts );
                if ( isset( $wgLocaltimezone ) ) {
-                       putenv( 'TZ='.$oldtz );
+                       date_default_timezone_set( $oldtz );
                }
-               wfRestoreWarnings();
 
                switch ( $index ) {
                        case 'currentmonth':
@@ -3965,26 +3963,29 @@ class Parser
                 * (see also bug 12815)
                 */
                $ts = $this->mOptions->getTimestamp();
-               $tz = wfMsgForContent( 'timezone-utc' );
                if ( isset( $wgLocaltimezone ) ) {
-                       $unixts = wfTimestamp( TS_UNIX, $ts );
-                       $oldtz = getenv( 'TZ' );
-                       putenv( 'TZ='.$wgLocaltimezone );
-                       $ts = date( 'YmdHis', $unixts );
-                       $tz = date( 'T', $unixts );  # might vary on DST changeover!
+                       $tz = $wgLocaltimezone;
+               } else {
+                       $tz = date_default_timezone_get();
+               }
 
-                       /* Allow translation of timezones trough wiki. date() can return
-                        * whatever crap the system uses, localised or not, so we cannot
-                        * ship premade translations.
-                        */
-                       $key = 'timezone-' . strtolower( trim( $tz ) );
-                       $value = wfMsgForContent( $key );
-                       if ( !wfEmptyMsg( $key, $value ) ) $tz = $value;
+               $unixts = wfTimestamp( TS_UNIX, $ts );
+               $oldtz = date_default_timezone_get();
+               date_default_timezone_set( $tz );
+               $ts = date( 'YmdHis', $unixts );
+               $tzMsg = date( 'T', $unixts );  # might vary on DST changeover!
 
-                       putenv( 'TZ='.$oldtz );
-               }
+               /* Allow translation of timezones trough wiki. date() can return
+                * whatever crap the system uses, localised or not, so we cannot
+                * ship premade translations.
+                */
+               $key = 'timezone-' . strtolower( trim( $tzMsg ) );
+               $value = wfMsgForContent( $key );
+               if ( !wfEmptyMsg( $key, $value ) ) $tzMsg = $value;
+
+               date_default_timezone_set( $oldtz );
 
-               $d = $wgContLang->timeanddate( $ts, false, false ) . " ($tz)";
+               $d = $wgContLang->timeanddate( $ts, false, false ) . " ($tzMsg)";
 
                # Variable replacement
                # Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags