r70922 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70921‎ | r70922 | r70923 >
Date:22:37, 11 August 2010
Author:bawolff
Status:ok
Tags:
Comment:
Follow up to r70860. Fix some stylistic info, and don't
have a $wgShowXMP global.
Modified paths:
  • /branches/img_metadata/phase3/includes/DefaultSettings.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/BitmapMetadataHandler.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/JpegMetadataExtractor.php (modified) (history)
  • /branches/img_metadata/phase3/includes/media/PNGMetadataExtractor.php (modified) (history)

Diff [purge]

Index: branches/img_metadata/phase3/includes/media/BitmapMetadataHandler.php
@@ -9,10 +9,6 @@
1010 @todo other image formats.
1111 */
1212 class BitmapMetadataHandler {
13 - const MAX_JPEG_SEGMENTS = 200;
14 - // the max segment is a sanity check.
15 - // A jpeg file should never even remotely have
16 - // that many segments. Your average file has about 10.
1713 private $filename;
1814 private $metadata = Array();
1915 private $metaPriority = Array(
@@ -62,7 +58,7 @@
6359 * @param Array $metaArray array of metadata values
6460 * @param string $type type. defaults to other. if two things have the same type they're merged
6561 */
66 - function addMetadata( $metaArray, $type = 'other' ) {
 62+ function addMetadata ( $metaArray, $type = 'other' ) {
6763 if ( isset( $this->metadata[$type] ) ) {
6864 /* merge with old data */
6965 $metaArray = $metaArray + $this->metadata[$type];
@@ -80,7 +76,7 @@
8177 *
8278 * @return Array metadata array
8379 */
84 - function getMetadataArray() {
 80+ function getMetadataArray () {
8581 // this seems a bit ugly... This is all so its merged in right order
8682 // based on the MWG recomendation.
8783 $temp = Array();
@@ -88,11 +84,11 @@
8985 foreach ( $this->metaPriority as $pri ) {
9086 foreach ( $pri as $type ) {
9187 if ( isset( $this->metadata[$type] ) ) {
92 - //Do some special casing for multilingual values.
 88+ // Do some special casing for multilingual values.
9389 // Don't discard translations if also as a simple value.
9490 foreach ( $this->metadata[$type] as $itemName => $item ) {
95 - if ( is_array($item) && isset($item['_type']) && $item['_type'] === 'lang' ) {
96 - if ( isset($temp[$itemName]) && !is_array($temp[$itemName]) ) {
 91+ if ( is_array( $item ) && isset( $item['_type'] ) && $item['_type'] === 'lang' ) {
 92+ if ( isset( $temp[$itemName] ) && !is_array( $temp[$itemName] ) ) {
9793 $default = $temp[$itemName];
9894 $temp[$itemName] = $item;
9995 $temp[$itemName]['x-default'] = $default;
@@ -123,22 +119,22 @@
124120 * @return metadata result array.
125121 * @throws MWException on invalid file.
126122 */
127 - static function Jpeg ( $file ) {
128 - global $wgShowXMP;
129 - $meta = new self( $file );
 123+ static function Jpeg ( $filename ) {
 124+ $showXMP = function_exists( 'xml_parser_create_ns' );
 125+ $meta = new self( $filename );
130126 $meta->getExif();
131127 $seg = Array();
132 - $seg = JpegMetadataExtractor::segmentSplitter( $file );
 128+ $seg = JpegMetadataExtractor::segmentSplitter( $filename );
133129 if ( isset( $seg['COM'] ) && isset( $seg['COM'][0] ) ) {
134130 $meta->addMetadata( Array( 'JPEGFileComment' => $seg['COM'] ), 'file-comment' );
135131 }
136132 if ( isset( $seg['PSIR'] ) ) {
137133 $meta->doApp13( $seg['PSIR'] );
138134 }
139 - if ( isset( $seg['XMP'] ) && $wgShowXMP ) {
 135+ if ( isset( $seg['XMP'] ) && $showXMP ) {
140136 $xmp = new XMPReader();
141137 $xmp->parse( $seg['XMP'] );
142 - foreach( $seg['XMP_ext'] as $xmpExt ) {
 138+ foreach ( $seg['XMP_ext'] as $xmpExt ) {
143139 /* Support for extended xmp in jpeg files
144140 * is not well tested and a bit fragile.
145141 */
@@ -146,8 +142,8 @@
147143
148144 }
149145 $res = $xmp->getResults();
150 - foreach( $res as $type => $array ) {
151 - $meta->addMetadata( $array, $type );
 146+ foreach ( $res as $type => $array ) {
 147+ $meta->addMetadata( $array, $type );
152148 }
153149 }
154150 return $meta->getMetadataArray();
@@ -160,16 +156,16 @@
161157 * @param $filename String full path to file
162158 * @return Array Array for storage in img_metadata.
163159 */
164 - static public function PNG( $filename ) {
165 - global $wgShowXMP;
 160+ static public function PNG ( $filename ) {
 161+ $showXMP = function_exists( 'xml_parser_create_ns' );
166162
167163 $meta = new self( $filename );
168164 $array = PNGMetadataExtractor::getMetadata( $filename );
169 - if ( isset( $array['xmp'] ) && $array['xmp'] !== '' && $wgShowXMP) {
 165+ if ( isset( $array['xmp'] ) && $array['xmp'] !== '' && $showXMP ) {
170166 $xmp = new XMPReader();
171 - $xmp->parse($array['xmp']);
 167+ $xmp->parse( $array['xmp'] );
172168 $xmpRes = $xmp->getResults();
173 - foreach( $xmpRes as $type => $xmpSection ) {
 169+ foreach ( $xmpRes as $type => $xmpSection ) {
174170 $meta->addMetadata( $xmpSection, $type );
175171 }
176172 }
Index: branches/img_metadata/phase3/includes/media/PNGMetadataExtractor.php
@@ -13,6 +13,8 @@
1414 static function getMetadata( $filename ) {
1515 self::$png_sig = pack( "C8", 137, 80, 78, 71, 13, 10, 26, 10 );
1616 self::$CRC_size = 4;
 17+
 18+ $showXMP = function_exists( 'xml_parser_create_ns' );
1719
1820 $frameCount = 0;
1921 $loopCount = 1;
@@ -63,7 +65,7 @@
6466 if( $fctldur['delay_num'] ) {
6567 $duration += $fctldur['delay_num'] / $fctldur['delay_den'];
6668 }
67 - } elseif ( $chunk_type == "iTXt" ) {
 69+ } elseif ( $chunk_type == "iTXt" && $showXMP ) {
6870 // At the moment this only does XMP iText chunks,
6971 // but in the future might extract other metadata chunks.
7072 if( $chunk_size <= 22 ) {
Index: branches/img_metadata/phase3/includes/media/JpegMetadataExtractor.php
@@ -22,8 +22,8 @@
2323 * @return Array of interesting segments.
2424 * @throws MWException if given invalid file.
2525 */
26 - static function segmentSplitter ($filename) {
27 - global $wgShowXMP;
 26+ static function segmentSplitter ( $filename ) {
 27+ $showXMP = function_exists( 'xml_parser_create_ns' );
2828
2929 $segmentCount = 0;
3030
@@ -43,7 +43,7 @@
4444 $segmentCount++;
4545 if ( $segmentCount > self::MAX_JPEG_SEGMENTS ) {
4646 // this is just a sanity check
47 - throw new MWException('Too many jpeg segments. Aborting');
 47+ throw new MWException( 'Too many jpeg segments. Aborting' );
4848 }
4949 if ( $buffer !== "\xFF" ) {
5050 throw new MWException( "Error reading jpeg file marker" );
@@ -57,15 +57,15 @@
5858 // if not try to convert it to windows-1252.
5959 $com = $oldCom = trim( self::jpegExtractMarker( $fh ) );
6060
61 - UtfNormal::quickIsNFCVerify( $com );
62 - //turns $com to valid utf-8.
63 - //thus if no change, its utf-8, otherwise its something else.
 61+ UtfNormal::quickIsNFCVerify( $com );
 62+ // turns $com to valid utf-8.
 63+ // thus if no change, its utf-8, otherwise its something else.
6464 if ( $com !== $oldCom ) {
6565 $oldCom = iconv( 'windows-1252', 'UTF-8//IGNORE', $oldCom );
6666 }
6767 $segments["COM"][] = $oldCom;
6868
69 - } elseif ( $buffer === "\xE1" && $wgShowXMP ) {
 69+ } elseif ( $buffer === "\xE1" && $showXMP ) {
7070 // APP1 section (Exif, XMP, and XMP extended)
7171 // only extract if XMP is enabled.
7272 $temp = self::jpegExtractMarker( $fh );
@@ -152,7 +152,7 @@
153153 // the piece of info this record contains.
154154
155155 $offset += 2;
156 -
 156+
157157 // some record types can contain a name, which
158158 // is a pascal string 0-padded to be an even
159159 // number of bytes. Most times (and any time
@@ -189,7 +189,7 @@
190190 // null pad byte.
191191 if ( $lenData['len'] % 2 == 1 ) $lenData['len']++;
192192 $offset += $lenData['len'];
193 -
 193+
194194 }
195195
196196 if ( !$realHash || !$recordedHash ) {
Index: branches/img_metadata/phase3/includes/DefaultSettings.php
@@ -388,11 +388,6 @@
389389 $wgShowEXIF = function_exists( 'exif_read_data' );
390390
391391 /**
392 - * Show/extract XMP metadata (similar to above exif setting)
393 - */
394 -$wgShowXMP = function_exists( 'xml_parser_create_ns' );
395 -
396 -/**
397392 * If to automatically update the img_metadata field
398393 * if the metadata field is outdated but compatible with the current version.
399394 * Defaults to false.

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r70860Read xmp data in png files...bawolff08:30, 11 August 2010

Status & tagging log