4 * PHP script to stream out an image thumbnail.
6 define( 'MW_NO_OUTPUT_COMPRESSION', 1 );
7 require_once( './includes/WebStart.php' );
8 wfProfileIn( 'thumb.php' );
9 wfProfileIn( 'thumb.php-start' );
11 $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png.
13 require_once( "$IP/includes/StreamFile.php" );
15 // Get input parameters
16 if ( get_magic_quotes_gpc() ) {
17 $params = array_map( 'stripslashes', $_REQUEST );
22 $fileName = isset( $params['f'] ) ?
$params['f'] : '';
23 unset( $params['f'] );
25 // Backwards compatibility parameters
26 if ( isset( $params['w'] ) ) {
27 $params['width'] = $params['w'];
28 unset( $params['w'] );
30 if ( isset( $params['p'] ) ) {
31 $params['page'] = $params['p'];
33 unset( $params['r'] );
35 // Some basic input validation
36 $fileName = strtr( $fileName, '\\/', '__' );
38 // Stream the file if it exists already
40 $img = wfLocalFile( $fileName );
41 if ( $img && false != ( $thumbName = $img->thumbName( $params ) ) ) {
42 $thumbPath = $img->getThumbPath( $thumbName );
44 if ( is_file( $thumbPath ) ) {
45 wfStreamFile( $thumbPath );
50 } catch ( MWException
$e ) {
51 thumbInternalError( $e->getHTML() );
56 wfProfileOut( 'thumb.php-start' );
57 wfProfileIn( 'thumb.php-render' );
61 $thumb = $img->transform( $params, File
::RENDER_NOW
);
65 } catch( Exception
$ex ) {
66 // Tried to select a page on a non-paged file?
70 if ( $thumb && $thumb->getPath() && file_exists( $thumb->getPath() ) ) {
71 wfStreamFile( $thumb->getPath() );
74 $msg = wfMsg( 'badtitletext' );
75 } elseif ( !$thumb ) {
76 $msg = wfMsgHtml( 'thumbnail_error', 'File::transform() returned false' );
77 } elseif ( $thumb->isError() ) {
78 $msg = $thumb->getHtmlMsg();
79 } elseif ( !$thumb->getPath() ) {
80 $msg = wfMsgHtml( 'thumbnail_error', 'No path supplied in thumbnail object' );
82 $msg = wfMsgHtml( 'thumbnail_error', 'Output file missing' );
84 thumbInternalError( $msg );
87 wfProfileOut( 'thumb.php-render' );
88 wfProfileOut( 'thumb.php' );
91 //--------------------------------------------------------------------------
93 function thumbInternalError( $msg ) {
94 header( 'Cache-Control: no-cache' );
95 header( 'Content-Type: text/html; charset=utf-8' );
96 header( 'HTTP/1.1 500 Internal server error' );
98 <html><head><title>Error generating thumbnail</title></head>
100 <h1>Error generating thumbnail</h1>