Fix regression in 28274: autodiscovery feed links were linked with feed=rss regardles...
[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 $errorMsg = false;
73 if ( !$img ) {
74 $errorMsg = wfMsg( 'badtitletext' );
75 } elseif ( !$thumb ) {
76 $errorMsg = wfMsgHtml( 'thumbnail_error', 'File::transform() returned false' );
77 } elseif ( $thumb->isError() ) {
78 $errorMsg = $thumb->getHtmlMsg();
79 } elseif ( !$thumb->getPath() ) {
80 $errorMsg = wfMsgHtml( 'thumbnail_error', 'No path supplied in thumbnail object' );
81 } elseif ( $thumb->getPath() == $img->getPath() ) {
82 $errorMsg = wfMsgHtml( 'thumbnail_error', 'Image was not scaled, ' .
83 'is the requested width bigger than the source?' );
84 } else {
85 wfStreamFile( $thumb->getPath() );
86 }
87 if ( $errorMsg !== false ) {
88 thumbInternalError( $errorMsg );
89 }
90
91 wfProfileOut( 'thumb.php-render' );
92 wfProfileOut( 'thumb.php' );
93 wfLogProfilingData();
94
95 //--------------------------------------------------------------------------
96
97 function thumbInternalError( $msg ) {
98 header( 'Cache-Control: no-cache' );
99 header( 'Content-Type: text/html; charset=utf-8' );
100 header( 'HTTP/1.1 500 Internal server error' );
101 echo <<<EOT
102 <html><head><title>Error generating thumbnail</title></head>
103 <body>
104 <h1>Error generating thumbnail</h1>
105 <p>
106 $msg
107 </p>
108 </body>
109 </html>
110
111 EOT;
112 }
113
114