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' );
15 require_once( 'Image.php' );
16 require_once( 'StreamFile.php' );
18 // Get input parameters
20 if ( get_magic_quotes_gpc() ) {
21 $fileName = stripslashes( $_REQUEST['f'] );
22 $width = stripslashes( $_REQUEST['w'] );
24 $fileName = $_REQUEST['f'];
25 $width = $_REQUEST['w'];
28 // Some basic input validation
30 $width = intval( $width );
31 $fileName = strtr( $fileName, '\\/', '__' );
33 // Work out paths, carefully avoiding constructing an Image object because that won't work yet
35 $imagePath = wfImageDir( $fileName ) . '/' . $fileName;
36 $thumbName = "{$width}px-$fileName";
37 if ( preg_match( '/\.svg$/', $fileName ) ) {
40 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
42 if ( file_exists( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
43 wfStreamFile( $thumbPath );
47 // OK, no valid thumbnail, time to get out the heavy machinery
48 require_once( 'Setup.php' );
50 $img = Image
::newFromName( $fileName );
52 $thumb = $img->renderThumb( $width, false );
57 if ( $thumb && $thumb->path
) {
58 wfStreamFile( $thumb->path
);
60 $badtitle = wfMsg( 'badtitle' );
61 $badtitletext = wfMsg( 'badtitletext' );
63 <title>$badtitle</title>