Index: trunk/extensions/PagedTiffHandler/tests/PagedTiffHandlerTest.php |
— | — | @@ -191,10 +191,10 @@ |
192 | 192 | //this is also strtolower in PagedTiffHandler::getThumbExtension |
193 | 193 | $this->assertEquals( strtolower( $metaArray['page_data'][1]['alpha'] ), 'false' ); |
194 | 194 | $this->assertEquals( strtolower( $metaArray['page_data'][2]['alpha'] ), 'true' ); |
195 | | - $this->assertEquals( $metaArray['exif']['Endianess'], 'MSB' ); |
| 195 | + $this->assertEquals( $metaArray['exif']['PhotometricInterpretation'], 2 ); //RGB |
196 | 196 | // formatMetadata |
197 | 197 | $formattedMetadata = $this->handler->formatMetadata( $this->image ); |
198 | | - $this->assertEquals( $formattedMetadata['collapsed'][0]['value'], 'TIFF (Tagged Image File Format)' ); |
| 198 | + $this->assertEquals( $formattedMetadata['collapsed'][3]['value'], 'RGB' ); //XXX: brittle, index might change. |
199 | 199 | } |
200 | 200 | |
201 | 201 | } |
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php |
— | — | @@ -250,15 +250,26 @@ |
251 | 251 | return false; |
252 | 252 | } |
253 | 253 | |
| 254 | + $errors = array(); |
| 255 | + foreach ( $errors_raw as $error ) { |
| 256 | + if ( $error === false || $error === null || $error === 0 || $error === '' ) |
| 257 | + continue; |
| 258 | + |
| 259 | + $error = trim( $error ); |
| 260 | + |
| 261 | + if ( $error === '' ) |
| 262 | + continue; |
| 263 | + |
| 264 | + if ( $to_html ) |
| 265 | + $error = htmlspecialchars( $error ); |
| 266 | + |
| 267 | + $errors[] = $error; |
| 268 | + } |
| 269 | + |
254 | 270 | if ( $to_html ) { |
255 | | - $errors = array(); |
256 | | - foreach ( $errors_raw as $error ) { |
257 | | - $errors[] = htmlspecialchars( $error ); |
258 | | - } |
259 | | - |
260 | | - return join( '<br />', $errors ); |
| 271 | + return trim( join( '<br />', $errors ) ); |
261 | 272 | } else { |
262 | | - return join( ";\n", $errors_raw ); |
| 273 | + return trim( join( ";\n", $errors ) ); |
263 | 274 | } |
264 | 275 | } |
265 | 276 | |
— | — | @@ -533,19 +544,21 @@ |
534 | 545 | $errors = PagedTiffHandler::joinMessages( $errors_raw ); |
535 | 546 | self::addMeta( $result, |
536 | 547 | 'collapsed', |
537 | | - 'identify', |
| 548 | + 'metadata', |
538 | 549 | 'error', |
539 | 550 | $errors |
540 | 551 | ); |
| 552 | + //XXX: need translation for <metadata-error> |
541 | 553 | } |
542 | | - if ( isset( $meta['warnings'] ) ) { |
| 554 | + if ( !empty( $meta['warnings'] ) ) { |
543 | 555 | $warnings = PagedTiffHandler::joinMessages( $meta['warnings'] ); |
544 | 556 | self::addMeta( $result, |
545 | 557 | 'collapsed', |
546 | | - 'identify', |
| 558 | + 'metadata', |
547 | 559 | 'warning', |
548 | 560 | $warnings |
549 | 561 | ); |
| 562 | + //XXX: need translation for <metadata-warning> |
550 | 563 | } |
551 | 564 | return $result; |
552 | 565 | } |
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler.image.php |
— | — | @@ -133,22 +133,13 @@ |
134 | 134 | $this->_meta['exif'][$data[1]] = $data[2]; |
135 | 135 | } |
136 | 136 | } else { |
137 | | - $cmd = wfEscapeShellArg( $wgImageMagickIdentifyCommand ) . |
138 | | - ' -verbose ' . |
139 | | - wfEscapeShellArg( $this->mFilename ) . "[0]"; |
140 | | - |
141 | | - wfProfileIn( 'identify -verbose' ); |
142 | | - wfDebug( __METHOD__ . ": $cmd\n" ); |
143 | | - $dump = wfShellExec( $cmd, $retval ); |
144 | | - wfProfileOut( 'identify -verbose' ); |
145 | | - |
146 | | - if ( $retval ) { |
147 | | - $data['errors'][] = "identify command failed: $cmd"; |
148 | | - wfDebug( __METHOD__ . ": identify command failed: $cmd\n" ); |
149 | | - //don't fail - we are missing info, but that's no reason to abort yet. |
150 | | - } |
151 | | - |
152 | | - $this->_meta['exif'] = $this->parseVerbose( $dump ); |
| 137 | + wfDebug( __METHOD__ . ": using internal Exif( {$this->mFilename} )\n" ); |
| 138 | + $exif = new Exif( $this->mFilename ); |
| 139 | + $data = $exif->getFilteredData(); |
| 140 | + if ( $data ) { |
| 141 | + $data['MEDIAWIKI_EXIF_VERSION'] = Exif::version(); |
| 142 | + $this->_meta['exif'] = $data; |
| 143 | + } |
153 | 144 | } |
154 | 145 | wfProfileOut( 'PagedTiffImage::retrieveMetaData' ); |
155 | 146 | } |
— | — | @@ -205,10 +196,15 @@ |
206 | 197 | $data['page_data'][$entry['page']] = $entry; |
207 | 198 | } |
208 | 199 | |
| 200 | + |
209 | 201 | $dump = preg_replace( '/\[BEGIN\](.+?)\[END\]/si', '', $dump ); |
210 | 202 | if ( strlen( $dump ) ) { |
211 | 203 | $errors = explode( "\n", $dump ); |
212 | 204 | foreach ( $errors as $error ) { |
| 205 | + $error = trim( $error ); |
| 206 | + if ( $error === '' ) |
| 207 | + continue; |
| 208 | + |
213 | 209 | $knownError = false; |
214 | 210 | foreach ( $wgTiffIdentifyRejectMessages as $msg ) { |
215 | 211 | if ( preg_match( $msg, trim( $error ) ) ) { |
— | — | @@ -234,31 +230,4 @@ |
235 | 231 | } |
236 | 232 | return $data; |
237 | 233 | } |
238 | | - |
239 | | - /** |
240 | | - * helper function of retrieveMetaData(). |
241 | | - * parses shell return from identify-verbose-command into an array. |
242 | | - */ |
243 | | - protected function parseVerbose( $dump ) { |
244 | | - $data = array(); |
245 | | - $dump = explode( "\n", $dump ); |
246 | | - $lastwhite = 0; |
247 | | - $lastkey = false; |
248 | | - foreach ( $dump as $line ) { |
249 | | - if ( preg_match( '/^(\s*?)(\w([\w\s]+?)?):(.*?)$/sim', $line, $res ) ) { |
250 | | - if ( $lastwhite == 0 || strlen( $res[1] ) == $lastwhite ) { |
251 | | - if ( strlen( trim( $res[4] ) ) ) { |
252 | | - $data[trim( $res[2] )] = trim( $res[4] ); |
253 | | - } else { |
254 | | - $data[trim( $res[2] )] = " Data:\n"; |
255 | | - } |
256 | | - $lastkey = trim( $res[2] ); |
257 | | - $lastwhite = strlen( $res[1] ); |
258 | | - } else { |
259 | | - $data[$lastkey] .= $line . "\n"; |
260 | | - } |
261 | | - } |
262 | | - } |
263 | | - return $data; |
264 | | - } |
265 | 234 | } |