From: Bryan Tong Minh Date: Sun, 19 Jun 2011 21:38:58 +0000 (+0000) Subject: (bug 29471) Exception thrown for files with invalid date in metadata X-Git-Tag: 1.31.0-rc.0~29409 X-Git-Url: http://git.cyclocoop.org/ecrire?a=commitdiff_plain;h=f66a1c1bb99c09c175135065c98869b8a6adef41;p=lhc%2Fweb%2Fwiklou.git (bug 29471) Exception thrown for files with invalid date in metadata MediaWiki doesn't handle BC dates nicely, so check for that. --- diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 935f5fe5f3..a66aed07ef 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -107,6 +107,7 @@ production. * Do not try to group together a page creation and edit in the RSS feed of RC. * (bug 29342) Patrol preferences shouldn't be visible to users who don't have patrol permissions +* (bug 29471) Exception thrown for files with invalid date in metadata === API changes in 1.19 === * BREAKING CHANGE: action=watch now requires POST and token. diff --git a/includes/media/FormatMetadata.php b/includes/media/FormatMetadata.php index e830901623..47fc1adc2d 100644 --- a/includes/media/FormatMetadata.php +++ b/includes/media/FormatMetadata.php @@ -104,7 +104,7 @@ class FormatMetadata { $time = wfTimestamp( TS_MW, '1971:01:01 ' . $tags[$tag] ); // the 1971:01:01 is just a placeholder, and not shown to user. - if ( $time ) { + if ( $time && intval( $time ) > 0 ) { $tags[$tag] = $wgLang->time( $time ); } continue; @@ -234,7 +234,7 @@ class FormatMetadata { $val = wfMsg( 'exif-unknowndate' ); } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d) (?:\d\d):(?:\d\d):(?:\d\d)$/D', $val ) ) { $time = wfTimestamp( TS_MW, $val ); - if ( $time ) { + if ( $time && intval( $time ) > 0 ) { $val = $wgLang->timeanddate( $time ); } } elseif ( preg_match( '/^(?:\d{4}):(?:\d\d):(?:\d\d)$/D', $val ) ) { @@ -243,7 +243,7 @@ class FormatMetadata { . substr( $val, 5, 2 ) . substr( $val, 8, 2 ) . '000000' ); - if ( $time ) { + if ( $time && intval( $time ) > 0 ) { $val = $wgLang->date( $time ); } } diff --git a/tests/phpunit/includes/media/FormatMetadataTest.php b/tests/phpunit/includes/media/FormatMetadataTest.php new file mode 100644 index 0000000000..98c8013e9b --- /dev/null +++ b/tests/phpunit/includes/media/FormatMetadataTest.php @@ -0,0 +1,23 @@ +formatMetadata(); + + // Find date exif entry + $this->assertArrayHasKey( 'visible', $meta ); + $dateIndex = null; + foreach ( $meta['visible'] as $i => $data ) { + if ( $data['id'] == 'exif-datetimeoriginal' ) { + $dateIndex = $i; + } + } + $this->assertNotNull( $dateIndex, 'Date entry exists in metadata' ); + $this->assertEquals( '0000:01:00 00:02:27', + $meta['visible'][$dateIndex]['value'], + 'File with invalid date metadata (bug 29471)' ); + } +} \ No newline at end of file diff --git a/tests/phpunit/includes/media/broken_exif_date.jpg b/tests/phpunit/includes/media/broken_exif_date.jpg new file mode 100644 index 0000000000..82f62f5704 Binary files /dev/null and b/tests/phpunit/includes/media/broken_exif_date.jpg differ