API: forgot to remove debugging statement
[lhc/web/wiklou.git] / thumb.php
1 <?php
2
3 /**
4 * PHP script to stream out an image thumbnail.
5 */
6 define( 'MW_NO_OUTPUT_COMPRESSION', 1 );
7 require_once( './includes/WebStart.php' );
8 wfProfileIn( 'thumb.php' );
9 wfProfileIn( 'thumb.php-start' );
10
11 $wgTrivialMimeDetection = true; //don't use fancy mime detection, just check the file extension for jpg/gif/png.
12
13 require_once( "$IP/includes/StreamFile.php" );
14
15 // Get input parameters
16 if ( get_magic_quotes_gpc() ) {
17 $params = array_map( 'stripslashes', $_REQUEST );
18 } else {
19 $params = $_REQUEST;
20 }
21
22 $fileName = isset( $params['f'] ) ? $params['f'] : '';
23 unset( $params['f'] );
24
25 // Backwards compatibility parameters
26 if ( isset( $params['w'] ) ) {
27 $params['width'] = $params['w'];
28 unset( $params['w'] );
29 }
30 if ( isset( $params['p'] ) ) {
31 $params['page'] = $params['p'];
32 }
33 unset( $params['r'] );
34
35 // Some basic input validation
36 $fileName = strtr( $fileName, '\\/', '__' );
37
38 // Stream the file if it exists already
39 try {
40 $img = wfLocalFile( $fileName );
41 if ( $img && false != ( $thumbName = $img->thumbName( $params ) ) ) {
42 $thumbPath = $img->getThumbPath( $thumbName );
43
44 if ( is_file( $thumbPath ) ) {
45 wfStreamFile( $thumbPath );
46 wfLogProfilingData();
47 exit;
48 }
49 }
50 } catch ( MWException $e ) {
51 thumbInternalError( $e->getHTML() );
52 wfLogProfilingData();
53 exit;
54 }
55
56 wfProfileOut( 'thumb.php-start' );
57 wfProfileIn( 'thumb.php-render' );
58
59 try {
60 if ( $img ) {
61 $thumb = $img->transform( $params, File::RENDER_NOW );
62 } else {
63 $thumb = false;
64 }
65 } catch( Exception $ex ) {
66 // Tried to select a page on a non-paged file?
67 $thumb = false;
68 }
69
70 if ( $thumb && $thumb->getPath() && file_exists( $thumb->getPath() ) ) {
71 wfStreamFile( $thumb->getPath() );
72 } else {
73 if ( !$img ) {
74 $msg = wfMsg( 'badtitletext' );
75 } elseif ( !$thumb ) {
76 $msg = wfMsgHtml( 'thumbnail_error', 'File::transform() returned false' );
77 } elseif ( $thumb->isError() ) {
78 $msg = $thumb->getHtmlMsg();
79 } elseif ( !$thumb->getPath() ) {
80 $msg = wfMsgHtml( 'thumbnail_error', 'No path supplied in thumbnail object' );
81 } else {
82 $msg = wfMsgHtml( 'thumbnail_error', 'Output file missing' );
83 }
84 thumbInternalError( $msg );
85 }
86
87 wfProfileOut( 'thumb.php-render' );
88 wfProfileOut( 'thumb.php' );
89 wfLogProfilingData();
90
91 //--------------------------------------------------------------------------
92
93 function thumbInternalError( $msg ) {
94 header( 'Cache-Control: no-cache' );
95 header( 'Content-Type: text/html; charset=utf-8' );
96 header( 'HTTP/1.1 500 Internal server error' );
97 echo <<<EOT
98 <html><head><title>Error generating thumbnail</title></head>
99 <body>
100 <h1>Error generating thumbnail</h1>
101 <p>
102 $msg
103 </p>
104 </body>
105 </html>
106
107 EOT;
108 }
109
110