Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | /** |
49 | 49 | * Customize the thumbnail shell command. |
50 | 50 | */ |
51 | | - static function renderCommand( &$cmd, $srcPath, $dstPath, $page, $width, $height ) { |
| 51 | + static function renderCommand( &$cmd, $srcPath, $dstPath, $page, $width, $height ) { ### why? ^DK |
52 | 52 | return true; |
53 | 53 | } |
54 | 54 | |
— | — | @@ -72,7 +72,7 @@ |
73 | 73 | function check( $saveName, $tempName, &$error ) { |
74 | 74 | global $wgTiffMaxEmbedFiles, $wgTiffMaxMetaSize, $wgMaxUploadSize, $wgTiffRejectOnError, $wgTiffRejectOnWarning, |
75 | 75 | $wgTiffUseTiffReader, $wgTiffReaderPath, $wgTiffReaderCheckEofForJS; |
76 | | - if (!(substr($saveName, -5, 5)=='.tiff' || substr($saveName, -4, 4)=='.tif')) return true; |
| 76 | + if (!(substr($saveName, -5, 5)=='.tiff' || substr($saveName, -4, 4)=='.tif')) return true; ### why? ^DK |
77 | 77 | wfLoadExtensionMessages( 'PagedTiffHandler' ); |
78 | 78 | if($wgTiffUseTiffReader) { |
79 | 79 | require_once($wgTiffReaderPath.'/TiffReader.php'); |
— | — | @@ -114,6 +114,7 @@ |
115 | 115 | |
116 | 116 | //NOTE: in future, it will become possible to pass parameters |
117 | 117 | //$error = array( 'tiff_bad_file' , join('<br />', $meta['errors']) ); |
| 118 | + ### does that work now? ^DK |
118 | 119 | |
119 | 120 | wfDebug( __METHOD__.": tiff_bad_file ($saveName) " . join('; ', $meta['errors']) . "\n" ); |
120 | 121 | return false; |
— | — | @@ -138,7 +139,8 @@ |
139 | 140 | function getParamMap() { |
140 | 141 | return array( |
141 | 142 | 'img_width' => 'width', |
142 | | - // @todo check height |
| 143 | + // @todo check height ### height!! ^DK |
| 144 | + ## Die Methode gibt nur die ParamMap für die MagicWordIDs zurück. Es gibt keine MagicWordID für height. ^SU |
143 | 145 | 'img_page' => 'page', |
144 | 146 | 'img_lossy' => 'lossy', |
145 | 147 | ); |
— | — | @@ -157,10 +159,10 @@ |
158 | 160 | } |
159 | 161 | return false; |
160 | 162 | } |
161 | | - if ( $value <= 0 ) { |
| 163 | + if ( $value <= 0 || $value > PHP_INT_MAX ) { ## check against integer overflow ^SU |
162 | 164 | return false; |
163 | 165 | } else { |
164 | | - return true; |
| 166 | + return true; ## spills at 65536?? ^DK |
165 | 167 | } |
166 | 168 | } else { |
167 | 169 | return false; |
— | — | @@ -176,7 +178,8 @@ |
177 | 179 | if ( !isset( $params['width'] ) ) { |
178 | 180 | return false; |
179 | 181 | } |
180 | | - return "page{$page}-{$params['width']}px"; |
| 182 | + $lossy = isset( $params['lossy'] ) && $params['lossy'] ? 'lossy' : 'lossless'; |
| 183 | + return "{$lossy}-page{$page}-{$params['width']}px"; |
181 | 184 | } |
182 | 185 | |
183 | 186 | /** |
— | — | @@ -184,8 +187,8 @@ |
185 | 188 | */ |
186 | 189 | function parseParamString( $str ) { |
187 | 190 | $m = false; |
188 | | - if ( preg_match( '/^page(\d+)-(\d+)px$/', $str, $m ) ) { |
189 | | - return array( 'width' => $m[2], 'page' => $m[1] ); |
| 191 | + if ( preg_match( '/^(\w+)-page(\d+)-(\d+)px$/', $str, $m ) ) { |
| 192 | + return array( 'width' => $m[3], 'page' => $m[2], 'lossy' => $m[1] ); |
190 | 193 | } else { |
191 | 194 | return false; |
192 | 195 | } |
— | — | @@ -195,7 +198,7 @@ |
196 | 199 | * lossy-paramter added |
197 | 200 | * TODO: The purpose of this function is not yet fully clear. |
198 | 201 | */ |
199 | | - function getScriptParams( $params ) { |
| 202 | + function getScriptParams( $params ) { ## wtf?? ^DK |
200 | 203 | return array( |
201 | 204 | 'width' => $params['width'], |
202 | 205 | 'page' => $params['page'], |
— | — | @@ -229,7 +232,8 @@ |
230 | 233 | $srcHeight = $size['height']; |
231 | 234 | |
232 | 235 | if ( isset( $params['height'] ) && $params['height'] != -1 ) { |
233 | | - if ( $params['width'] * $srcHeight > $params['height'] * $srcWidth ) { |
| 236 | + ## checks if with the given ratio the image box should be fitted ^SU |
| 237 | + if ( $params['width'] * $srcHeight > $params['height'] * $srcWidth ) { ## huh?? what does this do? ^DK |
234 | 238 | $params['width'] = wfFitBoxWidth( $srcWidth, $srcHeight, $params['height'] ); |
235 | 239 | } |
236 | 240 | } |
— | — | @@ -253,17 +257,18 @@ |
254 | 258 | |
255 | 259 | if ( !$metadata ) { |
256 | 260 | if($metadata == -1) { |
257 | | - return $this->doThumbError( @$params['width'], @$params['height'], 'tiff_error_cached' ); |
| 261 | + return $this->doThumbError( @$params['width'], @$params['height'], 'tiff_error_cached' ); ##test this ^DK |
258 | 262 | } |
259 | 263 | return $this->doThumbError( @$params['width'], @$params['height'], 'tiff_no_metadata' ); |
260 | 264 | } |
261 | 265 | if ( !$this->normaliseParams( $image, $params ) ) |
262 | 266 | return new TransformParameterError( $params ); |
263 | 267 | |
264 | | - $width = $params['width']; |
265 | | - $height = $params['height']; |
| 268 | + ## get params an forces width, height and page to be integer |
| 269 | + $width = $params['width'] - 0; |
| 270 | + $height = $params['height'] - 0; |
266 | 271 | $srcPath = $image->getPath(); |
267 | | - $page = $params['page']; |
| 272 | + $page = $params['page'] - 0; |
268 | 273 | |
269 | 274 | $extension = $this->getThumbExtension($image, $page, $params['lossy']); |
270 | 275 | $dstPath .= $extension; |
— | — | @@ -282,13 +287,16 @@ |
283 | 288 | if(isset($meta['pages'][$page]['pixels']) && $meta['pages'][$page]['pixels'] > $wgTiffMaxEmbedFileResolution) |
284 | 289 | return $this->doThumbError( $width, $height, 'tiff_sourcefile_too_large' ); |
285 | 290 | |
| 291 | + if(($width * $height) > $wgTiffMaxEmbedFileResolution) |
| 292 | + return $this->doThumbError( $width, $height, 'tiff_targetfile_too_large' ); |
| 293 | + |
286 | 294 | if ( !wfMkdirParents( dirname( $dstPath ) ) ) |
287 | 295 | return $this->doThumbError( $width, $height, 'thumbnail_dest_directory' ); |
288 | 296 | |
289 | 297 | if($wgTiffUseVips) { |
290 | 298 | // tested in Linux |
291 | 299 | $cmd = wfEscapeShellArg( $wgTiffVipsCommand ); |
292 | | - $cmd .= ' im_resize_linear "'.$srcPath.':'.($page-1).'" '; |
| 300 | + $cmd .= ' im_resize_linear "'.wfEscapeShellArg( $srcPath ).':'.($page-1).'" '; |
293 | 301 | $cmd .= wfEscapeShellArg( $dstPath ); |
294 | 302 | $cmd .= " {$width} {$height} 2>&1"; |
295 | 303 | } |
— | — | @@ -392,7 +400,7 @@ |
393 | 401 | $wgLang->formatNum( $metadata['pages'][$page]['width'] ), |
394 | 402 | $wgLang->formatNum( $metadata['pages'][$page]['height'] ), |
395 | 403 | $wgLang->formatSize( $image->getSize() ), |
396 | | - 'image/tiff', |
| 404 | + $image->getMimeType(), |
397 | 405 | $page ); |
398 | 406 | } |
399 | 407 | return true; |
— | — | @@ -405,7 +413,8 @@ |
406 | 414 | function isMetadataValid( $image, $metadata ) { |
407 | 415 | if(!empty( $metadata ) && $metadata != serialize(array())) { |
408 | 416 | $meta = unserialize($metadata); |
409 | | - if(isset($meta['Pages']) && isset($meta['pages'])) { |
| 417 | + ## Sollte das wirklich geändert werden, werden bereits bestehende Bilder Fehler produzieren. ^SU |
| 418 | + if(isset($meta['Pages']) && isset($meta['pages'])) { # ['Pages'] UND ['pages']? wieso das denn? das ist verwirrend... ^DK |
410 | 419 | return true; |
411 | 420 | } |
412 | 421 | } |
— | — | @@ -419,7 +428,8 @@ |
420 | 429 | * @return array of strings |
421 | 430 | * @access private |
422 | 431 | */ |
423 | | - function visibleMetadataFields() { |
| 432 | + ## könnte in den ImageHandler ... ist bis jetzt aber nur im BitmapHandler implementiert. ^SU |
| 433 | + function visibleMetadataFields() { #sieht vollig generisch aus. gehört das nicht in die oberklasse? ^DK |
424 | 434 | $fields = array(); |
425 | 435 | $lines = explode( "\n", wfMsg( 'metadata-fields' ) ); |
426 | 436 | foreach( $lines as $line ) { |
— | — | @@ -490,7 +500,7 @@ |
491 | 501 | 'collapsed', |
492 | 502 | 'identify', |
493 | 503 | 'error', |
494 | | - join('<br />', $errors) |
| 504 | + join('<br />', $errors) |
495 | 505 | ); |
496 | 506 | } |
497 | 507 | if(isset($meta['warnings'])) { |
— | — | @@ -502,7 +512,7 @@ |
503 | 513 | 'collapsed', |
504 | 514 | 'identify', |
505 | 515 | 'warning', |
506 | | - join('<br />', $warnings) |
| 516 | + join('<br />', $warnings) |
507 | 517 | ); |
508 | 518 | } |
509 | 519 | return $result; |
— | — | @@ -512,9 +522,12 @@ |
513 | 523 | * Returns a PagedTiffImage or create a new one if don´t exist. |
514 | 524 | */ |
515 | 525 | static function getTiffImage( $image, $path ) { |
| 526 | + ## Wenn kein ImageObject übergeben wurde, wird ein TiffImage-Object anhand des Pfades erzeugt. |
| 527 | + ## Ist ein ImageObject vorhanden, wird geprüft, ob darin schon eine TiffImage-Instanz gespeichert wurde. |
| 528 | + ## Ist dies nicht der Fall, wird eine Instanz erstellt und im ImageObject gespeichert. ^SU |
516 | 529 | if ( !$image ) |
517 | | - $tiffimg = new PagedTiffImage( $path ); |
518 | | - elseif ( !isset( $image->tiffImage ) ) |
| 530 | + $tiffimg = new PagedTiffImage( $path ); |
| 531 | + elseif ( !isset( $image->tiffImage ) ) #wo kommt $image her, wofür ist es gut? könnte es evtl schon ein TiffImage sein? ^DK |
519 | 532 | $tiffimg = $image->tiffImage = new PagedTiffImage( $path ); |
520 | 533 | else |
521 | 534 | $tiffimg = $image->tiffImage; |
— | — | @@ -526,6 +539,8 @@ |
527 | 540 | * Returns an Array with the Image-Metadata. |
528 | 541 | */ |
529 | 542 | function getMetaArray( $image ) { |
| 543 | + # gehört das nicht ein einen lazy initializer in TiffImage::getMetaArray() oder so? ^DK |
| 544 | + # Nein. Die Methode holt die Metadaten aus dem MediaWiki-ImageObject und nicht aus dem TiffImage. ^SU |
530 | 545 | if ( isset( $image->tiffMetaArray ) ) |
531 | 546 | return $image->tiffMetaArray; |
532 | 547 | |