r81875 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81874‎ | r81875 | r81876 >
Date:06:16, 10 February 2011
Author:yaron
Status:deferred
Tags:
Comment:
Added fixes to have 'default=now' in forms set based on the timezone set for MediaWiki (if any), and other small timezone fixes, based on a patch from John Morton
Modified paths:
  • /trunk/extensions/SemanticForms/includes/SF_FormInputs.php (modified) (history)
  • /trunk/extensions/SemanticForms/includes/SF_FormPrinter.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticForms/includes/SF_FormInputs.php
@@ -746,7 +746,17 @@
747747 $day = $date['day'];
748748 } else {
749749 // handle 'default=now'
750 - if ( $date == 'now' ) $date = date( 'Y/m/d' );
 750+ if ( $date == 'now' ) {
 751+ global $wgLocaltimezone;
 752+ if ( isset( $wgLocaltimezone ) ) {
 753+ $serverTimezone = date_default_timezone_get();
 754+ date_default_timezone_set( $wgLocaltimezone );
 755+ }
 756+ $date = date( 'Y/m/d' );
 757+ if ( isset( $wgLocaltimezone ) ) {
 758+ date_default_timezone_set( $serverTimezone );
 759+ }
 760+ }
751761 $actual_date = new SMWTimeValue( '_dat' );
752762 $actual_date->setUserValue( $date );
753763 $year = $actual_date->getYear();
@@ -805,8 +815,19 @@
806816 } else {
807817 // TODO - this should change to use SMW's own
808818 // date-handling class, just like
809 - // dateEntryHTML() does
810 - $actual_date = strtotime( $datetime );
 819+ // dateEntryHTML() does.
 820+
 821+ // Handle 'default=now'.
 822+ if ( $datetime == 'now' ) {
 823+ global $wgLocaltimezone;
 824+ if ( isset( $wgLocaltimezone ) ) {
 825+ $serverTimezone = date_default_timezone_get();
 826+ date_default_timezone_set( $wgLocaltimezone );
 827+ }
 828+ $actual_date = time();
 829+ } else {
 830+ $actual_date = strtotime( $datetime );
 831+ }
811832 if ( $sfg24HourTime ) {
812833 $hour = date( "G", $actual_date );
813834 } else {
@@ -818,6 +839,12 @@
819840 $ampm24h = date( "A", $actual_date );
820841 }
821842 $timezone = date( "T", $actual_date );
 843+ // Restore back to the server's timezone.
 844+ if ( $datetime == 'now' ) {
 845+ if ( isset( $wgLocaltimezone ) ) {
 846+ date_default_timezone_set( $serverTimezone );
 847+ }
 848+ }
822849 }
823850 } else {
824851 $cur_date = getdate();
@@ -850,7 +877,7 @@
851878
852879 if ( $include_timezone ) {
853880 $sfgTabIndex++;
854 - $text .= ' <input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[timezone]" type="text" value="' . $timezone . '" size="2"/ ' . $disabled_text . '>' . "\n";
 881+ $text .= ' <input tabindex="' . $sfgTabIndex . '" name="' . $input_name . '[timezone]" type="text" value="' . $timezone . '" size="3"/ ' . $disabled_text . '>' . "\n";
855882 }
856883
857884 return $text;
Index: trunk/extensions/SemanticForms/includes/SF_FormPrinter.php
@@ -949,9 +949,12 @@
950950 if ( $input_type == 'date' || $input_type == 'datetime' ||
951951 $input_type == 'datetime with timezone' || $input_type == 'year' ||
952952 ( $input_type == '' && $form_field->template_field->propertyIsOfType( '_dat' ) ) ) {
953 - // get current time, for the time zone specified in the wiki
 953+ // Get current time, for the time zone specified in the wiki.
954954 global $wgLocaltimezone;
955 - putenv( 'TZ=' . $wgLocaltimezone );
 955+ if ( isset( $wgLocaltimezone ) ) {
 956+ $serverTimezone = date_default_timezone_get();
 957+ date_default_timezone_set( $wgLocaltimezone );
 958+ }
956959 $cur_time = time();
957960 $year = date( "Y", $cur_time );
958961 $month = date( "n", $cur_time );
@@ -964,6 +967,9 @@
965968 } else {
966969 $cur_value_in_template = "$year/$month/$day";
967970 }
 971+ if ( isset( $wgLocaltimezone ) ) {
 972+ date_default_timezone_set( $serverTimezone );
 973+ }
968974 if ( $input_type == 'datetime' || $input_type == 'datetime with timezone' ) {
969975 if ( $sfg24HourTime ) {
970976 $hour = str_pad( intval( substr( date( "G", $cur_time ), 0, 2 ) ), 2, '0', STR_PAD_LEFT );