4 * PHP script to stream out an image thumbnail.
5 * If the file exists, we make do with abridged MediaWiki initialisation.
7 define( 'MW_NO_SETUP', 1 );
8 define( 'MW_NO_OUTPUT_COMPRESSION', 1 );
9 require_once( './includes/WebStart.php' );
10 wfProfileIn( 'thumb.php' );
11 wfProfileIn( 'thumb.php-start' );
12 require_once( './includes/GlobalFunctions.php' );
13 require_once( './includes/ImageFunctions.php' );
15 $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png.
17 require_once( './includes/Image.php' );
18 require_once( './includes/StreamFile.php' );
20 // Get input parameters
21 $fileName = isset( $_REQUEST['f'] ) ?
$_REQUEST['f'] : '';
22 $width = isset( $_REQUEST['w'] ) ?
intval( $_REQUEST['w'] ) : 0;
23 $page = isset( $_REQUEST['p'] ) ?
intval( $_REQUEST['p'] ) : null;
25 if ( get_magic_quotes_gpc() ) {
26 $fileName = stripslashes( $fileName );
29 $pre_render= isset($_REQUEST['r']) && $_REQUEST['r']!="0";
31 // Some basic input validation
32 $fileName = strtr( $fileName, '\\/', '__' );
34 // Work out paths, carefully avoiding constructing an Image object because that won't work yet
36 $imagePath = wfImageDir( $fileName ) . '/' . $fileName;
37 $thumbName = "{$width}px-$fileName";
38 if ( ! is_null( $page ) ) {
39 $thumbName = 'page' . $page . '-' . $thumbName;
44 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
46 if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
47 wfStreamFile( $thumbPath );
48 // Can't log profiling data with no Setup.php
52 // OK, no valid thumbnail, time to get out the heavy machinery
53 wfProfileOut( 'thumb.php-start' );
54 require_once( './includes/Setup.php' );
55 wfProfileIn( 'thumb.php-render' );
57 $img = Image
::newFromName( $fileName );
60 if ( ! is_null( $page ) ) {
61 $img->selectPage( $page );
63 $thumb = $img->renderThumb( $width, false );
67 } catch( Exception
$ex ) {
68 // Tried to select a page on a non-paged file?
72 if ( $thumb && $thumb->path
) {
73 wfStreamFile( $thumb->path
);
75 $badtitle = wfMsg( 'badtitle' );
76 $badtitletext = wfMsg( 'badtitletext' );
77 header( 'Cache-Control: no-cache' );
78 header( 'Content-Type: text/html; charset=utf-8' );
80 <title>$badtitle</title>
88 wfProfileOut( 'thumb.php-render' );
89 wfProfileOut( 'thumb.php' );