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