r68664 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68663‎ | r68664 | r68665 >
Date:16:15, 28 June 2010
Author:daniel
Status:ok
Tags:
Comment:
use internal Exif per default, as suggested by tim in a comment to bug 23258; also some more cleanup of metadata-handling
Modified paths:
  • /trunk/extensions/PagedTiffHandler/PagedTiffHandler.image.php (modified) (history)
  • /trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php (modified) (history)
  • /trunk/extensions/PagedTiffHandler/tests/PagedTiffHandlerTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PagedTiffHandler/tests/PagedTiffHandlerTest.php
@@ -191,10 +191,10 @@
192192 //this is also strtolower in PagedTiffHandler::getThumbExtension
193193 $this->assertEquals( strtolower( $metaArray['page_data'][1]['alpha'] ), 'false' );
194194 $this->assertEquals( strtolower( $metaArray['page_data'][2]['alpha'] ), 'true' );
195 - $this->assertEquals( $metaArray['exif']['Endianess'], 'MSB' );
 195+ $this->assertEquals( $metaArray['exif']['PhotometricInterpretation'], 2 ); //RGB
196196 // formatMetadata
197197 $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.
199199 }
200200
201201 }
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php
@@ -250,15 +250,26 @@
251251 return false;
252252 }
253253
 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+
254270 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 ) );
261272 } else {
262 - return join( ";\n", $errors_raw );
 273+ return trim( join( ";\n", $errors ) );
263274 }
264275 }
265276
@@ -533,19 +544,21 @@
534545 $errors = PagedTiffHandler::joinMessages( $errors_raw );
535546 self::addMeta( $result,
536547 'collapsed',
537 - 'identify',
 548+ 'metadata',
538549 'error',
539550 $errors
540551 );
 552+ //XXX: need translation for <metadata-error>
541553 }
542 - if ( isset( $meta['warnings'] ) ) {
 554+ if ( !empty( $meta['warnings'] ) ) {
543555 $warnings = PagedTiffHandler::joinMessages( $meta['warnings'] );
544556 self::addMeta( $result,
545557 'collapsed',
546 - 'identify',
 558+ 'metadata',
547559 'warning',
548560 $warnings
549561 );
 562+ //XXX: need translation for <metadata-warning>
550563 }
551564 return $result;
552565 }
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler.image.php
@@ -133,22 +133,13 @@
134134 $this->_meta['exif'][$data[1]] = $data[2];
135135 }
136136 } 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+ }
153144 }
154145 wfProfileOut( 'PagedTiffImage::retrieveMetaData' );
155146 }
@@ -205,10 +196,15 @@
206197 $data['page_data'][$entry['page']] = $entry;
207198 }
208199
 200+
209201 $dump = preg_replace( '/\[BEGIN\](.+?)\[END\]/si', '', $dump );
210202 if ( strlen( $dump ) ) {
211203 $errors = explode( "\n", $dump );
212204 foreach ( $errors as $error ) {
 205+ $error = trim( $error );
 206+ if ( $error === '' )
 207+ continue;
 208+
213209 $knownError = false;
214210 foreach ( $wgTiffIdentifyRejectMessages as $msg ) {
215211 if ( preg_match( $msg, trim( $error ) ) ) {
@@ -234,31 +230,4 @@
235231 }
236232 return $data;
237233 }
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 - }
265234 }

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68409passing thumbnail params to getThumbType, as suggested by TimStarling in a co...daniel16:01, 22 June 2010
r68418fixed thumbnail parameter handling, as suggested by TimStarling in a comment ...daniel17:40, 22 June 2010
r68661improved meta-data and error handling and persistance, as suggested by tim in...daniel14:41, 28 June 2010

Status & tagging log