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 require_once( './includes/WebStart.php' );
9 wfProfileIn( 'thumb.php' );
10 wfProfileIn( 'thumb.php-start' );
11 require_once( 'GlobalFunctions.php' );
12 require_once( 'ImageFunctions.php' );
14 $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png.
16 require_once( 'Image.php' );
17 require_once( 'StreamFile.php' );
19 // Get input parameters
20 $fileName = isset( $_REQUEST['f'] ) ?
$_REQUEST['f'] : '';
21 $width = isset( $_REQUEST['w'] ) ?
intval( $_REQUEST['w'] ) : 0;
22 $page = isset( $_REQUEST['p'] ) ?
intval( $_REQUEST['p'] ) : null;
24 if ( get_magic_quotes_gpc() ) {
25 $fileName = stripslashes( $fileName );
28 $pre_render= isset($_REQUEST['r']) && $_REQUEST['r']!="0";
30 // Some basic input validation
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 ( ! is_null( $page ) ) {
38 $thumbName = 'page' . $page . '-' . $thumbName;
43 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
45 if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
46 wfStreamFile( $thumbPath );
47 // Can't log profiling data with no Setup.php
51 // OK, no valid thumbnail, time to get out the heavy machinery
52 wfProfileOut( 'thumb.php-start' );
53 require_once( 'Setup.php' );
54 wfProfileIn( 'thumb.php-render' );
56 $img = Image
::newFromName( $fileName );
59 if ( ! is_null( $page ) ) {
60 $img->selectPage( $page );
62 $thumb = $img->renderThumb( $width, false );
66 } catch( Exception
$ex ) {
67 // Tried to select a page on a non-paged file?
71 if ( $thumb && $thumb->path
) {
72 wfStreamFile( $thumb->path
);
74 $badtitle = wfMsg( 'badtitle' );
75 $badtitletext = wfMsg( 'badtitletext' );
76 header( 'Cache-Control: no-cache' );
77 header( 'Content-Type: text/html' );
79 <title>$badtitle</title>
87 wfProfileOut( 'thumb.php-render' );
88 wfProfileOut( 'thumb.php' );