Index: branches/img_metadata/phase3/includes/media/BitmapMetadataHandler.php |
— | — | @@ -9,10 +9,6 @@ |
10 | 10 | @todo other image formats. |
11 | 11 | */ |
12 | 12 | 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. |
17 | 13 | private $filename; |
18 | 14 | private $metadata = Array(); |
19 | 15 | private $metaPriority = Array( |
— | — | @@ -62,7 +58,7 @@ |
63 | 59 | * @param Array $metaArray array of metadata values |
64 | 60 | * @param string $type type. defaults to other. if two things have the same type they're merged |
65 | 61 | */ |
66 | | - function addMetadata( $metaArray, $type = 'other' ) { |
| 62 | + function addMetadata ( $metaArray, $type = 'other' ) { |
67 | 63 | if ( isset( $this->metadata[$type] ) ) { |
68 | 64 | /* merge with old data */ |
69 | 65 | $metaArray = $metaArray + $this->metadata[$type]; |
— | — | @@ -80,7 +76,7 @@ |
81 | 77 | * |
82 | 78 | * @return Array metadata array |
83 | 79 | */ |
84 | | - function getMetadataArray() { |
| 80 | + function getMetadataArray () { |
85 | 81 | // this seems a bit ugly... This is all so its merged in right order |
86 | 82 | // based on the MWG recomendation. |
87 | 83 | $temp = Array(); |
— | — | @@ -88,11 +84,11 @@ |
89 | 85 | foreach ( $this->metaPriority as $pri ) { |
90 | 86 | foreach ( $pri as $type ) { |
91 | 87 | if ( isset( $this->metadata[$type] ) ) { |
92 | | - //Do some special casing for multilingual values. |
| 88 | + // Do some special casing for multilingual values. |
93 | 89 | // Don't discard translations if also as a simple value. |
94 | 90 | 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] ) ) { |
97 | 93 | $default = $temp[$itemName]; |
98 | 94 | $temp[$itemName] = $item; |
99 | 95 | $temp[$itemName]['x-default'] = $default; |
— | — | @@ -123,22 +119,22 @@ |
124 | 120 | * @return metadata result array. |
125 | 121 | * @throws MWException on invalid file. |
126 | 122 | */ |
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 ); |
130 | 126 | $meta->getExif(); |
131 | 127 | $seg = Array(); |
132 | | - $seg = JpegMetadataExtractor::segmentSplitter( $file ); |
| 128 | + $seg = JpegMetadataExtractor::segmentSplitter( $filename ); |
133 | 129 | if ( isset( $seg['COM'] ) && isset( $seg['COM'][0] ) ) { |
134 | 130 | $meta->addMetadata( Array( 'JPEGFileComment' => $seg['COM'] ), 'file-comment' ); |
135 | 131 | } |
136 | 132 | if ( isset( $seg['PSIR'] ) ) { |
137 | 133 | $meta->doApp13( $seg['PSIR'] ); |
138 | 134 | } |
139 | | - if ( isset( $seg['XMP'] ) && $wgShowXMP ) { |
| 135 | + if ( isset( $seg['XMP'] ) && $showXMP ) { |
140 | 136 | $xmp = new XMPReader(); |
141 | 137 | $xmp->parse( $seg['XMP'] ); |
142 | | - foreach( $seg['XMP_ext'] as $xmpExt ) { |
| 138 | + foreach ( $seg['XMP_ext'] as $xmpExt ) { |
143 | 139 | /* Support for extended xmp in jpeg files |
144 | 140 | * is not well tested and a bit fragile. |
145 | 141 | */ |
— | — | @@ -146,8 +142,8 @@ |
147 | 143 | |
148 | 144 | } |
149 | 145 | $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 ); |
152 | 148 | } |
153 | 149 | } |
154 | 150 | return $meta->getMetadataArray(); |
— | — | @@ -160,16 +156,16 @@ |
161 | 157 | * @param $filename String full path to file |
162 | 158 | * @return Array Array for storage in img_metadata. |
163 | 159 | */ |
164 | | - static public function PNG( $filename ) { |
165 | | - global $wgShowXMP; |
| 160 | + static public function PNG ( $filename ) { |
| 161 | + $showXMP = function_exists( 'xml_parser_create_ns' ); |
166 | 162 | |
167 | 163 | $meta = new self( $filename ); |
168 | 164 | $array = PNGMetadataExtractor::getMetadata( $filename ); |
169 | | - if ( isset( $array['xmp'] ) && $array['xmp'] !== '' && $wgShowXMP) { |
| 165 | + if ( isset( $array['xmp'] ) && $array['xmp'] !== '' && $showXMP ) { |
170 | 166 | $xmp = new XMPReader(); |
171 | | - $xmp->parse($array['xmp']); |
| 167 | + $xmp->parse( $array['xmp'] ); |
172 | 168 | $xmpRes = $xmp->getResults(); |
173 | | - foreach( $xmpRes as $type => $xmpSection ) { |
| 169 | + foreach ( $xmpRes as $type => $xmpSection ) { |
174 | 170 | $meta->addMetadata( $xmpSection, $type ); |
175 | 171 | } |
176 | 172 | } |
Index: branches/img_metadata/phase3/includes/media/PNGMetadataExtractor.php |
— | — | @@ -13,6 +13,8 @@ |
14 | 14 | static function getMetadata( $filename ) { |
15 | 15 | self::$png_sig = pack( "C8", 137, 80, 78, 71, 13, 10, 26, 10 ); |
16 | 16 | self::$CRC_size = 4; |
| 17 | + |
| 18 | + $showXMP = function_exists( 'xml_parser_create_ns' ); |
17 | 19 | |
18 | 20 | $frameCount = 0; |
19 | 21 | $loopCount = 1; |
— | — | @@ -63,7 +65,7 @@ |
64 | 66 | if( $fctldur['delay_num'] ) { |
65 | 67 | $duration += $fctldur['delay_num'] / $fctldur['delay_den']; |
66 | 68 | } |
67 | | - } elseif ( $chunk_type == "iTXt" ) { |
| 69 | + } elseif ( $chunk_type == "iTXt" && $showXMP ) { |
68 | 70 | // At the moment this only does XMP iText chunks, |
69 | 71 | // but in the future might extract other metadata chunks. |
70 | 72 | if( $chunk_size <= 22 ) { |
Index: branches/img_metadata/phase3/includes/media/JpegMetadataExtractor.php |
— | — | @@ -22,8 +22,8 @@ |
23 | 23 | * @return Array of interesting segments. |
24 | 24 | * @throws MWException if given invalid file. |
25 | 25 | */ |
26 | | - static function segmentSplitter ($filename) { |
27 | | - global $wgShowXMP; |
| 26 | + static function segmentSplitter ( $filename ) { |
| 27 | + $showXMP = function_exists( 'xml_parser_create_ns' ); |
28 | 28 | |
29 | 29 | $segmentCount = 0; |
30 | 30 | |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | $segmentCount++; |
45 | 45 | if ( $segmentCount > self::MAX_JPEG_SEGMENTS ) { |
46 | 46 | // this is just a sanity check |
47 | | - throw new MWException('Too many jpeg segments. Aborting'); |
| 47 | + throw new MWException( 'Too many jpeg segments. Aborting' ); |
48 | 48 | } |
49 | 49 | if ( $buffer !== "\xFF" ) { |
50 | 50 | throw new MWException( "Error reading jpeg file marker" ); |
— | — | @@ -57,15 +57,15 @@ |
58 | 58 | // if not try to convert it to windows-1252. |
59 | 59 | $com = $oldCom = trim( self::jpegExtractMarker( $fh ) ); |
60 | 60 | |
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. |
64 | 64 | if ( $com !== $oldCom ) { |
65 | 65 | $oldCom = iconv( 'windows-1252', 'UTF-8//IGNORE', $oldCom ); |
66 | 66 | } |
67 | 67 | $segments["COM"][] = $oldCom; |
68 | 68 | |
69 | | - } elseif ( $buffer === "\xE1" && $wgShowXMP ) { |
| 69 | + } elseif ( $buffer === "\xE1" && $showXMP ) { |
70 | 70 | // APP1 section (Exif, XMP, and XMP extended) |
71 | 71 | // only extract if XMP is enabled. |
72 | 72 | $temp = self::jpegExtractMarker( $fh ); |
— | — | @@ -152,7 +152,7 @@ |
153 | 153 | // the piece of info this record contains. |
154 | 154 | |
155 | 155 | $offset += 2; |
156 | | - |
| 156 | + |
157 | 157 | // some record types can contain a name, which |
158 | 158 | // is a pascal string 0-padded to be an even |
159 | 159 | // number of bytes. Most times (and any time |
— | — | @@ -189,7 +189,7 @@ |
190 | 190 | // null pad byte. |
191 | 191 | if ( $lenData['len'] % 2 == 1 ) $lenData['len']++; |
192 | 192 | $offset += $lenData['len']; |
193 | | - |
| 193 | + |
194 | 194 | } |
195 | 195 | |
196 | 196 | if ( !$realHash || !$recordedHash ) { |
Index: branches/img_metadata/phase3/includes/DefaultSettings.php |
— | — | @@ -388,11 +388,6 @@ |
389 | 389 | $wgShowEXIF = function_exists( 'exif_read_data' ); |
390 | 390 | |
391 | 391 | /** |
392 | | - * Show/extract XMP metadata (similar to above exif setting) |
393 | | - */ |
394 | | -$wgShowXMP = function_exists( 'xml_parser_create_ns' ); |
395 | | - |
396 | | -/** |
397 | 392 | * If to automatically update the img_metadata field |
398 | 393 | * if the metadata field is outdated but compatible with the current version. |
399 | 394 | * Defaults to false. |