4 * PHP script to stream out an image thumbnail.
5 * If the file exists, we make do with abridged MediaWiki initialisation.
8 define( 'MEDIAWIKI', true );
10 $wgNoOutputBuffer = true;
12 require_once( './includes/Defines.php' );
13 require_once( './LocalSettings.php' );
14 require_once( 'GlobalFunctions.php' );
16 $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png.
18 require_once( 'Image.php' );
19 require_once( 'StreamFile.php' );
21 // Get input parameters
23 if ( get_magic_quotes_gpc() ) {
24 $fileName = stripslashes( $_REQUEST['f'] );
25 $width = stripslashes( $_REQUEST['w'] );
27 $fileName = $_REQUEST['f'];
28 $width = $_REQUEST['w'];
31 $pre_render= isset($_REQUEST['r']) && $_REQUEST['r']!="0";
33 // Some basic input validation
35 $width = intval( $width );
36 $fileName = strtr( $fileName, '\\/', '__' );
38 // Work out paths, carefully avoiding constructing an Image object because that won't work yet
40 $imagePath = wfImageDir( $fileName ) . '/' . $fileName;
41 $thumbName = "{$width}px-$fileName";
45 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
47 if ( file_exists( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
48 wfStreamFile( $thumbPath );
52 // OK, no valid thumbnail, time to get out the heavy machinery
53 require_once( 'Setup.php' );
55 $img = Image
::newFromName( $fileName );
57 $thumb = $img->renderThumb( $width, false );
62 if ( $thumb && $thumb->path
) {
63 wfStreamFile( $thumb->path
);
65 $badtitle = wfMsg( 'badtitle' );
66 $badtitletext = wfMsg( 'badtitletext' );
68 <title>$badtitle</title>