4 * PHP script to stream out an image thumbnail.
8 define( 'MW_NO_OUTPUT_COMPRESSION', 1 );
9 require_once( './includes/WebStart.php' );
10 wfProfileIn( 'thumb.php' );
11 wfProfileIn( 'thumb.php-start' );
13 $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png.
15 require_once( "$IP/includes/StreamFile.php" );
17 // Get input parameters
18 if ( get_magic_quotes_gpc() ) {
19 $params = array_map( 'stripslashes', $_REQUEST );
24 $fileName = isset( $params['f'] ) ?
$params['f'] : '';
25 unset( $params['f'] );
27 // Backwards compatibility parameters
28 if ( isset( $params['w'] ) ) {
29 $params['width'] = $params['w'];
30 unset( $params['w'] );
32 if ( isset( $params['p'] ) ) {
33 $params['page'] = $params['p'];
35 unset( $params['r'] );
37 // Some basic input validation
38 $fileName = strtr( $fileName, '\\/', '__' );
40 // Stream the file if it exists already
42 $img = wfLocalFile( $fileName );
43 if ( $img && false != ( $thumbName = $img->thumbName( $params ) ) ) {
44 $thumbPath = $img->getThumbPath( $thumbName );
46 if ( is_file( $thumbPath ) ) {
47 wfStreamFile( $thumbPath );
52 } catch ( MWException
$e ) {
53 thumbInternalError( $e->getHTML() );
58 wfProfileOut( 'thumb.php-start' );
59 wfProfileIn( 'thumb.php-render' );
63 $thumb = $img->transform( $params, File
::RENDER_NOW
);
67 } catch( Exception
$ex ) {
68 // Tried to select a page on a non-paged file?
72 if ( $thumb && $thumb->getPath() && file_exists( $thumb->getPath() ) ) {
73 wfStreamFile( $thumb->getPath() );
76 $msg = wfMsg( 'badtitletext' );
77 } elseif ( !$thumb ) {
78 $msg = wfMsgHtml( 'thumbnail_error', 'File::transform() returned false' );
79 } elseif ( $thumb->isError() ) {
80 $msg = $thumb->getHtmlMsg();
81 } elseif ( !$thumb->getPath() ) {
82 $msg = wfMsgHtml( 'thumbnail_error', 'No path supplied in thumbnail object' );
84 $msg = wfMsgHtml( 'thumbnail_error', 'Output file missing' );
86 thumbInternalError( $msg );
89 wfProfileOut( 'thumb.php-render' );
90 wfProfileOut( 'thumb.php' );
93 //--------------------------------------------------------------------------
95 function thumbInternalError( $msg ) {
96 header( 'Cache-Control: no-cache' );
97 header( 'Content-Type: text/html; charset=utf-8' );
98 header( 'HTTP/1.1 500 Internal server error' );
100 <html><head><title>Error generating thumbnail</title></head>
102 <h1>Error generating thumbnail</h1>