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 if ( isset( $_REQUEST['GLOBALS'] ) ) {
11 echo '<a href="http://www.hardened-php.net/index.76.html">$GLOBALS overwrite vulnerability</a>';
15 define( 'MW_NO_OUTPUT_BUFFER', true );
17 require_once( './includes/Defines.php' );
18 require_once( './LocalSettings.php' );
19 require_once( 'GlobalFunctions.php' );
20 require_once( 'ImageFunctions.php' );
22 $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png.
24 require_once( 'Image.php' );
25 require_once( 'StreamFile.php' );
27 // Get input parameters
29 if ( get_magic_quotes_gpc() ) {
30 $fileName = stripslashes( $_REQUEST['f'] );
31 $width = stripslashes( $_REQUEST['w'] );
33 $fileName = $_REQUEST['f'];
34 $width = $_REQUEST['w'];
37 $pre_render= isset($_REQUEST['r']) && $_REQUEST['r']!="0";
39 // Some basic input validation
41 $width = intval( $width );
42 $fileName = strtr( $fileName, '\\/', '__' );
44 // Work out paths, carefully avoiding constructing an Image object because that won't work yet
46 $imagePath = wfImageDir( $fileName ) . '/' . $fileName;
47 $thumbName = "{$width}px-$fileName";
51 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
53 if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
54 wfStreamFile( $thumbPath );
58 // OK, no valid thumbnail, time to get out the heavy machinery
59 require_once( 'Setup.php' );
60 wfProfileIn( 'thumb.php' );
62 $img = Image
::newFromName( $fileName );
64 $thumb = $img->renderThumb( $width, false );
69 if ( $thumb && $thumb->path
) {
70 wfStreamFile( $thumb->path
);
72 $badtitle = wfMsg( 'badtitle' );
73 $badtitletext = wfMsg( 'badtitletext' );
75 <title>$badtitle</title>
82 wfProfileOut( 'thumb.php' );