r68712 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68711‎ | r68712 | r68713 >
Date:08:04, 29 June 2010
Author:daniel
Status:ok
Tags:
Comment:
style and comments; follow-up to r68661
Modified paths:
  • /trunk/extensions/PagedTiffHandler/PagedTiffHandler.image.php (modified) (history)
  • /trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php
@@ -60,8 +60,9 @@
6161 * - check for running-identify-service
6262 */
6363 static function check( $saveName, $tempName, &$error ) {
64 - global $wgTiffMaxEmbedFiles, $wgTiffMaxMetaSize, $wgMaxUploadSize, $wgTiffRejectOnError, $wgTiffRejectOnWarning,
65 - $wgTiffUseTiffReader, $wgTiffReaderPath, $wgTiffReaderCheckEofForJS;
 64+ global $wgTiffMaxEmbedFiles, $wgTiffMaxMetaSize, $wgMaxUploadSize,
 65+ $wgTiffRejectOnError, $wgTiffRejectOnWarning, $wgTiffUseTiffReader,
 66+ $wgTiffReaderPath, $wgTiffReaderCheckEofForJS;
6667 wfLoadExtensionMessages( 'PagedTiffHandler' );
6768 if ( $wgTiffUseTiffReader ) {
6869 $tr = new TiffReader( $tempName );
@@ -143,7 +144,7 @@
144145 if ( in_array( $name, array( 'width', 'height', 'page', 'lossy' ) ) ) {
145146 if ( $name == 'lossy' ) {
146147 return in_array( $value, array( 1, 0, '1', '0', 'true', 'false', 'lossy', 'lossless' ) );
147 - } elseif ( $value <= 0 || $value > 65535 ) { // ImageMagick hits an overflow for values over 65536
 148+ } elseif ( $value <= 0 || $value > 65535 ) { // ImageMagick overflows for values > 65536
148149 return false;
149150 } else {
150151 return true;
@@ -282,7 +283,8 @@
283284 * Supports extra parameters for multipage files and thumbnail type (lossless vs. lossy)
284285 */
285286 function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
286 - global $wgImageMagickConvertCommand, $wgTiffMaxEmbedFileResolution, $wgTiffUseVips, $wgTiffVipsCommand;
 287+ global $wgImageMagickConvertCommand, $wgTiffMaxEmbedFileResolution,
 288+ $wgTiffUseVips, $wgTiffVipsCommand;
287289
288290 $meta = $this->getMetaArray( $image );
289291 $errors = PagedTiffHandler::getMetadataErrors( $meta );
@@ -290,7 +292,8 @@
291293 if ( $errors ) {
292294 $errors = PagedTiffHandler::joinMessages( $errors );
293295 if ( is_string( $errors ) ) {
294 - return $this->doThumbError( $params, 'tiff_bad_file' ); #TODO: original error as param # #test this ^DK
 296+ // TODO: original error as param // TESTME
 297+ return $this->doThumbError( $params, 'tiff_bad_file' );
295298 } else {
296299 return $this->doThumbError( $params, 'tiff_no_metadata' );
297300 }
@@ -305,7 +308,8 @@
306309 $srcPath = $image->getPath();
307310 $page = intval( $params['page'] );
308311
309 - if ( $flags & self::TRANSFORM_LATER ) { //pretend the thumbnail exists, let it be created by a 404-handler
 312+ if ( $flags & self::TRANSFORM_LATER ) {
 313+ // pretend the thumbnail exists, let it be created by a 404-handler
310314 return new ThumbnailImage( $image, $dstUrl, $width, $height, $dstPath, $page );
311315 }
312316
@@ -318,7 +322,8 @@
319323 $height, $dstPath, $page );
320324 }
321325
322 - if ( isset( $meta['page_data'][$page]['pixels'] ) && $meta['page_data'][$page]['pixels'] > $wgTiffMaxEmbedFileResolution )
 326+ if ( isset( $meta['page_data'][$page]['pixels'] )
 327+ && $meta['page_data'][$page]['pixels'] > $wgTiffMaxEmbedFileResolution )
323328 return $this->doThumbError( $params, 'tiff_sourcefile_too_large' );
324329
325330 if ( ( $width * $height ) > $wgTiffMaxEmbedFileResolution )
@@ -388,21 +393,21 @@
389394 global $wgUser, $wgThumbLimits;
390395
391396 if ( empty( $params['width'] ) ) {
392 - // no width/height in the parameter array
 397+ // no usable width/height in the parameter array
393398 // only happens if we don't have image meta-data, and no
394399 // size was specified by the user.
395400 // we need to pick *some* size, and the preferred
396401 // thumbnail size seems sane.
397402 $sz = $wgUser->getOption( 'thumbsize' );
398403 $width = $wgThumbLimits[ $sz ];
399 - $height = $width; // we don't have a hight, and no aspect ratio. make it square.
 404+ $height = $width; // we don't have a hight or aspect ratio. make it square.
400405 } else {
401406 $width = intval( $params['width'] );
402407
403408 if ( !empty( $params['height'] ) ) {
404409 $height = intval( $params['height'] );
405410 } else {
406 - $height = $width; // we don't have a hight, and no aspect ratio. make it square.
 411+ $height = $width; // we don't have a hight or aspect ratio. make it square.
407412 }
408413 }
409414
@@ -459,8 +464,8 @@
460465 if ( !empty( $metadata ) && $metadata != serialize( array() ) ) {
461466 $meta = unserialize( $metadata );
462467 if ( isset( $meta['errors'] ) ) {
463 - //metadata contains an error message, but it's valid.
464 - //don't try to re-render until the error is resolved!
 468+ // metadata contains an error message, but it's valid.
 469+ // don't try to re-render until the error is resolved!
465470 return true;
466471 }
467472 if ( isset( $meta['page_amount'] ) && isset( $meta['page_data'] ) ) {
@@ -548,7 +553,7 @@
549554 'error',
550555 $errors
551556 );
552 - //XXX: need translation for <metadata-error>
 557+ // XXX: need translation for <metadata-error>
553558 }
554559 if ( !empty( $meta['warnings'] ) ) {
555560 $warnings = PagedTiffHandler::joinMessages( $meta['warnings'] );
@@ -558,7 +563,7 @@
559564 'warning',
560565 $warnings
561566 );
562 - //XXX: need translation for <metadata-warning>
 567+ // XXX: need translation for <metadata-warning>
563568 }
564569 return $result;
565570 }
@@ -570,8 +575,8 @@
571576 */
572577 static function getTiffImage( $image, $path ) {
573578 // If no Image object is passed, a TiffImage is created based on $path .
574 - // If there is an Image object, we check whether there's already a TiffImage instance in there;
575 - // if not, a new instance is created and stored in the Image object
 579+ // If there is an Image object, we check whether there's already a TiffImage
 580+ // instance in there; if not, a new instance is created and stored in the Image object
576581 if ( !$image ) {
577582 $tiffimg = new PagedTiffImage( $path );
578583 } elseif ( !isset( $image->tiffImage ) ) {
@@ -614,7 +619,8 @@
615620 * Returns false if unknown or if the document is not multi-page.
616621 */
617622 function getPageDimensions( $image, $page ) {
618 - // makeImageLink2 (Linker.php) sets $page to false if no page parameter in wiki code is set
 623+ // makeImageLink2 (Linker.php) sets $page to false if no page parameter
 624+ // is set in wiki code
619625 if ( !$page ) {
620626 $page = 1;
621627 }
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler.image.php
@@ -86,10 +86,8 @@
8787 if ( $wgImageMagickIdentifyCommand ) {
8888
8989 wfProfileIn( 'PagedTiffImage::retrieveMetaData' );
90 - /**
91 - * ImageMagick is used in order to get the basic metadata of embedded files.
92 - * This is not reliable in exiv2m since it is not possible to name a set of required fields.
93 - */
 90+
 91+ // ImageMagick is used to get the basic metadata of individual pages
9492 $cmd = wfEscapeShellArg( $wgImageMagickIdentifyCommand ) .
9593 ' -format "[BEGIN]page=%p\nalpha=%A\nalpha2=%r\nheight=%h\nwidth=%w\ndepth=%z[END]" ' .
9694 wfEscapeShellArg( $this->mFilename ) . ' 2>&1';
@@ -101,17 +99,19 @@
102100 if ( $retval ) {
103101 $data['errors'][] = "identify command failed: $cmd";
104102 wfDebug( __METHOD__ . ": identify command failed: $cmd\n" );
105 - return $data; //fail. we *need* that info
 103+ return $data; // fail. we *need* that info
106104 }
107105 $this->_meta = $this->convertDumpToArray( $dump );
108106 $this->_meta['exif'] = array();
109107
110108 if ( $wgTiffUseExiv ) {
 109+ // read EXIF, XMP, IPTC as name-tag => interpreted data
 110+ // -ignore unknown fields
 111+ // see exiv2-doc @link http://www.exiv2.org/sample.html
 112+ // NOTE: the linux version of exiv2 has a bug: it can only
 113+ // read one type of meta-data at a time, not all at once.
111114 $cmd = wfEscapeShellArg( $wgTiffExivCommand ) .
112 - ' -u -psix -Pnt ' . // read EXIF, XMP, IPTC as name-tag => interpreted data -ignore unknown fields
113 - // exiv2-doc @link http://www.exiv2.org/sample.html
114 - # # the linux version of exiv2 has a bug an this command doesn't work on it. ^SU
115 - wfEscapeShellArg( $this->mFilename );
 115+ ' -u -psix -Pnt ' . wfEscapeShellArg( $this->mFilename );
116116
117117 wfRunHooks( 'PagedTiffHandlerExivCommand', array( &$cmd, $this->mFilename ) );
118118
@@ -123,7 +123,7 @@
124124 if ( $retval ) {
125125 $data['errors'][] = "exiv command failed: $cmd";
126126 wfDebug( __METHOD__ . ": exiv command failed: $cmd\n" );
127 - //don't fail - we are missing info, but that's no reason to abort yet.
 127+ // don't fail - we are missing info, just report
128128 }
129129
130130 $result = array();
@@ -214,7 +214,7 @@
215215 }
216216 }
217217 if ( !$knownError ) {
218 - # # drop BypassMessages ^SU
 218+ // ignore messages that match $wgTiffIdentifyBypassMessages
219219 foreach ( $wgTiffIdentifyBypassMessages as $msg ) {
220220 if ( preg_match( $msg, trim( $error ) ) ) {
221221 // $data['warnings'][] = $error;

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r68661improved meta-data and error handling and persistance, as suggested by tim in...daniel14:41, 28 June 2010

Status & tagging log