r78884 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78883‎ | r78884 | r78885 >
Date:12:31, 23 December 2010
Author:bawolff
Status:deferred
Tags:
Comment:
Fix some issues with timestamp handling.
Modified paths:
  • /branches/img_metadata/phase3/includes/media/FormatMetadata.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/IPTC.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/XMPValidate.php (modified) (history)

Diff [purge]

Index: branches/img_metadata/phase3/includes/media/FormatMetadata.php
@@ -99,8 +99,14 @@
100100 continue;
101101 }
102102 $tags[$tag] = intval( $h[0] / $h[1] )
103 - . ':' . intval( $m[0] / $m[1] )
 103+ . ':' . str_pad( intval( $m[0] / $m[1] ), 2, '0', STR_PAD_LEFT )
104104 . ':' . str_pad( intval( $s[0] / $s[1] ), 2, '0', STR_PAD_LEFT );
 105+
 106+ $time = wfTimestamp( TS_MW, '1971:01:01 ' . $tags[$tag] );
 107+ // the 1971:01:01 is just a placeholder, and not shown to user.
 108+ if ( $time ) {
 109+ $tags[$tag] = $wgLang->time( $time );
 110+ }
105111 continue;
106112 }
107113
@@ -224,18 +230,20 @@
225231 case 'DateTimeMetadata':
226232 if ( $val == '0000:00:00 00:00:00' || $val == ' : : : : ' ) {
227233 $val = wfMsg( 'exif-unknowndate' );
228 - } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d):(?:\d\d)$/', $val ) ) {
229 - $val = $wgLang->timeanddate( wfTimestamp( TS_MW, $val ) );
230 - } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d)$/', $val ) ) {
231 - // avoid using wfTimestamp here for the pre-1902 photos
232 - // due to reverse y2k38 bug. $wgLang->timeanddate() is also
233 - // broken on dates from before 1902 so don't worry about it
234 - // in the above case (not to mention that most photos from the
235 - // 1800's don't have a time recorded anyways).
236 - $val = $wgLang->date( substr( $val, 0, 4 )
 234+ } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d):(?:\d\d)$/D', $val ) ) {
 235+ $time = wfTimestamp( TS_MW, $val );
 236+ if ( $time ) {
 237+ $val = $wgLang->timeanddate( $time );
 238+ }
 239+ } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d)$/D', $val ) ) {
 240+ // If only the date but not the time is filled in.
 241+ $time = wfTimestamp( TS_MW, substr( $val, 0, 4 )
237242 . substr( $val, 5, 2 )
238243 . substr( $val, 8, 2 )
239244 . '000000' );
 245+ if ( $time ) {
 246+ $val = $wgLang->date( $time );
 247+ }
240248 }
241249 // else it will just output $val without formatting it.
242250 break;
Index: branches/img_metadata/phase3/includes/media/IPTC.php
@@ -371,15 +371,12 @@
372372 return null;
373373 }
374374
375 - if ( substr($date, 0, 4) < "1902" ) {
376 - // We run into the reverse y2k38 bug.
377 - // Avoid using wfTimestamp as it doesn't work for pre-1902 dates
378 - return substr( $date, 0, 4 ) . ':'
379 - . substr( $date, 4, 2 ) . ':'
380 - . substr( $date, 6, 2 );
 375+ $unixTS = wfTimestamp( TS_UNIX, $date . substr( $time, 0, 6 ));
 376+ if ( $unixTS === false ) {
 377+ wfDebugLog( 'iptc', "IPTC: can't convert date to TS_UNIX: $date $time." );
 378+ return null;
381379 }
382 -
383 - $unixTS = wfTimestamp( TS_UNIX, $date . substr( $time, 0, 6 ));
 380+
384381 $tz = ( intval( substr( $time, 7, 2 ) ) *60*60 )
385382 + ( intval( substr( $time, 9, 2 ) ) * 60 );
386383
@@ -388,6 +385,10 @@
389386 }
390387
391388 $finalTimestamp = wfTimestamp( TS_EXIF, $unixTS + $tz );
 389+ if ( $finalTimestamp === false ) {
 390+ wfDebugLog( 'iptc', "IPTC: can't make final timestamp. Date: " . ( $unixTS + $tz ) );
 391+ return null;
 392+ }
392393 if ( $dateOnly ) {
393394 //return the date only
394395 return substr( $finalTimestamp, 0, 10 );
Index: branches/img_metadata/phase3/includes/media/XMPValidate.php
@@ -234,9 +234,7 @@
235235 //Extra check for empty string necessary due to TZ but no second case.
236236 $res[6] = isset( $res[6] ) && $res[6] != '' ? $res[6] : '00';
237237
238 - if ( !isset( $res[7] ) || $res[7] === 'Z' || $res[1] >= '2038' || $res[1] < '1902' ) {
239 - // timezone processing has y2k38 problem so pretend not set if
240 - // before 1902 or after 2037.
 238+ if ( !isset( $res[7] ) || $res[7] === 'Z' ) {
241239 $val = $res[1] . ':' . $res[2] . ':' . $res[3]
242240 . ' ' . $res[4] . ':' . $res[5] . ':' . $res[6];
243241 return;

Status & tagging log