r71117 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71116‎ | r71117 | r71118 >
Date:14:35, 15 August 2010
Author:bawolff
Status:ok
Tags:
Comment:
Make it so that jpeg's that have no metadata still get versioned
properly, and are seprate from jpeg's that caused an error when
extracting metadata.
Modified paths:
  • /branches/img_metadata/phase3/includes/media/Bitmap.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/Jpeg.php (modified) (history)

Diff [purge]

Index: branches/img_metadata/phase3/includes/media/Bitmap.php
@@ -341,8 +341,19 @@
342342 imagejpeg( $dst_image, $thumbPath, 95 );
343343 }
344344
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+ */
346356 function getMetadata( $image, $filename ) {
 357+ wfDeprected( __METHOD__ );
347358 global $wgShowEXIF;
348359 if( $wgShowEXIF && file_exists( $filename ) ) {
349360 $exif = new Exif( $filename );
@@ -362,6 +373,11 @@
363374 return 'exif';
364375 }
365376
 377+ /**
 378+ * In practise this is only used by jpegs...
 379+ *
 380+ * It should perhaps be moved to Jpeg.php.
 381+ */
366382 function isMetadataValid( $image, $metadata ) {
367383 global $wgShowEXIF;
368384 if ( !$wgShowEXIF ) {
@@ -369,7 +385,12 @@
370386 return self::METADATA_GOOD;
371387 }
372388 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' ) {
374395 return self::METADATA_GOOD;
375396 }
376397 wfSuppressWarnings();
@@ -414,7 +435,7 @@
415436
416437 function formatMetadata( $image ) {
417438 $metadata = $image->getMetadata();
418 - if ( !$metadata ) {
 439+ if ( !$metadata || $metadata == '-1' ) {
419440 return false;
420441 }
421442 $exif = unserialize( $metadata );
@@ -422,6 +443,9 @@
423444 return false;
424445 }
425446 unset( $exif['MEDIAWIKI_EXIF_VERSION'] );
 447+ if ( count( $exif ) == 0 ) {
 448+ return false;
 449+ }
426450 return $this->formatMetadataHelper( $exif );
427451 }
428452
Index: branches/img_metadata/phase3/includes/media/Jpeg.php
@@ -13,19 +13,27 @@
1414 function getMetadata ( $image, $filename ) {
1515 try {
1616 $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');
2420 }
 21+ $meta['MEDIAWIKI_EXIF_VERSION'] = Exif::version();
 22+ return serialize( $meta );
2523 }
2624 catch ( MWException $e ) {
2725 // BitmapMetadataHandler throws an exception in certain exceptional cases like if file does not exist.
2826 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';
3038 }
3139 }
3240

Status & tagging log