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
22 if ( get_magic_quotes_gpc() ) {
23 $fileName = stripslashes( $_REQUEST['f'] );
24 $width = stripslashes( $_REQUEST['w'] );
25 if ( isset( $_REQUEST['p'] ) ) { // optional page number
26 $page = stripslashes( $_REQUEST['p'] );
29 $fileName = $_REQUEST['f'];
30 $width = $_REQUEST['w'];
31 if ( isset( $_REQUEST['p'] ) ) { // optional page number
32 $page = $_REQUEST['p'] ;
36 $pre_render= isset($_REQUEST['r']) && $_REQUEST['r']!="0";
38 // Some basic input validation
40 $width = intval( $width );
41 if ( ! is_null( $page ) ) {
42 $page = intval( $page );
44 $fileName = strtr( $fileName, '\\/', '__' );
46 // Work out paths, carefully avoiding constructing an Image object because that won't work yet
48 $imagePath = wfImageDir( $fileName ) . '/' . $fileName;
49 $thumbName = "{$width}px-$fileName";
50 if ( ! is_null( $page ) ) {
51 $thumbName = 'page' . $page . '-' . $thumbName;
56 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
58 if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
59 wfStreamFile( $thumbPath );
60 // Can't log profiling data with no Setup.php
64 // OK, no valid thumbnail, time to get out the heavy machinery
65 wfProfileOut( 'thumb.php-start' );
66 require_once( 'Setup.php' );
67 wfProfileIn( 'thumb.php-render' );
69 $img = Image
::newFromName( $fileName );
71 if ( ! is_null( $page ) ) {
72 $img->selectPage( $page );
74 $thumb = $img->renderThumb( $width, false );
79 if ( $thumb && $thumb->path
) {
80 wfStreamFile( $thumb->path
);
82 $badtitle = wfMsg( 'badtitle' );
83 $badtitletext = wfMsg( 'badtitletext' );
85 <title>$badtitle</title>
92 wfProfileOut( 'thumb.php-render' );
93 wfProfileOut( 'thumb.php' );