From debf8b2eb051d03551fe330d0ebf9a58e33a76a8 Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Fri, 8 Jan 2010 01:48:53 +0000 Subject: [PATCH] * Fixed the issue of all date functions throwing E_STRICT on their first call due to the default timezone not being set. Used the same approach as phpMyAdmin: utilise PHP's server timezone detection code (which unconditionally throws E_STRICT) with warnings disabled, and store the result with date_default_timezone_set() to avoid future notices. Avoids the need for warning suppression to be dotted all over the codebase, like r58559. * (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 | 8 ++++++- includes/DefaultSettings.php | 12 +++++----- includes/Setup.php | 11 ++++++++- includes/parser/Parser.php | 43 ++++++++++++++++++------------------ 4 files changed, 45 insertions(+), 29 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 87b87fa58b..a4f4e26ddb 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -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= 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 == diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 29b83f7ade..fb50b72c7c 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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). diff --git a/includes/Setup.php b/includes/Setup.php index 62e7b0a22e..1bc2dba742 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -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; diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 334021a118..dad1ccadcb 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -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 -- 2.20.1