Don't show the restricted pages header if you can't see any. It'll just make
[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
8 define( 'MEDIAWIKI', true );
9 unset( $IP );
10 $wgNoOutputBuffer = true;
11
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' );
17
18 // Get input parameters
19
20 if ( get_magic_quotes_gpc() ) {
21 $fileName = stripslashes( $_REQUEST['f'] );
22 $width = stripslashes( $_REQUEST['w'] );
23 } else {
24 $fileName = $_REQUEST['f'];
25 $width = $_REQUEST['w'];
26 }
27
28 // Some basic input validation
29
30 $width = intval( $width );
31 $fileName = strtr( $fileName, '\\/', '__' );
32
33 // Work out paths, carefully avoiding constructing an Image object because that won't work yet
34
35 $imagePath = wfImageDir( $fileName ) . '/' . $fileName;
36 $thumbName = "{$width}px-$fileName";
37 if ( preg_match( '/\.svg$/', $fileName ) ) {
38 $thumbName .= '.png';
39 }
40 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
41
42 if ( file_exists( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
43 wfStreamFile( $thumbPath );
44 exit;
45 }
46
47 // OK, no valid thumbnail, time to get out the heavy machinery
48 require_once( 'Setup.php' );
49
50 $img = Image::newFromName( $fileName );
51 if ( $img ) {
52 $thumb = $img->renderThumb( $width, false );
53 } else {
54 $thumb = false;
55 }
56
57 if ( $thumb && $thumb->path ) {
58 wfStreamFile( $thumb->path );
59 } else {
60 $badtitle = wfMsg( 'badtitle' );
61 $badtitletext = wfMsg( 'badtitletext' );
62 echo "<html><head>
63 <title>$badtitle</title>
64 <body>
65 <h1>$badtitle</h1>
66 <p>$badtitletext</p>
67 </body></html>";
68 }
69
70
71 ?>