Index: branches/img_metadata/phase3/docs/hooks.txt |
— | — | @@ -824,6 +824,14 @@ |
825 | 825 | $url: string value as output (out parameter, can modify) |
826 | 826 | $query: query options passed to Title::getLocalURL() |
827 | 827 | |
| 828 | +'GetMetadataVersion': modify the image metadata version currently in use. This is |
| 829 | + used when requesting image metadata from a ForiegnApiRepo. Media handlers |
| 830 | + that need to have versioned metadata should add an element to the end of |
| 831 | + the version array of the form 'handler_name=version'. Most media handlers |
| 832 | + won't need to do this unless they broke backwards compatibility with a |
| 833 | + previous version of the media handler metadata output. |
| 834 | +&$version: Array of version strings |
| 835 | + |
828 | 836 | 'GetPreferences': modify user preferences |
829 | 837 | $user: User whose preferences are being modified. |
830 | 838 | &$preferences: Preferences description array, to be fed to an HTMLForm object |
Index: branches/img_metadata/phase3/includes/filerepo/LocalFile.php |
— | — | @@ -302,6 +302,7 @@ |
303 | 303 | * Upgrade a row if it needs it |
304 | 304 | */ |
305 | 305 | function maybeUpgradeRow() { |
| 306 | + global $wgUpdateCompatibleMetadata; |
306 | 307 | if ( wfReadOnly() ) { |
307 | 308 | return; |
308 | 309 | } |
— | — | @@ -312,9 +313,14 @@ |
313 | 314 | $this->upgraded = true; |
314 | 315 | } else { |
315 | 316 | $handler = $this->getHandler(); |
316 | | - if ( $handler && !$handler->isMetadataValid( $this, $this->metadata ) ) { |
317 | | - $this->upgradeRow(); |
318 | | - $this->upgraded = true; |
| 317 | + if ( $handler ) { |
| 318 | + $validity = $handler->isMetadataValid( $this, $this->metadata ); |
| 319 | + if ( $validity === MediaHandler::METADATA_BAD |
| 320 | + || ( $validity === MediaHandler::METADATA_COMPATIBLE && $wgUpdateCompatibleMetadata ) |
| 321 | + ) { |
| 322 | + $this->upgradeRow(); |
| 323 | + $this->upgraded = true; |
| 324 | + } |
319 | 325 | } |
320 | 326 | } |
321 | 327 | } |
Index: branches/img_metadata/phase3/includes/filerepo/ForeignAPIFile.php |
— | — | @@ -21,12 +21,8 @@ |
22 | 22 | 'titles' => 'File:' . $title->getText(), |
23 | 23 | 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime', |
24 | 24 | 'prop' => 'imageinfo', |
25 | | - 'iimetadataversion' => Exif::version() |
| 25 | + 'iimetadataversion' => mediaHandler::getMetadataVersion() |
26 | 26 | ) ); |
27 | | - // Note to self/fixme: Using Exif::version() here is obviously not good, as |
28 | | - // metadata is handler specific. Original plan was to use handler->getMetadataVersion() |
29 | | - // but that doesn't work, because we don't know mime type yet, thus don't know handler yet. |
30 | | - // need to think of a better way of doing this. |
31 | 27 | |
32 | 28 | $info = $repo->getImageInfo( $data ); |
33 | 29 | |
Index: branches/img_metadata/phase3/includes/api/ApiQueryImageInfo.php |
— | — | @@ -191,7 +191,7 @@ |
192 | 192 | * @param $scale Array containing 'width' and 'height' items, or null |
193 | 193 | * @return Array: result array |
194 | 194 | */ |
195 | | - static function getInfo( $file, $prop, $result, $scale = null, $version = 0 ) { |
| 195 | + static function getInfo( $file, $prop, $result, $scale = null, $version = 'latest' ) { |
196 | 196 | $vals = array(); |
197 | 197 | if ( isset( $prop['timestamp'] ) ) { |
198 | 198 | $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() ); |
— | — | @@ -240,7 +240,7 @@ |
241 | 241 | } |
242 | 242 | if ( isset( $prop['metadata'] ) ) { |
243 | 243 | $metadata = unserialize( $file->getMetadata() ); |
244 | | - if ( $version !== 0 ) { |
| 244 | + if ( $version !== 'latest' ) { |
245 | 245 | $metadata = $file->convertMetadataVersion( $metadata, $version ); |
246 | 246 | } |
247 | 247 | $vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null; |
— | — | @@ -311,9 +311,8 @@ |
312 | 312 | ApiBase::PARAM_DFLT => - 1 |
313 | 313 | ), |
314 | 314 | 'metadataversion' => array( |
315 | | - ApiBase::PARAM_TYPE => 'integer', |
316 | | - ApiBase::PARAM_DFLT => 1, |
317 | | - ApiBase::PARAM_MIN => 0, |
| 315 | + ApiBase::PARAM_TYPE => 'string', |
| 316 | + ApiBase::PARAM_DFLT => '1', |
318 | 317 | ), |
319 | 318 | 'continue' => null, |
320 | 319 | ); |
— | — | @@ -349,7 +348,7 @@ |
350 | 349 | 'urlwidth' => array( "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.", |
351 | 350 | 'Only the current version of the image can be scaled' ), |
352 | 351 | 'urlheight' => "Similar to {$p}urlwidth. Cannot be used without {$p}urlwidth", |
353 | | - 'metadataversion' => array( "Version of metadata to use. if 0 is specified, use latest version.", |
| 352 | + 'metadataversion' => array( "Version of metadata to use. if 'latest' is specified, use latest version.", |
354 | 353 | "Defaults to '1' for bacwards compatability" ), |
355 | 354 | 'continue' => 'When more results are available, use this to continue', |
356 | 355 | ); |
Index: branches/img_metadata/phase3/includes/media/Bitmap.php |
— | — | @@ -366,11 +366,11 @@ |
367 | 367 | global $wgShowEXIF; |
368 | 368 | if ( !$wgShowEXIF ) { |
369 | 369 | # Metadata disabled and so an empty field is expected |
370 | | - return true; |
| 370 | + return self::METADATA_GOOD; |
371 | 371 | } |
372 | 372 | if ( $metadata === '0' ) { |
373 | 373 | # Special value indicating that there is no EXIF data in the file |
374 | | - return true; |
| 374 | + return self::METADATA_GOOD; |
375 | 375 | } |
376 | 376 | wfSuppressWarnings(); |
377 | 377 | $exif = unserialize( $metadata ); |
— | — | @@ -378,11 +378,18 @@ |
379 | 379 | if ( !isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) || |
380 | 380 | $exif['MEDIAWIKI_EXIF_VERSION'] != Exif::version() ) |
381 | 381 | { |
382 | | - # Wrong version |
| 382 | + if ( isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) && |
| 383 | + $exif['MEDIAWIKI_EXIF_VERSION'] == 1 ) |
| 384 | + { |
| 385 | + //back-compatible but old |
| 386 | + wfDebug( __METHOD__.": back-compat version\n" ); |
| 387 | + return self::METADATA_COMPATIBLE; |
| 388 | + } |
| 389 | + # Wrong (non-compatible) version |
383 | 390 | wfDebug( __METHOD__.": wrong version\n" ); |
384 | | - return false; |
| 391 | + return self::METADATA_BAD; |
385 | 392 | } |
386 | | - return true; |
| 393 | + return self::METADATA_GOOD; |
387 | 394 | } |
388 | 395 | |
389 | 396 | /** |
Index: branches/img_metadata/phase3/includes/media/Generic.php |
— | — | @@ -12,7 +12,9 @@ |
13 | 13 | */ |
14 | 14 | abstract class MediaHandler { |
15 | 15 | const TRANSFORM_LATER = 1; |
16 | | - |
| 16 | + const METADATA_GOOD = true; |
| 17 | + const METADATA_BAD = false; |
| 18 | + const METADATA_COMPATIBLE = 2; // for old but backwards compatible. |
17 | 19 | /** |
18 | 20 | * Instance cache |
19 | 21 | */ |
— | — | @@ -88,10 +90,24 @@ |
89 | 91 | |
90 | 92 | /** |
91 | 93 | * Get metadata version. |
92 | | - * @return integer version |
93 | | - * @todo Originally this was going to be used by ForeignAPIFile, but currently does nothing. |
| 94 | + * |
| 95 | + * This is not used for validating metadata, this is used for the api when returning |
| 96 | + * metadata, since api content formats should stay the same over time, and so things |
| 97 | + * using ForiegnApiRepo can keep backwards compatibility |
| 98 | + * |
| 99 | + * All core media handlers share a common version number, and extensions can |
| 100 | + * use the GetMetadataVersion hook to append to the array (they should append a unique |
| 101 | + * string so not to get confusing). If there was a media handler named 'foo' with metadata |
| 102 | + * version 3 it might add to the end of the array the element 'foo=3'. if the core metadata |
| 103 | + * version is 2, the end version string would look like '2;foo=3'. |
| 104 | + * |
| 105 | + * @return string version string |
94 | 106 | */ |
95 | | - function getMetadataVersion () { return 1; } |
| 107 | + static function getMetadataVersion () { |
| 108 | + $version = Array( '2' ); // core metadata version |
| 109 | + wfRunHooks('GetMetadataVersion', Array(&$version)); |
| 110 | + return implode( ';', $version); |
| 111 | + } |
96 | 112 | |
97 | 113 | /** |
98 | 114 | * Convert metadata version. |
— | — | @@ -120,9 +136,15 @@ |
121 | 137 | |
122 | 138 | /** |
123 | 139 | * Check if the metadata string is valid for this handler. |
124 | | - * If it returns false, Image will reload the metadata from the file and update the database |
| 140 | + * If it returns MediaHandler::METADATA_BAD (or false), Image |
| 141 | + * will reload the metadata from the file and update the database. |
| 142 | + * MediaHandler::METADATA_GOOD for if the metadata is a-ok, |
| 143 | + * MediaHanlder::METADATA_COMPATIBLE if metadata is old but backwards |
| 144 | + * compatible (which may or may not trigger a metadata reload). |
125 | 145 | */ |
126 | | - function isMetadataValid( $image, $metadata ) { return true; } |
| 146 | + function isMetadataValid( $image, $metadata ) { |
| 147 | + return self::METADATA_GOOD; |
| 148 | + } |
127 | 149 | |
128 | 150 | |
129 | 151 | /** |
Index: branches/img_metadata/phase3/includes/media/Jpeg.php |
— | — | @@ -30,7 +30,9 @@ |
31 | 31 | |
32 | 32 | function convertMetadataVersion( $metadata, $version = 1 ) { |
33 | 33 | // basically flattens arrays. |
34 | | - if ( $version != 1 ) { |
| 34 | + $version = explode(';', $version, 2); |
| 35 | + $version = intval($version[0]); |
| 36 | + if ( $version < 1 || $version >= 2 ) { |
35 | 37 | return $metadata; |
36 | 38 | } |
37 | 39 | |
— | — | @@ -46,8 +48,7 @@ |
47 | 49 | $val = formatExif::flattenArray( $val ); |
48 | 50 | } |
49 | 51 | } |
50 | | - $metadata['MEDIAWIKI_EXIF_VERSION'] = $version; |
| 52 | + $metadata['MEDIAWIKI_EXIF_VERSION'] = 1; |
51 | 53 | return $metadata; |
52 | 54 | } |
53 | | - function getMetadataVersion () { return Exif::version(); } |
54 | 55 | } |
Index: branches/img_metadata/phase3/includes/DefaultSettings.php |
— | — | @@ -389,6 +389,13 @@ |
390 | 390 | $wgShowEXIF = function_exists( 'exif_read_data' ); |
391 | 391 | |
392 | 392 | /** |
| 393 | + * If to automatically update the img_metadata field |
| 394 | + * if the metadata field is outdated but compatible with the current version. |
| 395 | + * Defaults to false. |
| 396 | + */ |
| 397 | +$wgUpdateCompatibleMetadata = false; |
| 398 | + |
| 399 | +/** |
393 | 400 | * Set to true to enable the upload _link_ while local uploads are disabled. |
394 | 401 | * Assumes that the special page link will be bounced to another server where |
395 | 402 | * uploads do work. |