Index: trunk/phase3/RELEASE-NOTES-1.19 |
— | — | @@ -15,6 +15,8 @@ |
16 | 16 | * (bug 27132) movefile right granted by default to registered users. |
17 | 17 | * Default cookie lifetime ($wgCookieExpiration) is increased to 180 days. |
18 | 18 | * (bug 31204) Removed old user.user_options |
| 19 | +* $wgMaxImageArea now applies to jpeg files if they are not scaled with |
| 20 | + ImageMagick. |
19 | 21 | |
20 | 22 | === New features in 1.19 === |
21 | 23 | * (bug 19838) Possibility to get all interwiki prefixes if the interwiki |
Index: trunk/phase3/includes/media/Bitmap.php |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | * @return bool |
23 | 23 | */ |
24 | 24 | function normaliseParams( $image, &$params ) { |
25 | | - global $wgMaxImageArea; |
| 25 | + |
26 | 26 | if ( !parent::normaliseParams( $image, $params ) ) { |
27 | 27 | return false; |
28 | 28 | } |
— | — | @@ -42,20 +42,44 @@ |
43 | 43 | return true; |
44 | 44 | } |
45 | 45 | } |
46 | | - |
| 46 | + |
| 47 | + return true; |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * Check if the file is smaller than the maximum image area for |
| 52 | + * thumbnailing. Check will always pass if the scaler is 'hookaborted' or |
| 53 | + * if the scaler is 'im' and the mime type is 'image/jpeg' |
| 54 | + * |
| 55 | + * @param File $image |
| 56 | + * @param string $scaler |
| 57 | + */ |
| 58 | + function checkImageArea( $image, $scaler ) { |
| 59 | + global $wgMaxImageArea; |
47 | 60 | # Don't thumbnail an image so big that it will fill hard drives and send servers into swap |
48 | 61 | # JPEG has the handy property of allowing thumbnailing without full decompression, so we make |
49 | 62 | # an exception for it. |
50 | | - # @todo FIXME: This actually only applies to ImageMagick |
51 | | - if ( $mimeType !== 'image/jpeg' && |
52 | | - $srcWidth * $srcHeight > $wgMaxImageArea ) |
| 63 | + |
| 64 | + |
| 65 | + if ( $image->getMimeType() == 'image/jpeg' && $scaler == 'im' ) |
53 | 66 | { |
54 | | - return false; |
| 67 | + # ImageMagick can efficiently downsize jpg images without loading |
| 68 | + # the entire file in memory |
| 69 | + return true; |
55 | 70 | } |
56 | | - |
57 | | - return true; |
| 71 | + |
| 72 | + if ( $scaler == 'hookaborted' ) |
| 73 | + { |
| 74 | + # If a hook wants to transform the image, it is responsible for |
| 75 | + # checking the image size, so abort here |
| 76 | + return true; |
| 77 | + } |
| 78 | + |
| 79 | + # Do the actual check |
| 80 | + return $this->getImageArea( $image, $image->getWidth(), $image->getHeight() ) <= $wgMaxImageArea; |
58 | 81 | } |
59 | 82 | |
| 83 | + |
60 | 84 | /** |
61 | 85 | * Extracts the width/height if the image will be scaled before rotating |
62 | 86 | * |
— | — | @@ -160,6 +184,12 @@ |
161 | 185 | wfDebug( __METHOD__ . ": Hook to BitmapHandlerTransform created an mto\n" ); |
162 | 186 | $scaler = 'hookaborted'; |
163 | 187 | } |
| 188 | + |
| 189 | + # Check max image area |
| 190 | + if ( !$this->checkImageArea( $image, $scaler ) ) |
| 191 | + { |
| 192 | + return new TransformParameterError( $params ); |
| 193 | + } |
164 | 194 | |
165 | 195 | switch ( $scaler ) { |
166 | 196 | case 'hookaborted': |