(bug 2857) fixed parsing of lists in <pre> sections
[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
16 $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png.
17
18 require_once( 'Image.php' );
19 require_once( 'StreamFile.php' );
20
21 // Get input parameters
22
23 if ( get_magic_quotes_gpc() ) {
24 $fileName = stripslashes( $_REQUEST['f'] );
25 $width = stripslashes( $_REQUEST['w'] );
26 } else {
27 $fileName = $_REQUEST['f'];
28 $width = $_REQUEST['w'];
29 }
30
31 $pre_render= isset($_REQUEST['r']) && $_REQUEST['r']!="0";
32
33 // Some basic input validation
34
35 $width = intval( $width );
36 $fileName = strtr( $fileName, '\\/', '__' );
37
38 // Work out paths, carefully avoiding constructing an Image object because that won't work yet
39
40 $imagePath = wfImageDir( $fileName ) . '/' . $fileName;
41 $thumbName = "{$width}px-$fileName";
42 if ( $pre_render ) {
43 $thumbName .= '.png';
44 }
45 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
46
47 if ( file_exists( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
48 wfStreamFile( $thumbPath );
49 exit;
50 }
51
52 // OK, no valid thumbnail, time to get out the heavy machinery
53 require_once( 'Setup.php' );
54
55 $img = Image::newFromName( $fileName );
56 if ( $img ) {
57 $thumb = $img->renderThumb( $width, false );
58 } else {
59 $thumb = false;
60 }
61
62 if ( $thumb && $thumb->path ) {
63 wfStreamFile( $thumb->path );
64 } else {
65 $badtitle = wfMsg( 'badtitle' );
66 $badtitletext = wfMsg( 'badtitletext' );
67 echo "<html><head>
68 <title>$badtitle</title>
69 <body>
70 <h1>$badtitle</h1>
71 <p>$badtitletext</p>
72 </body></html>";
73 }
74
75
76 ?>