Fix bug 7715:
authorRobert Leverington <roberthl@users.mediawiki.org>
Wed, 28 May 2008 07:40:55 +0000 (07:40 +0000)
committerRobert Leverington <roberthl@users.mediawiki.org>
Wed, 28 May 2008 07:40:55 +0000 (07:40 +0000)
* Add two conditional functions date_default_timezone_get() and date_default_timezone_set()
  which are created if they are not available (PHP <5.1.0).
* Replace setenv( TZ= ) and getenv( TZ ) calls with date_default_timezone_get( TZ ) and
  date_default_timezone_set( TZ ).
* Remove some warning supression calls, they were suppressing an E_STRICT level error that
  is thrown in PHP >5.1.0, however the above changes stop that error from ever occurring
  in the first place.
* Alter comment in DefaultSettings.php to refer to this function rather than the old
  method of using setenv().
* Add item to RELEASE-NOTES bug fixes section and fix line width of one item.
Based on attachment 2577 by nekocue.

RELEASE-NOTES
includes/DefaultSettings.php
includes/GlobalFunctions.php
includes/Parser.php
includes/Parser_OldPP.php

index 44bdd0f..89b9e99 100644 (file)
@@ -127,8 +127,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
 * (bug 13095) Search by first letters or digits in [[Special:Categories]]
 * Users moving a page can now move all subpages automatically as well
 * Sidebar is now cached for all languages
-* (bug 14259) Localisation message for upload button on Special:Import is now 'import-upload'
-  instead of 'upload'
+* (bug 14259) Localisation message for upload button on Special:Import is now
+  'import-upload' instead of 'upload'
 
 === Bug fixes in 1.13 ===
 
@@ -301,6 +301,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN
   disabling $wgStrictFileExtensions
 * (bug 14241) Pages can no longer be protected to levels you are not in
 * (bug 14296) Fix local name of ang: (Anglo-Saxon)
+* (bug 7715) Use date_default_timezone_* instead of TZ environment variable if
+  available
 
 === API changes in 1.13 ===
 
index 992be45..550d7d8 100644 (file)
@@ -2444,7 +2444,7 @@ $wgLocaltimezone = null;
  * this in conjunction with the signature timezone and override the TZ
  * environment variable 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 3294c8f..e51fc71 100644 (file)
@@ -87,6 +87,28 @@ if ( !function_exists( 'array_diff_key' ) ) {
        }
 }
 
+if ( !function_exists( 'date_default_timezone_get' ) ) {
+       /**
+        * Exists in PHP 5.1.0+
+        * Simulates functionality partially.
+        * @return String: Environment timezone.
+        */
+       function date_default_timezone_get() {
+               return getenv( 'TZ' );
+       }
+}
+if ( !function_exists( 'date_default_timezone_set' ) ) {
+       /**
+        * Exists in PHP 5.1.0+
+        * Simulates functionality partially.
+        * @param String: Timezone to set to.
+        * @return Boolean: Indication regarding if setting was successful.
+        */
+       function date_default_timezone_set( $setting ) {
+               return putenv( 'TZ=' . $setting );
+       }
+}
+
 /**
  * Like array_diff( $a, $b ) except that it works with two-dimensional arrays.
  */
index 0b8497f..a467f8d 100644 (file)
@@ -2381,11 +2381,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 );
                $localMonthName = date( 'n', $ts );
@@ -2396,9 +2395,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':
@@ -3703,11 +3701,11 @@ class Parser
                $tz = 'UTC';
                if ( isset( $wgLocaltimezone ) ) {
                        $unixts = wfTimestamp( TS_UNIX, $ts );
-                       $oldtz = getenv( 'TZ' );
-                       putenv( 'TZ='.$wgLocaltimezone );
+                       $oldtz = date_default_timezone_get();
+                       date_default_timezone_set( $wgLocaltimezone );
                        $ts = date( 'YmdHis', $unixts );
                        $tz = date( 'T', $unixts );  # might vary on DST changeover!
-                       putenv( 'TZ='.$oldtz );
+                       date_default_timezone_set( $oldtz );
                }
                $d = $wgContLang->timeanddate( $ts, false, false ) . " ($tz)";
 
index 57a981e..f2f1b72 100644 (file)
@@ -2402,11 +2402,10 @@ class Parser_OldPP
                # 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 );
                $localMonthName = date( 'n', $ts );
@@ -2417,9 +2416,8 @@ class Parser_OldPP
                $localYear = date( 'Y', $ts );
                $localHour = date( 'H', $ts );
                if ( isset( $wgLocaltimezone ) ) {
-                       putenv( 'TZ='.$oldtz );
+                       date_default_timezone_set( $oldtz );
                }
-               wfRestoreWarnings();
 
                switch ( $index ) {
                        case 'currentmonth':
@@ -3781,13 +3779,13 @@ class Parser_OldPP
                 * than the one selected in each user's preferences.
                 */
                if ( isset( $wgLocaltimezone ) ) {
-                       $oldtz = getenv( 'TZ' );
-                       putenv( 'TZ='.$wgLocaltimezone );
+                       $oldtz = date_default_timezone_get();
+                       date_default_timezone_set( $wgLocaltimezone );
                }
                $d = $wgContLang->timeanddate( date( 'YmdHis' ), false, false) .
                  ' (' . date( 'T' ) . ')';
                if ( isset( $wgLocaltimezone ) ) {
-                       putenv( 'TZ='.$oldtz );
+                       date_default_timezone_set( $oldtz );
                }
 
                # Variable replacement