Index: trunk/phase3/includes/media/Bitmap.php |
— | — | @@ -8,20 +8,31 @@ |
9 | 9 | * @ingroup Media |
10 | 10 | */ |
11 | 11 | class BitmapHandler extends ImageHandler { |
12 | | - function getParamMap() { |
| 12 | + /** |
| 13 | + * Override parent method to add crop to param map. |
| 14 | + */ |
| 15 | + public function getParamMap() { |
13 | 16 | return array( |
14 | 17 | 'img_width' => 'width', |
15 | 18 | 'img_crop' => 'crop', |
16 | 19 | ); |
17 | 20 | } |
18 | | - function validateParam( $name, $value ) { |
| 21 | + |
| 22 | + /** |
| 23 | + * Override param map to validate the crop param. |
| 24 | + */ |
| 25 | + public function validateParam( $name, $value ) { |
19 | 26 | if ( $name == 'crop' ) { |
20 | 27 | return $this->splitCropParam( $value ) !== false; |
21 | 28 | } else { |
22 | 29 | return parent::validateParam( $name, $value ); |
23 | 30 | } |
24 | 31 | } |
25 | | - function splitCropParam( $value ) { |
| 32 | + /** |
| 33 | + * Split the crop param into up to 4 parts and convert them to integers. |
| 34 | + * Returns false in case of malformed param. |
| 35 | + */ |
| 36 | + protected function splitCropParam( $value ) { |
26 | 37 | $parts = explode( 'x', $value ); |
27 | 38 | if ( count( $parts ) > 4 ) |
28 | 39 | return false; |
— | — | @@ -38,7 +49,11 @@ |
39 | 50 | return $parts; |
40 | 51 | } |
41 | 52 | |
42 | | - function parseParamString( $str ) { |
| 53 | + /** |
| 54 | + * Override parent method to check for optional crop parameter in param |
| 55 | + * string. |
| 56 | + */ |
| 57 | + public function parseParamString( $str ) { |
43 | 58 | $res = parent::parseParamString( $str ); |
44 | 59 | if ( $res === false ) { |
45 | 60 | $m = false; |
— | — | @@ -49,15 +64,19 @@ |
50 | 65 | } |
51 | 66 | } |
52 | 67 | } |
53 | | - function makeParamString( $params ) { |
| 68 | + /** |
| 69 | + * Add the crop parameter the string generated by the parent. |
| 70 | + */ |
| 71 | + public function makeParamString( $params ) { |
54 | 72 | $res = parent::makeParamString( $params ); |
55 | 73 | if ( !empty( $params['crop'] ) ) |
56 | 74 | $res .= '-'.implode( 'x', $params['crop'] ).'crop'; |
57 | 75 | return $res; |
58 | 76 | } |
59 | 77 | |
60 | | - function normaliseParams( $image, &$params ) { |
| 78 | + public function normaliseParams( $image, &$params ) { |
61 | 79 | global $wgMaxImageArea; |
| 80 | + # Parent fills in width, height and page and normalizes them. |
62 | 81 | if ( !parent::normaliseParams( $image, $params ) ) { |
63 | 82 | return false; |
64 | 83 | } |
— | — | @@ -115,7 +134,6 @@ |
116 | 135 | } |
117 | 136 | else |
118 | 137 | { |
119 | | - header("X-Size: {$targetWidth}x{$targetHeight}"); |
120 | 138 | $params['crop'] = $cropParams; |
121 | 139 | $params['height'] = $params['physicalHeight'] = File::scaleHeight( |
122 | 140 | $targetWidth, $targetHeight, $params['width'] ); |
— | — | @@ -128,13 +146,15 @@ |
129 | 147 | } |
130 | 148 | |
131 | 149 | |
132 | | - // Function that returns the number of pixels to be thumbnailed. |
133 | | - // Intended for animated GIFs to multiply by the number of frames. |
134 | | - function getImageArea( $image, $width, $height ) { |
| 150 | + /** |
| 151 | + * Function that returns the number of pixels to be thumbnailed. |
| 152 | + * Intended for animated GIFs to multiply by the number of frames. |
| 153 | + */ |
| 154 | + protected function getImageArea( $image, $width, $height ) { |
135 | 155 | return $width * $height; |
136 | 156 | } |
137 | 157 | |
138 | | - function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) { |
| 158 | + public function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) { |
139 | 159 | global $wgUseImageMagick, $wgImageMagickConvertCommand, $wgImageMagickTempDir; |
140 | 160 | global $wgCustomConvertCommand, $wgUseImageResize; |
141 | 161 | global $wgSharpenParameter, $wgSharpenReductionThreshold; |
— | — | @@ -341,13 +361,13 @@ |
342 | 362 | } |
343 | 363 | } |
344 | 364 | |
345 | | - static function imageJpegWrapper( $dst_image, $thumbPath ) { |
| 365 | + public static function imageJpegWrapper( $dst_image, $thumbPath ) { |
346 | 366 | imageinterlace( $dst_image ); |
347 | 367 | imagejpeg( $dst_image, $thumbPath, 95 ); |
348 | 368 | } |
349 | 369 | |
350 | 370 | |
351 | | - function getMetadata( $image, $filename ) { |
| 371 | + public function getMetadata( $image, $filename ) { |
352 | 372 | global $wgShowEXIF; |
353 | 373 | if( $wgShowEXIF && file_exists( $filename ) ) { |
354 | 374 | $exif = new Exif( $filename ); |
— | — | @@ -363,11 +383,11 @@ |
364 | 384 | } |
365 | 385 | } |
366 | 386 | |
367 | | - function getMetadataType( $image ) { |
| 387 | + public function getMetadataType( $image ) { |
368 | 388 | return 'exif'; |
369 | 389 | } |
370 | 390 | |
371 | | - function isMetadataValid( $image, $metadata ) { |
| 391 | + public function isMetadataValid( $image, $metadata ) { |
372 | 392 | global $wgShowEXIF; |
373 | 393 | if ( !$wgShowEXIF ) { |
374 | 394 | # Metadata disabled and so an empty field is expected |
— | — | @@ -395,7 +415,7 @@ |
396 | 416 | * @return array of strings |
397 | 417 | * @access private |
398 | 418 | */ |
399 | | - function visibleMetadataFields() { |
| 419 | + public function visibleMetadataFields() { |
400 | 420 | $fields = array(); |
401 | 421 | $lines = explode( "\n", wfMsgForContent( 'metadata-fields' ) ); |
402 | 422 | foreach( $lines as $line ) { |
— | — | @@ -408,7 +428,7 @@ |
409 | 429 | return $fields; |
410 | 430 | } |
411 | 431 | |
412 | | - function formatMetadata( $image ) { |
| 432 | + public function formatMetadata( $image ) { |
413 | 433 | $result = array( |
414 | 434 | 'visible' => array(), |
415 | 435 | 'collapsed' => array() |