Index: branches/img_metadata/phase3/includes/Exif.php |
— | — | @@ -1438,6 +1438,10 @@ |
1439 | 1439 | return ""; // paranoia. This should never happen |
1440 | 1440 | wfDebug( __METHOD__ . ' metadata array with 0 elements!' ); |
1441 | 1441 | } |
| 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 | + */ |
1442 | 1446 | else { |
1443 | 1447 | switch( $type ) { |
1444 | 1448 | case 'lang': |
— | — | @@ -1450,16 +1454,17 @@ |
1451 | 1455 | $content .= "\n*" . $vals['x-default']; |
1452 | 1456 | unset( $vals['x-default'] ); |
1453 | 1457 | } |
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>"; |
1457 | 1462 | } |
1458 | 1463 | return $content; |
1459 | 1464 | case 'ol': |
1460 | | - return "\n#" . implode( "\n#", $vals ); |
| 1465 | + return "<ol><li>" . implode( "</li>\n<li>", $vals ) . '</li></ol>'; |
1461 | 1466 | case 'ul': |
1462 | 1467 | default: |
1463 | | - return "\n*" . implode( "\n*", $vals ); |
| 1468 | + return "<ul><li>" . implode( "</li>\n<li>", $vals ) . '</li></ul>'; |
1464 | 1469 | } |
1465 | 1470 | } |
1466 | 1471 | } |
Index: branches/img_metadata/phase3/includes/media/XMP.php |
— | — | @@ -29,6 +29,7 @@ |
30 | 30 | private $itemLang = false; // used for lang alts only |
31 | 31 | |
32 | 32 | private $xmlParser; |
| 33 | + private $charset = false; |
33 | 34 | |
34 | 35 | protected $items; |
35 | 36 | |
— | — | @@ -114,6 +115,46 @@ |
115 | 116 | */ |
116 | 117 | public function parse( $content ) { |
117 | 118 | 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 | + |
118 | 159 | $ok = xml_parse( $this->xmlParser, $content, true ); |
119 | 160 | if ( !$ok ) { |
120 | 161 | $error = xml_error_string( xml_get_error_code( $this->xmlParser ) ); |
— | — | @@ -284,15 +325,15 @@ |
285 | 326 | |
286 | 327 | if ( $elm === self::NS_RDF . ' Seq' ) { |
287 | 328 | array_shift( $this->mode ); |
288 | | - $this->results['xmp-' . $info['map_group']][$finalName]['_format'] = 'ol'; |
| 329 | + $this->results['xmp-' . $info['map_group']][$finalName]['_type'] = 'ol'; |
289 | 330 | } elseif ( $elm === self::NS_RDF . ' Bag' ) { |
290 | 331 | array_shift( $this->mode ); |
291 | | - $this->results['xmp-' . $info['map_group']][$finalName]['_format'] = 'ul'; |
| 332 | + $this->results['xmp-' . $info['map_group']][$finalName]['_type'] = 'ul'; |
292 | 333 | } elseif ( $elm === self::NS_RDF . ' Alt' ) { |
293 | 334 | array_shift( $this->mode ); |
294 | 335 | // extra if needed as you could theoretically have a non-language alt. |
295 | 336 | 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'; |
297 | 338 | } |
298 | 339 | |
299 | 340 | } else { |
Index: branches/img_metadata/phase3/includes/media/BitmapMetadataHandler.php |
— | — | @@ -19,7 +19,8 @@ |
20 | 20 | 20 => Array( 'other' ), |
21 | 21 | 40 => Array( 'file-comment' ), |
22 | 22 | 60 => Array( 'iptc-bad-hash' ), |
23 | | - 80 => Array( 'xmp' ), |
| 23 | + 80 => Array( 'xmp-general' ), |
| 24 | + 90 => Array( 'xmp-exif' ), |
24 | 25 | 100 => Array( 'iptc-good-hash', 'iptc-no-hash' ), |
25 | 26 | 120 => Array( 'exif' ), |
26 | 27 | ); |
— | — | @@ -85,7 +86,7 @@ |
86 | 87 | |
87 | 88 | // check what type of app segment this is. |
88 | 89 | if ( substr( $temp, 0, 29 ) === "http://ns.adobe.com/xap/1.0/\x00" ) { |
89 | | - $segments["XMP"] = $temp; |
| 90 | + $segments["XMP"] = substr( $temp, 29 ); |
90 | 91 | } elseif ( substr( $temp, 0, 35 ) === "http://ns.adobe.com/xmp/extension/\x00" ) { |
91 | 92 | $segments["XMP_ext"][] = $temp; |
92 | 93 | } |
— | — | @@ -312,6 +313,18 @@ |
313 | 314 | if ( isset( $seg['PSIR'] ) ) { |
314 | 315 | $meta->doApp13( $seg['PSIR'] ); |
315 | 316 | } |
| 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 | + } |
316 | 329 | return $meta; |
317 | 330 | } |
318 | 331 | |