* (bug 6023) Fixed mismatch of 0/NULL for wl_notificationtimestamp; now notification
[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 $p=null;
21
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'] );
27 }
28 } else {
29 $fileName = $_REQUEST['f'];
30 $width = $_REQUEST['w'];
31 if ( isset( $_REQUEST['p'] ) ) { // optional page number
32 $page = $_REQUEST['p'] ;
33 }
34 }
35
36 $pre_render= isset($_REQUEST['r']) && $_REQUEST['r']!="0";
37
38 // Some basic input validation
39
40 $width = intval( $width );
41 if ( ! is_null( $page ) ) {
42 $page = intval( $page );
43 }
44 $fileName = strtr( $fileName, '\\/', '__' );
45
46 // Work out paths, carefully avoiding constructing an Image object because that won't work yet
47
48 $imagePath = wfImageDir( $fileName ) . '/' . $fileName;
49 $thumbName = "{$width}px-$fileName";
50 if ( ! is_null( $page ) ) {
51 $thumbName = 'page' . $page . '-' . $thumbName;
52 }
53 if ( $pre_render ) {
54 $thumbName .= '.png';
55 }
56 $thumbPath = wfImageThumbDir( $fileName ) . '/' . $thumbName;
57
58 if ( is_file( $thumbPath ) && filemtime( $thumbPath ) >= filemtime( $imagePath ) ) {
59 wfStreamFile( $thumbPath );
60 // Can't log profiling data with no Setup.php
61 exit;
62 }
63
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' );
68
69 $img = Image::newFromName( $fileName );
70 if ( $img ) {
71 if ( ! is_null( $page ) ) {
72 $img->selectPage( $page );
73 }
74 $thumb = $img->renderThumb( $width, false );
75 } else {
76 $thumb = false;
77 }
78
79 if ( $thumb && $thumb->path ) {
80 wfStreamFile( $thumb->path );
81 } else {
82 $badtitle = wfMsg( 'badtitle' );
83 $badtitletext = wfMsg( 'badtitletext' );
84 echo "<html><head>
85 <title>$badtitle</title>
86 <body>
87 <h1>$badtitle</h1>
88 <p>$badtitletext</p>
89 </body></html>";
90 }
91
92 wfProfileOut( 'thumb.php-render' );
93 wfProfileOut( 'thumb.php' );
94 wfLogProfilingData();
95
96 ?>