Removed some unused/obsolete messages:
[lhc/web/wiklou.git] / thumb.php
1 <?php
2
3 /**
4 * PHP script to stream out an image thumbnail.
5 * If the file exists, we make do with abridged MediaWiki initialisation.
6 */
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' );
13
14 $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png.
15
16 require_once( 'Image.php' );
17 require_once( 'StreamFile.php' );
18
19 // Get input parameters
20
21 if ( get_magic_quotes_gpc() ) {
22 $fileName = stripslashes( $_REQUEST['f'] );
23 $width = stripslashes( $_REQUEST['w'] );
24 } else {
25 $fileName = $_REQUEST['f'];
26 $width = $_REQUEST['w'];
27 }
28
29 $pre_render= isset($_REQUEST['r']) && $_REQUEST['r']!="0";
30
31 // Some basic input validation
32
33 $width = intval( $width );
34 $fileName = strtr( $fileName, '\\/', '__' );
35
36 // Work out paths, carefully avoiding constructing an Image object because that won't work yet
37
38 $imagePath = wfImageDir( $fileName ) . '/' . $fileName;
39 $thumbName = "{$width}px-$fileName";
40 if ( $pre_render ) {
41 $thumbName .= '.png';
42 }
43 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
44
45 if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
46 wfStreamFile( $thumbPath );
47 // Can't log profiling data with no Setup.php
48 exit;
49 }
50
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' );
55
56 $img = Image::newFromName( $fileName );
57 if ( $img ) {
58 $thumb = $img->renderThumb( $width, false );
59 } else {
60 $thumb = false;
61 }
62
63 if ( $thumb && $thumb->path ) {
64 wfStreamFile( $thumb->path );
65 } else {
66 $badtitle = wfMsg( 'badtitle' );
67 $badtitletext = wfMsg( 'badtitletext' );
68 echo "<html><head>
69 <title>$badtitle</title>
70 <body>
71 <h1>$badtitle</h1>
72 <p>$badtitletext</p>
73 </body></html>";
74 }
75
76 wfProfileOut( 'thumb.php-render' );
77 wfProfileOut( 'thumb.php' );
78 wfLogProfilingData();
79
80 ?>