r60825 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60824‎ | r60825 | r60826 >
Date:01:48, 8 January 2010
Author:tstarling
Status:ok
Tags:
Comment:
* 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.
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/DefaultSettings.php (modified) (history)
  • /trunk/phase3/includes/Setup.php (modified) (history)
  • /trunk/phase3/includes/parser/Parser.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Setup.php
@@ -140,7 +140,6 @@
141141 );
142142 }
143143
144 -
145144 if ( !class_exists( 'AutoLoader' ) ) {
146145 require_once( "$IP/includes/AutoLoader.php" );
147146 }
@@ -160,9 +159,19 @@
161160 require_once( "$IP/includes/StubObject.php" );
162161 wfProfileOut( $fname.'-includes' );
163162 wfProfileIn( $fname.'-misc1' );
 163+
164164 # Raise the memory limit if it's too low
165165 wfMemoryLimit();
166166
 167+/**
 168+ * Set up the timezone, suppressing the pseudo-security warning in PHP 5.1+
 169+ * that happens whenever you use a date function without the timezone being
 170+ * explicitly set. Inspired by phpMyAdmin's treatment of the problem.
 171+ */
 172+wfSuppressWarnings();
 173+date_default_timezone_set( date_default_timezone_get() );
 174+wfRestoreWarnings();
 175+
167176 $wgIP = false; # Load on demand
168177 # Can't stub this one, it sets up $_GET and $_REQUEST in its constructor
169178 $wgRequest = new WebRequest;
Index: trunk/phase3/includes/DefaultSettings.php
@@ -3080,10 +3080,10 @@
30813081 /**
30823082 * Fake out the timezone that the server thinks it's in. This will be used for
30833083 * date display and not for what's stored in the DB. Leave to null to retain
3084 - * your server's OS-based timezone value. This is the same as the timezone.
 3084+ * your server's OS-based timezone value.
30853085 *
3086 - * This variable is currently used ONLY for signature formatting, not for
3087 - * anything else.
 3086+ * This variable is currently used only for signature formatting and for local
 3087+ * time/date parser variables ({{LOCALTIME}} etc.)
30883088 *
30893089 * Timezones can be translated by editing MediaWiki messages of type
30903090 * timezone-nameinlowercase like timezone-utc.
@@ -3105,10 +3105,10 @@
31063106 * $wgLocalTZoffset = date("Z") / 60;
31073107 *
31083108 * If your server is not configured for the timezone you want, you can set
3109 - * this in conjunction with the signature timezone and override the TZ
3110 - * environment variable like so:
 3109+ * this in conjunction with the signature timezone and override the PHP default
 3110+ * timezone like so:
31113111 * $wgLocaltimezone="Europe/Berlin";
3112 - * putenv("TZ=$wgLocaltimezone");
 3112+ * date_default_timezone_set( $wgLocaltimezone );
31133113 * $wgLocalTZoffset = date("Z") / 60;
31143114 *
31153115 * Leave at NULL to show times in universal time (UTC/GMT).
Index: trunk/phase3/includes/parser/Parser.php
@@ -2332,11 +2332,10 @@
23332333 # Use the time zone
23342334 global $wgLocaltimezone;
23352335 if ( isset( $wgLocaltimezone ) ) {
2336 - $oldtz = getenv( 'TZ' );
2337 - putenv( 'TZ='.$wgLocaltimezone );
 2336+ $oldtz = date_default_timezone_get();
 2337+ date_default_timezone_set( $wgLocaltimezone );
23382338 }
23392339
2340 - wfSuppressWarnings(); // E_STRICT system time bitching
23412340 $localTimestamp = date( 'YmdHis', $ts );
23422341 $localMonth = date( 'm', $ts );
23432342 $localMonth1 = date( 'n', $ts );
@@ -2348,9 +2347,8 @@
23492348 $localYear = date( 'Y', $ts );
23502349 $localHour = date( 'H', $ts );
23512350 if ( isset( $wgLocaltimezone ) ) {
2352 - putenv( 'TZ='.$oldtz );
 2351+ date_default_timezone_set( $oldtz );
23532352 }
2354 - wfRestoreWarnings();
23552353
23562354 switch ( $index ) {
23572355 case 'currentmonth':
@@ -3965,27 +3963,30 @@
39663964 * (see also bug 12815)
39673965 */
39683966 $ts = $this->mOptions->getTimestamp();
3969 - $tz = wfMsgForContent( 'timezone-utc' );
39703967 if ( isset( $wgLocaltimezone ) ) {
3971 - $unixts = wfTimestamp( TS_UNIX, $ts );
3972 - $oldtz = getenv( 'TZ' );
3973 - putenv( 'TZ='.$wgLocaltimezone );
3974 - $ts = date( 'YmdHis', $unixts );
3975 - $tz = date( 'T', $unixts ); # might vary on DST changeover!
 3968+ $tz = $wgLocaltimezone;
 3969+ } else {
 3970+ $tz = date_default_timezone_get();
 3971+ }
39763972
3977 - /* Allow translation of timezones trough wiki. date() can return
3978 - * whatever crap the system uses, localised or not, so we cannot
3979 - * ship premade translations.
3980 - */
3981 - $key = 'timezone-' . strtolower( trim( $tz ) );
3982 - $value = wfMsgForContent( $key );
3983 - if ( !wfEmptyMsg( $key, $value ) ) $tz = $value;
 3973+ $unixts = wfTimestamp( TS_UNIX, $ts );
 3974+ $oldtz = date_default_timezone_get();
 3975+ date_default_timezone_set( $tz );
 3976+ $ts = date( 'YmdHis', $unixts );
 3977+ $tzMsg = date( 'T', $unixts ); # might vary on DST changeover!
39843978
3985 - putenv( 'TZ='.$oldtz );
3986 - }
 3979+ /* Allow translation of timezones trough wiki. date() can return
 3980+ * whatever crap the system uses, localised or not, so we cannot
 3981+ * ship premade translations.
 3982+ */
 3983+ $key = 'timezone-' . strtolower( trim( $tzMsg ) );
 3984+ $value = wfMsgForContent( $key );
 3985+ if ( !wfEmptyMsg( $key, $value ) ) $tzMsg = $value;
39873986
3988 - $d = $wgContLang->timeanddate( $ts, false, false ) . " ($tz)";
 3987+ date_default_timezone_set( $oldtz );
39893988
 3989+ $d = $wgContLang->timeanddate( $ts, false, false ) . " ($tzMsg)";
 3990+
39903991 # Variable replacement
39913992 # Because mOutputType is OT_WIKI, this will only process {{subst:xxx}} type tags
39923993 $text = $this->replaceVariables( $text );
Index: trunk/phase3/RELEASE-NOTES
@@ -84,7 +84,12 @@
8585 * $wgUploadNavigationUrl now also affects images inline images that do not
8686 exist. In that case the URL will get (?|&)wpDestFile=<filename> appended to
8787 it as appropriate.
88 -
 88+* If $wgLocaltimezone is null, use the server's timezone as the default for
 89+ signatures. This was always the behaviour documented in DefaultSettings.php
 90+ but has not been the actual behaviour for some time: instead, UTC was used
 91+ by default.
 92+
 93+
8994 === New features in 1.16 ===
9095
9196 * Add CSS defintion of the 'wikitable' class to shared.css
@@ -683,6 +688,7 @@
684689 type selector on Special:Log
685690 * (bug 20115) Special:Userlogin title says "Log in / create account" even if the
686691 user can't create an account
 692+* (bug 2658) Don't attempt to set the TZ environment variable.
687693
688694 == API changes in 1.16 ==
689695

Follow-up revisions

RevisionCommit summaryAuthorDate
r60826When $wgLocaltimezone is null, make #timel match the behaviour of {{LOCALTIME...tstarling01:51, 8 January 2010
r98425Swap ParserFuncs to use the timezone funcs (like r60825) rather than putenv()...demon18:20, 29 September 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r58559Fixed some Oracle-specific installer and Strict Standards issuesfreakolowsky19:09, 4 November 2009

Status & tagging log