4 * PHP script to stream out an image thumbnail.
5 * If the file exists, we make do with abridged MediaWiki initialisation.
9 define( 'MEDIAWIKI', true );
10 require_once( './includes/Defines.php' );
11 require_once( './LocalSettings.php' );
12 require_once( 'Image.php' );
13 require_once( 'StreamFile.php' );
15 // Get input parameters
17 if ( get_magic_quotes_gpc() ) {
18 $fileName = stripslashes( $_REQUEST['f'] );
19 $width = stripslashes( $_REQUEST['w'] );
21 $fileName = $_REQUEST['f'];
22 $width = $_REQUEST['w'];
25 // Some basic input validation
27 $width = intval( $width );
28 $fileName = strtr( $fileName, '\\/', '__' );
30 // Work out paths, carefully avoiding constructing an Image object because that won't work yet
32 $imagePath = wfImageDir( $fileName ) . '/' . $fileName;
33 $thumbName = "{$width}px-$fileName";
34 if ( preg_match( '/\.svg$/', $fileName ) ) {
37 $thumbPath = wfImageThumbDir( $thumbName ) . '/' . $thumbName;
39 if ( file_exists( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
40 wfStreamFile( $thumbPath );
44 // OK, no valid thumbnail, time to get out the heavy machinery
45 require_once( 'Setup.php' );
47 // Force renderThumb() to actually do something
48 $wgThumbnailScriptPath = false;
49 $wgSharedThumbnailScriptPath = false;
51 $img = Image
::newFromName( $fileName );
53 $thumb = $img->renderThumb( $width );
59 wfStreamFile( $thumb->path
);
61 $badtitle = wfMsg( 'badtitle' );
62 $badtitletext = wfMsg( 'badtitletext' );
64 <title>$badtitle</title>