http://www.mediawiki.org/wiki/Special:Code/MediaWiki/69021
Revision: 69021
Author: bawolff
Date: 2010-07-04 21:31:08 +0000 (Sun, 04 Jul 2010)
Log Message:
-----------
Stuff related to being backwards compatible
Modified Paths:
--------------
branches/img_metadata/phase3/docs/hooks.txt
branches/img_metadata/phase3/includes/DefaultSettings.php
branches/img_metadata/phase3/includes/api/ApiQueryImageInfo.php
branches/img_metadata/phase3/includes/filerepo/ForeignAPIFile.php
branches/img_metadata/phase3/includes/filerepo/LocalFile.php
branches/img_metadata/phase3/includes/media/Bitmap.php
branches/img_metadata/phase3/includes/media/Generic.php
branches/img_metadata/phase3/includes/media/Jpeg.php
Modified: branches/img_metadata/phase3/docs/hooks.txt
===================================================================
--- branches/img_metadata/phase3/docs/hooks.txt 2010-07-04 21:25:16 UTC (rev
69020)
+++ branches/img_metadata/phase3/docs/hooks.txt 2010-07-04 21:31:08 UTC (rev
69021)
@@ -824,6 +824,14 @@
$url: string value as output (out parameter, can modify)
$query: query options passed to Title::getLocalURL()
+'GetMetadataVersion': modify the image metadata version currently in use. This
is
+ used when requesting image metadata from a ForiegnApiRepo. Media
handlers
+ that need to have versioned metadata should add an element to the end of
+ the version array of the form 'handler_name=version'. Most media
handlers
+ won't need to do this unless they broke backwards compatibility with a
+ previous version of the media handler metadata output.
+&$version: Array of version strings
+
'GetPreferences': modify user preferences
$user: User whose preferences are being modified.
&$preferences: Preferences description array, to be fed to an HTMLForm object
Modified: branches/img_metadata/phase3/includes/DefaultSettings.php
===================================================================
--- branches/img_metadata/phase3/includes/DefaultSettings.php 2010-07-04
21:25:16 UTC (rev 69020)
+++ branches/img_metadata/phase3/includes/DefaultSettings.php 2010-07-04
21:31:08 UTC (rev 69021)
@@ -389,6 +389,13 @@
$wgShowEXIF = function_exists( 'exif_read_data' );
/**
+ * If to automatically update the img_metadata field
+ * if the metadata field is outdated but compatible with the current version.
+ * Defaults to false.
+ */
+$wgUpdateCompatibleMetadata = false;
+
+/**
* Set to true to enable the upload _link_ while local uploads are disabled.
* Assumes that the special page link will be bounced to another server where
* uploads do work.
Modified: branches/img_metadata/phase3/includes/api/ApiQueryImageInfo.php
===================================================================
--- branches/img_metadata/phase3/includes/api/ApiQueryImageInfo.php
2010-07-04 21:25:16 UTC (rev 69020)
+++ branches/img_metadata/phase3/includes/api/ApiQueryImageInfo.php
2010-07-04 21:31:08 UTC (rev 69021)
@@ -191,7 +191,7 @@
* @param $scale Array containing 'width' and 'height' items, or null
* @return Array: result array
*/
- static function getInfo( $file, $prop, $result, $scale = null, $version
= 0 ) {
+ static function getInfo( $file, $prop, $result, $scale = null, $version
= 'latest' ) {
$vals = array();
if ( isset( $prop['timestamp'] ) ) {
$vals['timestamp'] = wfTimestamp( TS_ISO_8601,
$file->getTimestamp() );
@@ -240,7 +240,7 @@
}
if ( isset( $prop['metadata'] ) ) {
$metadata = unserialize( $file->getMetadata() );
- if ( $version !== 0 ) {
+ if ( $version !== 'latest' ) {
$metadata = $file->convertMetadataVersion(
$metadata, $version );
}
$vals['metadata'] = $metadata ? self::processMetaData(
$metadata, $result ) : null;
@@ -311,9 +311,8 @@
ApiBase::PARAM_DFLT => - 1
),
'metadataversion' => array(
- ApiBase::PARAM_TYPE => 'integer',
- ApiBase::PARAM_DFLT => 1,
- ApiBase::PARAM_MIN => 0,
+ ApiBase::PARAM_TYPE => 'string',
+ ApiBase::PARAM_DFLT => '1',
),
'continue' => null,
);
@@ -349,7 +348,7 @@
'urlwidth' => array( "If {$p}prop=url is set, a URL to
an image scaled to this width will be returned.",
'Only the current version of the
image can be scaled' ),
'urlheight' => "Similar to {$p}urlwidth. Cannot be used
without {$p}urlwidth",
- 'metadataversion' => array( "Version of metadata to
use. if 0 is specified, use latest version.",
+ 'metadataversion' => array( "Version of metadata to
use. if 'latest' is specified, use latest version.",
"Defaults to '1' for bacwards
compatability" ),
'continue' => 'When more results are available, use
this to continue',
);
Modified: branches/img_metadata/phase3/includes/filerepo/ForeignAPIFile.php
===================================================================
--- branches/img_metadata/phase3/includes/filerepo/ForeignAPIFile.php
2010-07-04 21:25:16 UTC (rev 69020)
+++ branches/img_metadata/phase3/includes/filerepo/ForeignAPIFile.php
2010-07-04 21:31:08 UTC (rev 69021)
@@ -21,12 +21,8 @@
'titles' => 'File:' . $title->getText(),
'iiprop' =>
'timestamp|user|comment|url|size|sha1|metadata|mime',
'prop' => 'imageinfo',
- 'iimetadataversion' => Exif::version()
+ 'iimetadataversion' =>
mediaHandler::getMetadataVersion()
) );
- // Note to self/fixme: Using Exif::version() here is obviously
not good, as
- // metadata is handler specific. Original plan was to use
handler->getMetadataVersion()
- // but that doesn't work, because we don't know mime type yet,
thus don't know handler yet.
- // need to think of a better way of doing this.
$info = $repo->getImageInfo( $data );
Modified: branches/img_metadata/phase3/includes/filerepo/LocalFile.php
===================================================================
--- branches/img_metadata/phase3/includes/filerepo/LocalFile.php
2010-07-04 21:25:16 UTC (rev 69020)
+++ branches/img_metadata/phase3/includes/filerepo/LocalFile.php
2010-07-04 21:31:08 UTC (rev 69021)
@@ -302,6 +302,7 @@
* Upgrade a row if it needs it
*/
function maybeUpgradeRow() {
+ global $wgUpdateCompatibleMetadata;
if ( wfReadOnly() ) {
return;
}
@@ -312,9 +313,14 @@
$this->upgraded = true;
} else {
$handler = $this->getHandler();
- if ( $handler && !$handler->isMetadataValid( $this,
$this->metadata ) ) {
- $this->upgradeRow();
- $this->upgraded = true;
+ if ( $handler ) {
+ $validity = $handler->isMetadataValid( $this,
$this->metadata );
+ if ( $validity === MediaHandler::METADATA_BAD
+ || ( $validity ===
MediaHandler::METADATA_COMPATIBLE && $wgUpdateCompatibleMetadata )
+ ) {
+ $this->upgradeRow();
+ $this->upgraded = true;
+ }
}
}
}
Modified: branches/img_metadata/phase3/includes/media/Bitmap.php
===================================================================
--- branches/img_metadata/phase3/includes/media/Bitmap.php 2010-07-04
21:25:16 UTC (rev 69020)
+++ branches/img_metadata/phase3/includes/media/Bitmap.php 2010-07-04
21:31:08 UTC (rev 69021)
@@ -366,11 +366,11 @@
global $wgShowEXIF;
if ( !$wgShowEXIF ) {
# Metadata disabled and so an empty field is expected
- return true;
+ return self::METADATA_GOOD;
}
if ( $metadata === '0' ) {
# Special value indicating that there is no EXIF data
in the file
- return true;
+ return self::METADATA_GOOD;
}
wfSuppressWarnings();
$exif = unserialize( $metadata );
@@ -378,11 +378,18 @@
if ( !isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) ||
$exif['MEDIAWIKI_EXIF_VERSION'] != Exif::version() )
{
- # Wrong version
+ if ( isset( $exif['MEDIAWIKI_EXIF_VERSION'] ) &&
+ $exif['MEDIAWIKI_EXIF_VERSION'] == 1 )
+ {
+ //back-compatible but old
+ wfDebug( __METHOD__.": back-compat version\n" );
+ return self::METADATA_COMPATIBLE;
+ }
+ # Wrong (non-compatible) version
wfDebug( __METHOD__.": wrong version\n" );
- return false;
+ return self::METADATA_BAD;
}
- return true;
+ return self::METADATA_GOOD;
}
/**
Modified: branches/img_metadata/phase3/includes/media/Generic.php
===================================================================
--- branches/img_metadata/phase3/includes/media/Generic.php 2010-07-04
21:25:16 UTC (rev 69020)
+++ branches/img_metadata/phase3/includes/media/Generic.php 2010-07-04
21:31:08 UTC (rev 69021)
@@ -12,7 +12,9 @@
*/
abstract class MediaHandler {
const TRANSFORM_LATER = 1;
-
+ const METADATA_GOOD = true;
+ const METADATA_BAD = false;
+ const METADATA_COMPATIBLE = 2; // for old but backwards compatible.
/**
* Instance cache
*/
@@ -88,10 +90,24 @@
/**
* Get metadata version.
- * @return integer version
- * @todo Originally this was going to be used by ForeignAPIFile, but
currently does nothing.
+ *
+ * This is not used for validating metadata, this is used for the api
when returning
+ * metadata, since api content formats should stay the same over time,
and so things
+ * using ForiegnApiRepo can keep backwards compatibility
+ *
+ * All core media handlers share a common version number, and extensions
can
+ * use the GetMetadataVersion hook to append to the array (they should
append a unique
+ * string so not to get confusing). If there was a media handler named
'foo' with metadata
+ * version 3 it might add to the end of the array the element 'foo=3'.
if the core metadata
+ * version is 2, the end version string would look like '2;foo=3'.
+ *
+ * @return string version string
*/
- function getMetadataVersion () { return 1; }
+ static function getMetadataVersion () {
+ $version = Array( '2' ); // core metadata version
+ wfRunHooks('GetMetadataVersion', Array(&$version));
+ return implode( ';', $version);
+ }
/**
* Convert metadata version.
@@ -120,9 +136,15 @@
/**
* Check if the metadata string is valid for this handler.
- * If it returns false, Image will reload the metadata from the file
and update the database
+ * If it returns MediaHandler::METADATA_BAD (or false), Image
+ * will reload the metadata from the file and update the database.
+ * MediaHandler::METADATA_GOOD for if the metadata is a-ok,
+ * MediaHanlder::METADATA_COMPATIBLE if metadata is old but backwards
+ * compatible (which may or may not trigger a metadata reload).
*/
- function isMetadataValid( $image, $metadata ) { return true; }
+ function isMetadataValid( $image, $metadata ) {
+ return self::METADATA_GOOD;
+ }
/**
Modified: branches/img_metadata/phase3/includes/media/Jpeg.php
===================================================================
--- branches/img_metadata/phase3/includes/media/Jpeg.php 2010-07-04
21:25:16 UTC (rev 69020)
+++ branches/img_metadata/phase3/includes/media/Jpeg.php 2010-07-04
21:31:08 UTC (rev 69021)
@@ -30,7 +30,9 @@
function convertMetadataVersion( $metadata, $version = 1 ) {
// basically flattens arrays.
- if ( $version != 1 ) {
+ $version = explode(';', $version, 2);
+ $version = intval($version[0]);
+ if ( $version < 1 || $version >= 2 ) {
return $metadata;
}
@@ -46,8 +48,7 @@
$val = formatExif::flattenArray( $val );
}
}
- $metadata['MEDIAWIKI_EXIF_VERSION'] = $version;
+ $metadata['MEDIAWIKI_EXIF_VERSION'] = 1;
return $metadata;
}
- function getMetadataVersion () { return Exif::version(); }
}
_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs