Index: trunk/extensions/PagedTiffHandler/tests/PagedTiffHandlerTest.php |
— | — | @@ -120,10 +120,10 @@ |
121 | 121 | // lossy and lossless |
122 | 122 | $params = array('width'=>'100', 'height'=>'100', 'page'=>'1'); |
123 | 123 | $this->handler->normaliseParams($this->image, $params ); |
124 | | - $this->assertEquals($params['lossy'], '1'); |
| 124 | + $this->assertEquals($params['lossy'], 'lossy'); |
125 | 125 | $params = array('width'=>'100', 'height'=>'100', 'page'=>'2'); |
126 | 126 | $this->handler->normaliseParams($this->image, $params ); |
127 | | - $this->assertEquals($params['lossy'], '0'); |
| 127 | + $this->assertEquals($params['lossy'], 'lossless'); |
128 | 128 | // makeParamString |
129 | 129 | $this->assertEquals( |
130 | 130 | $this->handler->makeParamString( |
— | — | @@ -146,10 +146,15 @@ |
147 | 147 | $error = $this->handler->doTransform( wfFindFile( Title::newFromText( 'Image:Caspian.tif' ) ), dirname( __FILE__ ) . '/testImages/caspian.tif', 'Caspian.tif', array( 'width' => 100, 'height' => 100 ) ); |
148 | 148 | $this->assertEquals( $error->textMsg, wfMsg( 'thumbnail_error', wfMsg( 'tiff_bad_file' ) ) ); |
149 | 149 | // ---- Image information |
150 | | - // getThumbExtension |
151 | | - $this->assertEquals( $this->handler->getThumbExtension( $this->image, 2, 1 ), '.jpg' ); |
152 | | - // TODO: 0 is obviously the same as NULL |
153 | | - $this->assertEquals( $this->handler->getThumbExtension( $this->image, 2, '0' ), '.png' ); |
| 150 | + // getThumbType |
| 151 | + $type = $this->handler->getThumbType( '.tiff', 'image/tiff', array( 'lossy' => 'lossy' ) ); |
| 152 | + $this->assertEquals( $type[0], 'jpg' ); |
| 153 | + $this->assertEquals( $type[1], 'image/jpeg' ); |
| 154 | + |
| 155 | + $type = $this->handler->getThumbType( '.tiff', 'image/tiff', array( 'lossy' => 'lossless' ) ); |
| 156 | + $this->assertEquals( $type[0], 'png' ); |
| 157 | + $this->assertEquals( $type[1], 'image/png' ); |
| 158 | + |
154 | 159 | // getLongDesc |
155 | 160 | if ( $wgLanguageCode == 'de' ) { |
156 | 161 | $this->assertEquals( $this->handler->getLongDesc( $this->image ), wfMsg( 'tiff-file-info-size', '1.024', '768', '2,64 MB', 'image/tiff', '1' ) ); |
Index: trunk/extensions/PagedTiffHandler/PagedTiffHandler_body.php |
— | — | @@ -122,13 +122,11 @@ |
123 | 123 | |
124 | 124 | /** |
125 | 125 | * Maps MagicWord-IDs to parameters. |
126 | | - * Parameter 'lossy' was added. |
| 126 | + * In this case, width, page, and lossy. |
127 | 127 | */ |
128 | 128 | function getParamMap() { |
129 | | - // FIXME: This function is unused and should probably be a static member anyway |
130 | 129 | return array( |
131 | 130 | 'img_width' => 'width', |
132 | | - // @todo check height ## MediaWiki doesn't have a MagicWord-ID for height, appears to be a bug. ^SU |
133 | 131 | 'img_page' => 'page', |
134 | 132 | 'img_lossy' => 'lossy', |
135 | 133 | ); |
— | — | @@ -158,18 +156,11 @@ |
159 | 157 | * Page number was added. |
160 | 158 | */ |
161 | 159 | function makeParamString( $params ) { |
162 | | - $page = isset( $params['page'] ) ? $params['page'] : 1; |
163 | | - if ( !isset( $params['width'] ) ) { |
| 160 | + if ( !isset( $params['width'] ) || !isset( $params['lossy'] ) || !isset( $params['page'] )) { |
164 | 161 | return false; |
165 | 162 | } |
166 | 163 | |
167 | | - if ( !isset( $params['lossy'] ) || in_array( $params['lossy'], array( 1, '1', 'true', 'lossy' ) ) ) { |
168 | | - $lossy = 'lossy'; |
169 | | - } else { |
170 | | - $lossy = 'lossless'; |
171 | | - } |
172 | | - |
173 | | - return "{$lossy}-page{$page}-{$params['width']}px"; |
| 164 | + return "{$params['lossy']}-page{$params['page']}-{$params['width']}px"; |
174 | 165 | } |
175 | 166 | |
176 | 167 | /** |
— | — | @@ -185,12 +176,12 @@ |
186 | 177 | } |
187 | 178 | |
188 | 179 | /** |
189 | | - * Lossy parameter added |
190 | | - * TODO: The purpose of this function is not yet fully clear. |
191 | | - */ |
192 | | - function getScriptParams( $params ) { # # wtf?? ^DK |
193 | | - // FIXME: This function is unused, seems to be useless, |
194 | | - // and could be replaced with an array_intersect() call |
| 180 | + * The function is used to specify which parameters to File::transform() should be |
| 181 | + * passed through to thumb.php, in the case where the configuration specifies |
| 182 | + * thumb.php is to be used (e.g. $wgThumbnailScriptPath !== false). You should |
| 183 | + * pass through the same parameters as in makeParamString(). |
| 184 | + */ |
| 185 | + function getScriptParams( $params ) { |
195 | 186 | return array( |
196 | 187 | 'width' => $params['width'], |
197 | 188 | 'page' => $params['page'], |
— | — | @@ -203,38 +194,37 @@ |
204 | 195 | * Standard values for page and lossy are added. |
205 | 196 | */ |
206 | 197 | function normaliseParams( $image, &$params ) { |
207 | | - $mimeType = $image->getMimeType(); |
208 | | - |
209 | | - if ( !isset( $params['width'] ) ) { |
| 198 | + $data = $this->getMetaArray( $image ); |
| 199 | + if ( !$data ) { |
210 | 200 | return false; |
211 | 201 | } |
212 | | - if ( !isset( $params['page'] ) || $params['page'] < 1 ) { |
213 | | - $params['page'] = 1; |
214 | | - } |
215 | | - if ( $params['page'] > $this->pageCount( $image ) ) { |
216 | | - $params['page'] = $this->pageCount( $image ); |
217 | | - } |
218 | | - if ( !isset( $params['lossy'] ) || $params['lossy'] == null ) { |
219 | | - $data = $this->getMetaArray( $image ); |
220 | | - if ( ( strtolower( $data['page_data'][$params['page']]['alpha'] ) == 'true' ) ) $params['lossy'] = '0'; |
221 | | - else $params['lossy'] = 1; |
222 | | - } |
223 | | - $size = PagedTiffImage::getPageSize( $this->getMetaArray( $image ), $params['page'] ); |
224 | | - $srcWidth = $size['width']; |
225 | | - $srcHeight = $size['height']; |
226 | 202 | |
227 | | - if ( isset( $params['height'] ) && $params['height'] != - 1 ) { |
228 | | - // If the image is in letter format and the height parameter is set, the width |
229 | | - // parameter is adjusted so the original ratio doesn't get messed up. This is |
230 | | - // so the thumbnails on an ImagePage don't mess up the layout. ^SU |
231 | | - if ( $params['width'] * $srcHeight > $params['height'] * $srcWidth ) { |
232 | | - $params['width'] = wfFitBoxWidth( $srcWidth, $srcHeight, $params['height'] ); |
| 203 | + if ( isset( $params['page'] ) ) { |
| 204 | + $pages = $data['page_amount']; |
| 205 | + |
| 206 | + if ( $params['page'] > $pages ) { |
| 207 | + $params['page'] = intval( $pages ); |
233 | 208 | } |
234 | 209 | } |
235 | | - $params['height'] = File::scaleHeight( $srcWidth, $srcHeight, $params['width'] ); |
236 | | - if ( !$this->validateThumbParams( $params['width'], $params['height'], $srcWidth, $srcHeight, $mimeType ) ) { |
| 210 | + |
| 211 | + if ( !parent::normaliseParams( $image, $params ) ) { |
237 | 212 | return false; |
238 | 213 | } |
| 214 | + |
| 215 | + if ( isset( $params['lossy'] ) ) { |
| 216 | + if ( in_array( $params['lossy'], array( 1, '1', 'true', 'lossy' ) ) ) { |
| 217 | + $params['lossy'] = 'lossy'; |
| 218 | + } else { |
| 219 | + $params['lossy'] = 'lossless'; |
| 220 | + } |
| 221 | + } else { |
| 222 | + if ( ( strtolower( $data['page_data'][$params['page']]['alpha'] ) == 'true' ) ) { |
| 223 | + $params['lossy'] = 'lossless'; |
| 224 | + } else { |
| 225 | + $params['lossy'] = 'lossy'; |
| 226 | + } |
| 227 | + } |
| 228 | + |
239 | 229 | return true; |
240 | 230 | } |
241 | 231 | |
— | — | @@ -245,15 +235,14 @@ |
246 | 236 | */ |
247 | 237 | function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) { |
248 | 238 | global $wgImageMagickConvertCommand, $wgTiffMaxEmbedFileResolution, $wgTiffUseVips, $wgTiffVipsCommand; |
249 | | - |
250 | 239 | $metadata = $image->getMetadata(); |
251 | 240 | |
252 | 241 | if ( !$metadata ) { |
253 | 242 | if ( $metadata == - 1 ) { |
254 | | - return $this->doThumbError( @$params['width'], @$params['height'], 'tiff_error_cached' ); # #test this ^DK |
| 243 | + return $this->doThumbError( $params['width'], $params['height'], 'tiff_error_cached' ); # #test this ^DK |
255 | 244 | // $wgCacheType = CACHE_DB |
256 | 245 | } |
257 | | - return $this->doThumbError( @$params['width'], @$params['height'], 'tiff_no_metadata' ); |
| 246 | + return $this->doThumbError( $params['width'], $params['height'], 'tiff_no_metadata' ); |
258 | 247 | } |
259 | 248 | if ( !$this->normaliseParams( $image, $params ) ) |
260 | 249 | return new TransformParameterError( $params ); |
— | — | @@ -264,10 +253,6 @@ |
265 | 254 | $srcPath = $image->getPath(); |
266 | 255 | $page = intval( $params['page'] ); |
267 | 256 | |
268 | | - $extension = $this->getThumbExtension( $image, $page, $params['lossy'] ); |
269 | | - $dstPath .= $extension; |
270 | | - $dstUrl .= $extension; |
271 | | - |
272 | 257 | if ( $flags & self::TRANSFORM_LATER ) { //pretend the thumbnail exists, let it be created by a 404-handler |
273 | 258 | return new ThumbnailImage( $image, $dstUrl, $width, $height, $dstPath, $page ); |
274 | 259 | } |
— | — | @@ -275,7 +260,7 @@ |
276 | 261 | $meta = unserialize( $metadata ); |
277 | 262 | |
278 | 263 | if ( !$this->extCheck( $meta, $error, $dstPath ) ) { |
279 | | - return $this->doThumbError( @$params['width'], @$params['height'], $error ); |
| 264 | + return $this->doThumbError( $params['width'], $params['height'], $error ); |
280 | 265 | } |
281 | 266 | |
282 | 267 | if ( is_file( $dstPath ) ) |
— | — | @@ -323,25 +308,14 @@ |
324 | 309 | } |
325 | 310 | |
326 | 311 | /** |
327 | | - * Decides (taking lossy parameter into account) the filetype of the thumbnail. |
328 | | - * If there is no lossy parameter (null = not set), the decision is made |
329 | | - * according to the presence of an alpha value. |
330 | | - * (alpha == true = png, alpha == false = jpg) |
| 312 | + * Get the thumbnail extension and MIME type for a given source MIME type |
| 313 | + * @return array thumbnail extension and MIME type |
331 | 314 | */ |
332 | | - function getThumbExtension( $image, $page, $lossy ) { |
333 | | - if ( $lossy === null ) { |
334 | | - $data = $this->getMetaArray( $image ); |
335 | | - if ( ( strtolower( $data['page_data'][$page]['alpha'] ) == 'true' ) ) { |
336 | | - return '.png'; |
337 | | - } else { |
338 | | - return '.jpg'; |
339 | | - } |
| 315 | + function getThumbType( $ext, $mime, $params ) { |
| 316 | + if ( $params[ 'lossy' ] == 'lossy' ) { |
| 317 | + return array( 'jpg', 'image/jpeg' ); |
340 | 318 | } else { |
341 | | - if ( in_array( $lossy, array( 1, '1', 'true', 'lossy' ) ) ) { |
342 | | - return '.jpg'; |
343 | | - } else { |
344 | | - return '.png'; |
345 | | - } |
| 319 | + return array( 'png', 'image/png' ); |
346 | 320 | } |
347 | 321 | } |
348 | 322 | |