r69021 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r69020‎ | r69021 | r69022 >
Date:21:31, 4 July 2010
Author:bawolff
Status:ok
Tags:
Comment:
Stuff related to being backwards compatible
Modified paths:
  • /branches/img_metadata/phase3/docs/hooks.txt (modified) (history)
  • /branches/img_metadata/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/img_metadata/phase3/includes/api/ApiQueryImageInfo.php (modified) (history)
  • /branches/img_metadata/phase3/includes/filerepo/ForeignAPIFile.php (modified) (history)
  • /branches/img_metadata/phase3/includes/filerepo/LocalFile.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/Bitmap.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/Generic.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/Jpeg.php (modified) (history)

Diff [purge]

Index: branches/img_metadata/phase3/docs/hooks.txt
@@ -824,6 +824,14 @@
825825 $url: string value as output (out parameter, can modify)
826826 $query: query options passed to Title::getLocalURL()
827827
 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+
828836 'GetPreferences': modify user preferences
829837 $user: User whose preferences are being modified.
830838 &$preferences: Preferences description array, to be fed to an HTMLForm object
Index: branches/img_metadata/phase3/includes/filerepo/LocalFile.php
@@ -302,6 +302,7 @@
303303 * Upgrade a row if it needs it
304304 */
305305 function maybeUpgradeRow() {
 306+ global $wgUpdateCompatibleMetadata;
306307 if ( wfReadOnly() ) {
307308 return;
308309 }
@@ -312,9 +313,14 @@
313314 $this->upgraded = true;
314315 } else {
315316 $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+ }
319325 }
320326 }
321327 }
Index: branches/img_metadata/phase3/includes/filerepo/ForeignAPIFile.php
@@ -21,12 +21,8 @@
2222 'titles' => 'File:' . $title->getText(),
2323 'iiprop' => 'timestamp|user|comment|url|size|sha1|metadata|mime',
2424 'prop' => 'imageinfo',
25 - 'iimetadataversion' => Exif::version()
 25+ 'iimetadataversion' => mediaHandler::getMetadataVersion()
2626 ) );
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.
3127
3228 $info = $repo->getImageInfo( $data );
3329
Index: branches/img_metadata/phase3/includes/api/ApiQueryImageInfo.php
@@ -191,7 +191,7 @@
192192 * @param $scale Array containing 'width' and 'height' items, or null
193193 * @return Array: result array
194194 */
195 - static function getInfo( $file, $prop, $result, $scale = null, $version = 0 ) {
 195+ static function getInfo( $file, $prop, $result, $scale = null, $version = 'latest' ) {
196196 $vals = array();
197197 if ( isset( $prop['timestamp'] ) ) {
198198 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $file->getTimestamp() );
@@ -240,7 +240,7 @@
241241 }
242242 if ( isset( $prop['metadata'] ) ) {
243243 $metadata = unserialize( $file->getMetadata() );
244 - if ( $version !== 0 ) {
 244+ if ( $version !== 'latest' ) {
245245 $metadata = $file->convertMetadataVersion( $metadata, $version );
246246 }
247247 $vals['metadata'] = $metadata ? self::processMetaData( $metadata, $result ) : null;
@@ -311,9 +311,8 @@
312312 ApiBase::PARAM_DFLT => - 1
313313 ),
314314 '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',
318317 ),
319318 'continue' => null,
320319 );
@@ -349,7 +348,7 @@
350349 'urlwidth' => array( "If {$p}prop=url is set, a URL to an image scaled to this width will be returned.",
351350 'Only the current version of the image can be scaled' ),
352351 '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.",
354353 "Defaults to '1' for bacwards compatability" ),
355354 'continue' => 'When more results are available, use this to continue',
356355 );
Index: branches/img_metadata/phase3/includes/media/Bitmap.php
@@ -366,11 +366,11 @@
367367 global $wgShowEXIF;
368368 if ( !$wgShowEXIF ) {
369369 # Metadata disabled and so an empty field is expected
370 - return true;
 370+ return self::METADATA_GOOD;
371371 }
372372 if ( $metadata === '0' ) {
373373 # Special value indicating that there is no EXIF data in the file
374 - return true;
 374+ return self::METADATA_GOOD;
375375 }
376376 wfSuppressWarnings();
377377 $exif = unserialize( $metadata );
@@ -378,11 +378,18 @@
379379 if ( !isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) ||
380380 $exif['MEDIAWIKI_EXIF_VERSION'] != Exif::version() )
381381 {
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
383390 wfDebug( __METHOD__.": wrong version\n" );
384 - return false;
 391+ return self::METADATA_BAD;
385392 }
386 - return true;
 393+ return self::METADATA_GOOD;
387394 }
388395
389396 /**
Index: branches/img_metadata/phase3/includes/media/Generic.php
@@ -12,7 +12,9 @@
1313 */
1414 abstract class MediaHandler {
1515 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.
1719 /**
1820 * Instance cache
1921 */
@@ -88,10 +90,24 @@
8991
9092 /**
9193 * 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
94106 */
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+ }
96112
97113 /**
98114 * Convert metadata version.
@@ -120,9 +136,15 @@
121137
122138 /**
123139 * 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).
125145 */
126 - function isMetadataValid( $image, $metadata ) { return true; }
 146+ function isMetadataValid( $image, $metadata ) {
 147+ return self::METADATA_GOOD;
 148+ }
127149
128150
129151 /**
Index: branches/img_metadata/phase3/includes/media/Jpeg.php
@@ -30,7 +30,9 @@
3131
3232 function convertMetadataVersion( $metadata, $version = 1 ) {
3333 // basically flattens arrays.
34 - if ( $version != 1 ) {
 34+ $version = explode(';', $version, 2);
 35+ $version = intval($version[0]);
 36+ if ( $version < 1 || $version >= 2 ) {
3537 return $metadata;
3638 }
3739
@@ -46,8 +48,7 @@
4749 $val = formatExif::flattenArray( $val );
4850 }
4951 }
50 - $metadata['MEDIAWIKI_EXIF_VERSION'] = $version;
 52+ $metadata['MEDIAWIKI_EXIF_VERSION'] = 1;
5153 return $metadata;
5254 }
53 - function getMetadataVersion () { return Exif::version(); }
5455 }
Index: branches/img_metadata/phase3/includes/DefaultSettings.php
@@ -389,6 +389,13 @@
390390 $wgShowEXIF = function_exists( 'exif_read_data' );
391391
392392 /**
 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+/**
393400 * Set to true to enable the upload _link_ while local uploads are disabled.
394401 * Assumes that the special page link will be bounced to another server where
395402 * uploads do work.

Status & tagging log