From 8e41f42b67cec4a6256080aea8a89c9e5b0ceb05 Mon Sep 17 00:00:00 2001 From: Robert Leverington Date: Wed, 28 May 2008 07:40:55 +0000 Subject: [PATCH] Fix bug 7715: * 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 | 6 ++++-- includes/DefaultSettings.php | 2 +- includes/GlobalFunctions.php | 22 ++++++++++++++++++++++ includes/Parser.php | 14 ++++++-------- includes/Parser_OldPP.php | 14 ++++++-------- 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 44bdd0fe41..89b9e998ca 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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 === diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 992be45fb9..550d7d8d39 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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). diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 3294c8f9b0..e51fc71193 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -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. */ diff --git a/includes/Parser.php b/includes/Parser.php index 0b8497f4fb..a467f8d004 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -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)"; diff --git a/includes/Parser_OldPP.php b/includes/Parser_OldPP.php index 57a981e462..f2f1b72422 100644 --- a/includes/Parser_OldPP.php +++ b/includes/Parser_OldPP.php @@ -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 -- 2.20.1