Index: branches/img_metadata/phase3/includes/media/Bitmap.php |
— | — | @@ -341,8 +341,19 @@ |
342 | 342 | imagejpeg( $dst_image, $thumbPath, 95 ); |
343 | 343 | } |
344 | 344 | |
345 | | - |
| 345 | + /** |
| 346 | + * Its unclear if anything still uses this |
| 347 | + * as jpeg is now in its own subclass. |
| 348 | + * |
| 349 | + * And really each media handler should use a |
| 350 | + * different getMetadata, as the formats aren't |
| 351 | + * all that similar and usually have different |
| 352 | + * metadata needs. |
| 353 | + * |
| 354 | + * @deprected |
| 355 | + */ |
346 | 356 | function getMetadata( $image, $filename ) { |
| 357 | + wfDeprected( __METHOD__ ); |
347 | 358 | global $wgShowEXIF; |
348 | 359 | if( $wgShowEXIF && file_exists( $filename ) ) { |
349 | 360 | $exif = new Exif( $filename ); |
— | — | @@ -362,6 +373,11 @@ |
363 | 374 | return 'exif'; |
364 | 375 | } |
365 | 376 | |
| 377 | + /** |
| 378 | + * In practise this is only used by jpegs... |
| 379 | + * |
| 380 | + * It should perhaps be moved to Jpeg.php. |
| 381 | + */ |
366 | 382 | function isMetadataValid( $image, $metadata ) { |
367 | 383 | global $wgShowEXIF; |
368 | 384 | if ( !$wgShowEXIF ) { |
— | — | @@ -369,7 +385,12 @@ |
370 | 386 | return self::METADATA_GOOD; |
371 | 387 | } |
372 | 388 | if ( $metadata === '0' ) { |
373 | | - # Special value indicating that there is no EXIF data in the file |
| 389 | + # Old special value indicating that there is no EXIF data in the file. |
| 390 | + # or that there was an error well extracting the metadata. |
| 391 | + wfDebug( __METHOD__ . ": back-compat version\n"); |
| 392 | + return self::METADATA_COMPATIBLE; |
| 393 | + } |
| 394 | + if ( $metadata === '-1' ) { |
374 | 395 | return self::METADATA_GOOD; |
375 | 396 | } |
376 | 397 | wfSuppressWarnings(); |
— | — | @@ -414,7 +435,7 @@ |
415 | 436 | |
416 | 437 | function formatMetadata( $image ) { |
417 | 438 | $metadata = $image->getMetadata(); |
418 | | - if ( !$metadata ) { |
| 439 | + if ( !$metadata || $metadata == '-1' ) { |
419 | 440 | return false; |
420 | 441 | } |
421 | 442 | $exif = unserialize( $metadata ); |
— | — | @@ -422,6 +443,9 @@ |
423 | 444 | return false; |
424 | 445 | } |
425 | 446 | unset( $exif['MEDIAWIKI_EXIF_VERSION'] ); |
| 447 | + if ( count( $exif ) == 0 ) { |
| 448 | + return false; |
| 449 | + } |
426 | 450 | return $this->formatMetadataHelper( $exif ); |
427 | 451 | } |
428 | 452 | |
Index: branches/img_metadata/phase3/includes/media/Jpeg.php |
— | — | @@ -13,19 +13,27 @@ |
14 | 14 | function getMetadata ( $image, $filename ) { |
15 | 15 | try { |
16 | 16 | $meta = BitmapMetadataHandler::Jpeg( $filename ); |
17 | | - if ( $meta ) { |
18 | | - $meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version(); |
19 | | - return serialize( $meta ); |
20 | | - } else { |
21 | | - /* FIXME, this should probably be something else to do versioning |
22 | | - with older files that say have no exif, but have xmp */ |
23 | | - return '0'; |
| 17 | + if ( !is_array( $meta ) ) { |
| 18 | + // This should never happen, but doesn't hurt to be paranoid. |
| 19 | + throw new MWException('Metadata array is not an array'); |
24 | 20 | } |
| 21 | + $meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version(); |
| 22 | + return serialize( $meta ); |
25 | 23 | } |
26 | 24 | catch ( MWException $e ) { |
27 | 25 | // BitmapMetadataHandler throws an exception in certain exceptional cases like if file does not exist. |
28 | 26 | wfDebug( __METHOD__ . ': ' . $e->getMessage() . "\n" ); |
29 | | - return '0'; |
| 27 | + |
| 28 | + /* This used to use 0 for the cases |
| 29 | + * * No metadata in the file |
| 30 | + * * Something is broken in the file. |
| 31 | + * However, if the metadata support gets expanded then you can't tell if the 0 is from |
| 32 | + * a broken file, or just no props found. A broken file is likely to stay broken, but |
| 33 | + * a file which had no props could have props once the metadata support is improved. |
| 34 | + * Thus switch to using -1 to denote only a broken file, and use an array with only |
| 35 | + * MEDIAWIKI_EXIF_VERSION to denote no props. |
| 36 | + */ |
| 37 | + return '-1'; |
30 | 38 | } |
31 | 39 | } |
32 | 40 | |