MediaWiki  REL1_22
MockBitmapHandler.php
Go to the documentation of this file.
00001 <?php
00024 class MockBitmapHandler extends BitmapHandler {
00025     function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
00026         return MockImageHandler::doFakeTransform( $this, $image, $dstPath, $dstUrl, $params, $flags );
00027     }
00028     function doClientImage( $image, $scalerParams ) {
00029             return $this->getClientScalingThumbnailImage( $image, $scalerParams );
00030     }
00031 }
00032 class MockSvgHandler extends SvgHandler {
00033     function doTransform( $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
00034         return MockImageHandler::doFakeTransform( $this, $image, $dstPath, $dstUrl, $params, $flags );
00035     }
00036 }
00044 class MockImageHandler {
00045 
00052     static function doFakeTransform( $that, $image, $dstPath, $dstUrl, $params, $flags = 0 ) {
00053         # Example of what we receive:
00054         # $image: LocalFile
00055         # $dstPath: /tmp/transform_7d0a7a2f1a09-1.jpg
00056         # $dstUrl : http://example.com/images/thumb/0/09/Bad.jpg/320px-Bad.jpg
00057         # $params:  width: 320,  descriptionUrl http://trunk.dev/wiki/File:Bad.jpg
00058 
00059         $that->normaliseParams( $image, $params );
00060 
00061         $scalerParams = array(
00062             # The size to which the image will be resized
00063             'physicalWidth' => $params['physicalWidth'],
00064             'physicalHeight' => $params['physicalHeight'],
00065             'physicalDimensions' => "{$params['physicalWidth']}x{$params['physicalHeight']}",
00066             # The size of the image on the page
00067             'clientWidth' => $params['width'],
00068             'clientHeight' => $params['height'],
00069             # Comment as will be added to the EXIF of the thumbnail
00070             'comment' => isset( $params['descriptionUrl'] ) ?
00071             "File source: {$params['descriptionUrl']}" : '',
00072             # Properties of the original image
00073             'srcWidth' => $image->getWidth(),
00074             'srcHeight' => $image->getHeight(),
00075             'mimeType' => $image->getMimeType(),
00076             'dstPath' => $dstPath,
00077             'dstUrl' => $dstUrl,
00078         );
00079 
00080         # In some cases, we do not bother generating a thumbnail.
00081         if ( !$image->mustRender() &&
00082             $scalerParams['physicalWidth'] == $scalerParams['srcWidth']
00083             && $scalerParams['physicalHeight'] == $scalerParams['srcHeight']
00084         ) {
00085             wfDebug( __METHOD__ . ": returning unscaled image\n" );
00086             // getClientScalingThumbnailImage is protected
00087             return $that->doClientImage( $image, $scalerParams );
00088         }
00089 
00090         return new ThumbnailImage( $image, $dstUrl, false, $params );
00091     }
00092 }