r70726 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70725‎ | r70726 | r70727 >
Date:00:08, 9 August 2010
Author:bawolff
Status:deferred
Tags:
Comment:
Initial bit of attaching the xmp stuff with the jpeg stuff.

Still doesn't do the XMPExtended block, and has some bits that
need to be made nicer.
Modified paths:
  • /branches/img_metadata/phase3/includes/Exif.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/BitmapMetadataHandler.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/XMP.php (modified) (history)

Diff [purge]

Index: branches/img_metadata/phase3/includes/Exif.php
@@ -1438,6 +1438,10 @@
14391439 return ""; // paranoia. This should never happen
14401440 wfDebug( __METHOD__ . ' metadata array with 0 elements!' );
14411441 }
 1442+ /* Fixme: This should hide some of the list entries if there are
 1443+ * say more than four. Especially if a field is translated into 20
 1444+ * languages, we don't want to show them all by default
 1445+ */
14421446 else {
14431447 switch( $type ) {
14441448 case 'lang':
@@ -1450,16 +1454,17 @@
14511455 $content .= "\n*" . $vals['x-default'];
14521456 unset( $vals['x-default'] );
14531457 }
1454 - foreach ( $vals as $lang => $content ) {
1455 - $content = "\n*<span lang=\"$lang\">"
1456 - . "'''$lang''' $content</span>";
 1458+ foreach ( $vals as $lang => $item ) {
 1459+ global $wgContLang;
 1460+ $content .= "\n*<span lang=\"$lang\">"
 1461+ . "'''$lang''' $item</span>";
14571462 }
14581463 return $content;
14591464 case 'ol':
1460 - return "\n#" . implode( "\n#", $vals );
 1465+ return "<ol><li>" . implode( "</li>\n<li>", $vals ) . '</li></ol>';
14611466 case 'ul':
14621467 default:
1463 - return "\n*" . implode( "\n*", $vals );
 1468+ return "<ul><li>" . implode( "</li>\n<li>", $vals ) . '</li></ul>';
14641469 }
14651470 }
14661471 }
Index: branches/img_metadata/phase3/includes/media/XMP.php
@@ -29,6 +29,7 @@
3030 private $itemLang = false; // used for lang alts only
3131
3232 private $xmlParser;
 33+ private $charset = false;
3334
3435 protected $items;
3536
@@ -114,6 +115,46 @@
115116 */
116117 public function parse( $content ) {
117118 try {
 119+
 120+ // detect encoding by looking for BOM
 121+ // see page 12 of http://www.adobe.com/devnet/xmp/pdfs/XMPSpecificationPart3.pdf
 122+ if ( !$this->charset ) {
 123+ $bom = array();
 124+ if ( preg_match( '/\xEF\xBB\xBF|\xFE\xFF|\x00\x00\xFE\xFF|\xFF\xFE\x00\x00|\xFF\xFE/',
 125+ $content, $bom )
 126+ ) {
 127+ switch ( $bom[0] ) {
 128+ case "\xFE\xFF":
 129+ $this->charset = 'UTF-16BE';
 130+ break;
 131+ case "\xFF\xFE":
 132+ $this->charset = 'UTF-16LE';
 133+ break;
 134+ case "\x00\x00\xFE\xFF":
 135+ $this->charset = 'UTF-32BE';
 136+ break;
 137+ case "\xFF\xFE\x00\x00":
 138+ $this->charset = 'UTF-32LE';
 139+ break;
 140+ case "\xEF\xBB\xBF":
 141+ $this->charset = 'UTF-8';
 142+ break;
 143+ default:
 144+ //this should be impossible to get to
 145+ throw new MWException("Invalid BOM");
 146+ break;
 147+
 148+ }
 149+
 150+ } else {
 151+ $this->charset = 'UTF-8';
 152+ }
 153+ }
 154+ if ( $this->charset !== 'UTF-8' ) {
 155+ //don't convert if already utf-8
 156+ $content = iconv( $this->charset, 'UTF-8//IGNORE', $content );
 157+ }
 158+
118159 $ok = xml_parse( $this->xmlParser, $content, true );
119160 if ( !$ok ) {
120161 $error = xml_error_string( xml_get_error_code( $this->xmlParser ) );
@@ -284,15 +325,15 @@
285326
286327 if ( $elm === self::NS_RDF . ' Seq' ) {
287328 array_shift( $this->mode );
288 - $this->results['xmp-' . $info['map_group']][$finalName]['_format'] = 'ol';
 329+ $this->results['xmp-' . $info['map_group']][$finalName]['_type'] = 'ol';
289330 } elseif ( $elm === self::NS_RDF . ' Bag' ) {
290331 array_shift( $this->mode );
291 - $this->results['xmp-' . $info['map_group']][$finalName]['_format'] = 'ul';
 332+ $this->results['xmp-' . $info['map_group']][$finalName]['_type'] = 'ul';
292333 } elseif ( $elm === self::NS_RDF . ' Alt' ) {
293334 array_shift( $this->mode );
294335 // extra if needed as you could theoretically have a non-language alt.
295336 if ( $info['mode'] === self::MODE_LANG ) {
296 - $this->results['xmp-' . $info['map_group']][$finalName]['_format'] = 'lang';
 337+ $this->results['xmp-' . $info['map_group']][$finalName]['_type'] = 'lang';
297338 }
298339
299340 } else {
Index: branches/img_metadata/phase3/includes/media/BitmapMetadataHandler.php
@@ -19,7 +19,8 @@
2020 20 => Array( 'other' ),
2121 40 => Array( 'file-comment' ),
2222 60 => Array( 'iptc-bad-hash' ),
23 - 80 => Array( 'xmp' ),
 23+ 80 => Array( 'xmp-general' ),
 24+ 90 => Array( 'xmp-exif' ),
2425 100 => Array( 'iptc-good-hash', 'iptc-no-hash' ),
2526 120 => Array( 'exif' ),
2627 );
@@ -85,7 +86,7 @@
8687
8788 // check what type of app segment this is.
8889 if ( substr( $temp, 0, 29 ) === "http://ns.adobe.com/xap/1.0/\x00" ) {
89 - $segments["XMP"] = $temp;
 90+ $segments["XMP"] = substr( $temp, 29 );
9091 } elseif ( substr( $temp, 0, 35 ) === "http://ns.adobe.com/xmp/extension/\x00" ) {
9192 $segments["XMP_ext"][] = $temp;
9293 }
@@ -312,6 +313,18 @@
313314 if ( isset( $seg['PSIR'] ) ) {
314315 $meta->doApp13( $seg['PSIR'] );
315316 }
 317+ if ( isset( $seg['XMP'] ) ) {
 318+ $xmp = new XMPReader();
 319+ $xmp->parse( $seg['XMP'] );
 320+ if ( isset( $seg['XMP_ext'] ) ) {
 321+ /* FIXME!! */
 322+
 323+ }
 324+ $res = $xmp->getResults();
 325+ foreach( $res as $type => $array ) {
 326+ $meta->addMetadata( $array, $type );
 327+ }
 328+ }
316329 return $meta;
317330 }
318331

Status & tagging log