Update OOjs UI to v0.1.0-pre (7d2507b267)
[lhc/web/wiklou.git] / thumb.php
1 <?php
2 /**
3 * PHP script to stream out an image thumbnail.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup Media
22 */
23
24 define( 'MW_NO_OUTPUT_COMPRESSION', 1 );
25 require __DIR__ . '/includes/WebStart.php';
26
27 // Don't use fancy mime detection, just check the file extension for jpg/gif/png
28 $wgTrivialMimeDetection = true;
29
30 if ( defined( 'THUMB_HANDLER' ) ) {
31 // Called from thumb_handler.php via 404; extract params from the URI...
32 wfThumbHandle404();
33 } else {
34 // Called directly, use $_GET params
35 wfThumbHandleRequest();
36 }
37
38 wfLogProfilingData();
39 // Commit and close up!
40 $factory = wfGetLBFactory();
41 $factory->commitMasterChanges();
42 $factory->shutdown();
43
44 //--------------------------------------------------------------------------
45
46 /**
47 * Handle a thumbnail request via query parameters
48 *
49 * @return void
50 */
51 function wfThumbHandleRequest() {
52 $params = get_magic_quotes_gpc()
53 ? array_map( 'stripslashes', $_GET )
54 : $_GET;
55
56 wfStreamThumb( $params ); // stream the thumbnail
57 }
58
59 /**
60 * Handle a thumbnail request via thumbnail file URL
61 *
62 * @return void
63 */
64 function wfThumbHandle404() {
65 global $wgArticlePath;
66
67 # Set action base paths so that WebRequest::getPathInfo()
68 # recognizes the "X" as the 'title' in ../thumb_handler.php/X urls.
69 # Note: If Custom per-extension repo paths are set, this may break.
70 $repo = RepoGroup::singleton()->getLocalRepo();
71 $oldArticlePath = $wgArticlePath;
72 $wgArticlePath = $repo->getZoneUrl( 'thumb' ) . '/$1';
73
74 $matches = WebRequest::getPathInfo();
75
76 $wgArticlePath = $oldArticlePath;
77
78 if ( !isset( $matches['title'] ) ) {
79 wfThumbError( 404, 'Could not determine the name of the requested thumbnail.' );
80 return;
81 }
82
83 $params = wfExtractThumbRequestInfo( $matches['title'] ); // basic wiki URL param extracting
84 if ( $params == null ) {
85 wfThumbError( 400, 'The specified thumbnail parameters are not recognized.' );
86 return;
87 }
88
89 wfStreamThumb( $params ); // stream the thumbnail
90 }
91
92 /**
93 * Stream a thumbnail specified by parameters
94 *
95 * @param array $params List of thumbnailing parameters. In addition to parameters
96 * passed to the MediaHandler, this may also includes the keys:
97 * f (for filename), archived (if archived file), temp (if temp file),
98 * w (alias for width), p (alias for page), r (ignored; historical),
99 * rel404 (path for render on 404 to verify hash path correct),
100 * thumbName (thumbnail name to potentially extract more parameters from
101 * e.g. 'lossy-page1-120px-Foo.tiff' would add page, lossy and width
102 * to the parameters)
103 * @return void
104 */
105 function wfStreamThumb( array $params ) {
106 global $wgVaryOnXFP;
107
108 $section = new ProfileSection( __METHOD__ );
109
110 $headers = array(); // HTTP headers to send
111
112 $fileName = isset( $params['f'] ) ? $params['f'] : '';
113
114 // Backwards compatibility parameters
115 if ( isset( $params['w'] ) ) {
116 $params['width'] = $params['w'];
117 unset( $params['w'] );
118 }
119 if ( isset( $params['p'] ) ) {
120 $params['page'] = $params['p'];
121 }
122
123 // Is this a thumb of an archived file?
124 $isOld = ( isset( $params['archived'] ) && $params['archived'] );
125 unset( $params['archived'] ); // handlers don't care
126
127 // Is this a thumb of a temp file?
128 $isTemp = ( isset( $params['temp'] ) && $params['temp'] );
129 unset( $params['temp'] ); // handlers don't care
130
131 // Some basic input validation
132 $fileName = strtr( $fileName, '\\/', '__' );
133
134 // Actually fetch the image. Method depends on whether it is archived or not.
135 if ( $isTemp ) {
136 $repo = RepoGroup::singleton()->getLocalRepo()->getTempRepo();
137 $img = new UnregisteredLocalFile( null, $repo,
138 # Temp files are hashed based on the name without the timestamp.
139 # The thumbnails will be hashed based on the entire name however.
140 # @todo fix this convention to actually be reasonable.
141 $repo->getZonePath( 'public' ) . '/' . $repo->getTempHashPath( $fileName ) . $fileName
142 );
143 } elseif ( $isOld ) {
144 // Format is <timestamp>!<name>
145 $bits = explode( '!', $fileName, 2 );
146 if ( count( $bits ) != 2 ) {
147 wfThumbError( 404, wfMessage( 'badtitletext' )->text() );
148 return;
149 }
150 $title = Title::makeTitleSafe( NS_FILE, $bits[1] );
151 if ( !$title ) {
152 wfThumbError( 404, wfMessage( 'badtitletext' )->text() );
153 return;
154 }
155 $img = RepoGroup::singleton()->getLocalRepo()->newFromArchiveName( $title, $fileName );
156 } else {
157 $img = wfLocalFile( $fileName );
158 }
159
160 // Check the source file title
161 if ( !$img ) {
162 wfThumbError( 404, wfMessage( 'badtitletext' )->text() );
163 return;
164 }
165
166 // Check permissions if there are read restrictions
167 $varyHeader = array();
168 if ( !in_array( 'read', User::getGroupPermissions( array( '*' ) ), true ) ) {
169 if ( !$img->getTitle() || !$img->getTitle()->userCan( 'read' ) ) {
170 wfThumbError( 403, 'Access denied. You do not have permission to access ' .
171 'the source file.' );
172 return;
173 }
174 $headers[] = 'Cache-Control: private';
175 $varyHeader[] = 'Cookie';
176 }
177
178 // Check if the file is hidden
179 if ( $img->isDeleted( File::DELETED_FILE ) ) {
180 wfThumbError( 404, "The source file '$fileName' does not exist." );
181 return;
182 }
183
184 // Do rendering parameters extraction from thumbnail name.
185 if ( isset( $params['thumbName'] ) ) {
186 $params = wfExtractThumbParams( $img, $params );
187 }
188 if ( $params == null ) {
189 wfThumbError( 400, 'The specified thumbnail parameters are not recognized.' );
190 return;
191 }
192
193 // Check the source file storage path
194 if ( !$img->exists() ) {
195 $redirectedLocation = false;
196 if ( !$isTemp ) {
197 // Check for file redirect
198 // Since redirects are associated with pages, not versions of files,
199 // we look for the most current version to see if its a redirect.
200 $possRedirFile = RepoGroup::singleton()->getLocalRepo()->findFile( $img->getName() );
201 if ( $possRedirFile && !is_null( $possRedirFile->getRedirected() ) ) {
202 $redirTarget = $possRedirFile->getName();
203 $targetFile = wfLocalFile( Title::makeTitleSafe( NS_FILE, $redirTarget ) );
204 if ( $targetFile->exists() ) {
205 $newThumbName = $targetFile->thumbName( $params );
206 if ( $isOld ) {
207 $newThumbUrl = $targetFile->getArchiveThumbUrl(
208 $bits[0] . '!' . $targetFile->getName(), $newThumbName );
209 } else {
210 $newThumbUrl = $targetFile->getThumbUrl( $newThumbName );
211 }
212 $redirectedLocation = wfExpandUrl( $newThumbUrl, PROTO_CURRENT );
213 }
214 }
215 }
216
217 if ( $redirectedLocation ) {
218 // File has been moved. Give redirect.
219 $response = RequestContext::getMain()->getRequest()->response();
220 $response->header( "HTTP/1.1 302 " . HttpStatus::getMessage( 302 ) );
221 $response->header( 'Location: ' . $redirectedLocation );
222 $response->header( 'Expires: ' .
223 gmdate( 'D, d M Y H:i:s', time() + 12 * 3600 ) . ' GMT' );
224 if ( $wgVaryOnXFP ) {
225 $varyHeader[] = 'X-Forwarded-Proto';
226 }
227 if ( count( $varyHeader ) ) {
228 $response->header( 'Vary: ' . implode( ', ', $varyHeader ) );
229 }
230 return;
231 }
232
233 // If its not a redirect that has a target as a local file, give 404.
234 wfThumbError( 404, "The source file '$fileName' does not exist." );
235 return;
236 } elseif ( $img->getPath() === false ) {
237 wfThumbError( 500, "The source file '$fileName' is not locally accessible." );
238 return;
239 }
240
241 // Check IMS against the source file
242 // This means that clients can keep a cached copy even after it has been deleted on the server
243 if ( !empty( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) ) {
244 // Fix IE brokenness
245 $imsString = preg_replace( '/;.*$/', '', $_SERVER["HTTP_IF_MODIFIED_SINCE"] );
246 // Calculate time
247 wfSuppressWarnings();
248 $imsUnix = strtotime( $imsString );
249 wfRestoreWarnings();
250 if ( wfTimestamp( TS_UNIX, $img->getTimestamp() ) <= $imsUnix ) {
251 header( 'HTTP/1.1 304 Not Modified' );
252 return;
253 }
254 }
255
256 $rel404 = isset( $params['rel404'] ) ? $params['rel404'] : null;
257 unset( $params['r'] ); // ignore 'r' because we unconditionally pass File::RENDER
258 unset( $params['f'] ); // We're done with 'f' parameter.
259 unset( $params['rel404'] ); // moved to $rel404
260
261 // Get the normalized thumbnail name from the parameters...
262 try {
263 $thumbName = $img->thumbName( $params );
264 if ( !strlen( $thumbName ) ) { // invalid params?
265 wfThumbError( 400, 'The specified thumbnail parameters are not valid.' );
266 return;
267 }
268 $thumbName2 = $img->thumbName( $params, File::THUMB_FULL_NAME ); // b/c; "long" style
269 } catch ( MWException $e ) {
270 wfThumbError( 500, $e->getHTML() );
271 return;
272 }
273
274 // For 404 handled thumbnails, we only use the the base name of the URI
275 // for the thumb params and the parent directory for the source file name.
276 // Check that the zone relative path matches up so squid caches won't pick
277 // up thumbs that would not be purged on source file deletion (bug 34231).
278 if ( $rel404 !== null ) { // thumbnail was handled via 404
279 if ( rawurldecode( $rel404 ) === $img->getThumbRel( $thumbName ) ) {
280 // Request for the canonical thumbnail name
281 } elseif ( rawurldecode( $rel404 ) === $img->getThumbRel( $thumbName2 ) ) {
282 // Request for the "long" thumbnail name; redirect to canonical name
283 $response = RequestContext::getMain()->getRequest()->response();
284 $response->header( "HTTP/1.1 301 " . HttpStatus::getMessage( 301 ) );
285 $response->header( 'Location: ' .
286 wfExpandUrl( $img->getThumbUrl( $thumbName ), PROTO_CURRENT ) );
287 $response->header( 'Expires: ' .
288 gmdate( 'D, d M Y H:i:s', time() + 7 * 86400 ) . ' GMT' );
289 if ( $wgVaryOnXFP ) {
290 $varyHeader[] = 'X-Forwarded-Proto';
291 }
292 if ( count( $varyHeader ) ) {
293 $response->header( 'Vary: ' . implode( ', ', $varyHeader ) );
294 }
295 return;
296 } else {
297 wfThumbError( 404, "The given path of the specified thumbnail is incorrect;
298 expected '" . $img->getThumbRel( $thumbName ) . "' but got '" .
299 rawurldecode( $rel404 ) . "'." );
300 return;
301 }
302 }
303
304 $dispositionType = isset( $params['download'] ) ? 'attachment' : 'inline';
305
306 // Suggest a good name for users downloading this thumbnail
307 $headers[] = "Content-Disposition: {$img->getThumbDisposition( $thumbName, $dispositionType )}";
308
309 if ( count( $varyHeader ) ) {
310 $headers[] = 'Vary: ' . implode( ', ', $varyHeader );
311 }
312
313 // Stream the file if it exists already...
314 $thumbPath = $img->getThumbPath( $thumbName );
315 if ( $img->getRepo()->fileExists( $thumbPath ) ) {
316 $img->getRepo()->streamFile( $thumbPath, $headers );
317 return;
318 }
319
320 $user = RequestContext::getMain()->getUser();
321 if ( !wfThumbIsStandard( $img, $params ) && $user->pingLimiter( 'renderfile-nonstandard' ) ) {
322 wfThumbError( 500, wfMessage( 'actionthrottledtext' ) );
323 return;
324 } elseif ( $user->pingLimiter( 'renderfile' ) ) {
325 wfThumbError( 500, wfMessage( 'actionthrottledtext' ) );
326 return;
327 }
328
329 // Actually generate a new thumbnail
330 list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName, $thumbPath );
331
332 // Check for thumbnail generation errors...
333 $msg = wfMessage( 'thumbnail_error' );
334 if ( !$thumb ) {
335 $errorMsg = $errorMsg ?: $msg->rawParams( 'File::transform() returned false' )->escaped();
336 } elseif ( $thumb->isError() ) {
337 $errorMsg = $thumb->getHtmlMsg();
338 } elseif ( !$thumb->hasFile() ) {
339 $errorMsg = $msg->rawParams( 'No path supplied in thumbnail object' )->escaped();
340 } elseif ( $thumb->fileIsSource() ) {
341 $errorMsg = $msg->
342 rawParams( 'Image was not scaled, is the requested width bigger than the source?' )->escaped();
343 }
344
345 if ( $errorMsg !== false ) {
346 wfThumbError( 500, $errorMsg );
347 } else {
348 // Stream the file if there were no errors
349 $thumb->streamFile( $headers );
350 }
351 }
352
353 /**
354 * Actually try to generate a new thumbnail
355 *
356 * @param File $file
357 * @param array $params
358 * @param string $thumbName
359 * @param string $thumbPath
360 * @return array (MediaTransformOutput|bool, string|bool error message HTML)
361 */
362 function wfGenerateThumbnail( File $file, array $params, $thumbName, $thumbPath ) {
363 global $wgMemc, $wgAttemptFailureEpoch;
364
365 $key = wfMemcKey( 'attempt-failures', $wgAttemptFailureEpoch,
366 $file->getRepo()->getName(), md5( $file->getName() ), md5( $thumbName ) );
367
368 // Check if this file keeps failing to render
369 if ( $wgMemc->get( $key ) >= 4 ) {
370 return array( false, wfMessage( 'thumbnail_image-failure-limit', 4 ) );
371 }
372
373 $done = false;
374 // Record failures on PHP fatals in addition to caching exceptions
375 register_shutdown_function( function() use ( &$done, $key ) {
376 if ( !$done ) { // transform() gave a fatal
377 global $wgMemc;
378 // Randomize TTL to reduce stampedes
379 $wgMemc->incrWithInit( $key, 3600 + mt_rand( 0, 300 ) );
380 }
381 } );
382
383 $thumb = false;
384 $errorHtml = false;
385
386 // Thumbnail isn't already there, so create the new thumbnail...
387 try {
388 $work = new PoolCounterWorkViaCallback( 'FileRender', sha1( $file->getName() ),
389 array(
390 'doWork' => function() use ( $file, $params ) {
391 return $file->transform( $params, File::RENDER_NOW );
392 },
393 'getCachedWork' => function() use ( $file, $params, $thumbPath ) {
394 // If the worker that finished made this thumbnail then use it.
395 // Otherwise, it probably made a different thumbnail for this file.
396 return $file->getRepo()->fileExists( $thumbPath )
397 ? $file->transform( $params, File::RENDER_NOW )
398 : false; // retry once more in exclusive mode
399 },
400 'fallback' => function() {
401 return wfMessage( 'generic-pool-error' )->parse();
402 },
403 'error' => function ( $status ) {
404 return $status->getHTML();
405 }
406 )
407 );
408 $result = $work->execute();
409 if ( $result instanceof MediaTransformOutput ) {
410 $thumb = $result;
411 } elseif ( is_string( $result ) ) { // error
412 $errorHtml = $result;
413 }
414 } catch ( Exception $e ) {
415 // Tried to select a page on a non-paged file?
416 }
417
418 $done = true; // no PHP fatal occured
419
420 if ( !$thumb || $thumb->isError() ) {
421 // Randomize TTL to reduce stampedes
422 $wgMemc->incrWithInit( $key, 3600 + mt_rand( 0, 300 ) );
423 }
424
425 return array( $thumb, $errorHtml );
426 }
427
428 /**
429 * Returns true if this thumbnail is one that MediaWiki generates
430 * links to on file description pages and possibly parser output.
431 *
432 * $params is considered non-standard if they involve a non-standard
433 * width or any non-default parameters aside from width and page number.
434 * The number of possible files with standard parameters is far less than
435 * that of all combinations; rate-limiting for them can thus be more generious.
436 *
437 * @param File $file
438 * @param array $params
439 * @return bool
440 */
441 function wfThumbIsStandard( File $file, array $params ) {
442 global $wgThumbLimits, $wgImageLimits;
443
444 $handler = $file->getHandler();
445 if ( !$handler || !isset( $params['width'] ) ) {
446 return false;
447 }
448
449 $basicParams = array();
450 if ( isset( $params['page'] ) ) {
451 $basicParams['page'] = $params['page'];
452 }
453
454 // Check if the width matches one of $wgThumbLimits
455 if ( in_array( $params['width'], $wgThumbLimits ) ) {
456 $normalParams = $basicParams + array( 'width' => $params['width'] );
457 // Append any default values to the map (e.g. "lossy", "lossless", ...)
458 $handler->normaliseParams( $file, $normalParams );
459 } else {
460 // If not, then check if the width matchs one of $wgImageLimits
461 $match = false;
462 foreach ( $wgImageLimits as $pair ) {
463 $normalParams = $basicParams + array( 'width' => $pair[0], 'height' => $pair[1] );
464 // Decide whether the thumbnail should be scaled on width or height.
465 // Also append any default values to the map (e.g. "lossy", "lossless", ...)
466 $handler->normaliseParams( $file, $normalParams );
467 // Check if this standard thumbnail size maps to the given width
468 if ( $normalParams['width'] == $params['width'] ) {
469 $match = true;
470 break;
471 }
472 }
473 if ( !$match ) {
474 return false; // not standard for description pages
475 }
476 }
477
478 // Check that the given values for non-page, non-width, params are just defaults
479 foreach ( $params as $key => $value ) {
480 if ( !isset( $normalParams[$key] ) || $normalParams[$key] != $value ) {
481 return false;
482 }
483 }
484
485 return true;
486 }
487
488 /**
489 * Convert pathinfo type parameter, into normal request parameters
490 *
491 * So for example, if the request was redirected from
492 * /w/images/thumb/a/ab/Foo.png/120px-Foo.png. The $thumbRel parameter
493 * of this function would be set to "a/ab/Foo.png/120px-Foo.png".
494 * This method is responsible for turning that into an array
495 * with the folowing keys:
496 * * f => the filename (Foo.png)
497 * * rel404 => the whole thing (a/ab/Foo.png/120px-Foo.png)
498 * * archived => 1 (If the request is for an archived thumb)
499 * * temp => 1 (If the file is in the "temporary" zone)
500 * * thumbName => the thumbnail name, including parameters (120px-Foo.png)
501 *
502 * Transform specific parameters are set later via wfExtractThumbParams().
503 *
504 * @param string $thumbRel Thumbnail path relative to the thumb zone
505 * @return array|null Associative params array or null
506 */
507 function wfExtractThumbRequestInfo( $thumbRel ) {
508 $repo = RepoGroup::singleton()->getLocalRepo();
509
510 $hashDirReg = $subdirReg = '';
511 for ( $i = 0; $i < $repo->getHashLevels(); $i++ ) {
512 $subdirReg .= '[0-9a-f]';
513 $hashDirReg .= "$subdirReg/";
514 }
515
516 // Check if this is a thumbnail of an original in the local file repo
517 if ( preg_match( "!^((archive/)?$hashDirReg([^/]*)/([^/]*))$!", $thumbRel, $m ) ) {
518 list( /*all*/, $rel, $archOrTemp, $filename, $thumbname ) = $m;
519 // Check if this is a thumbnail of an temp file in the local file repo
520 } elseif ( preg_match( "!^(temp/)($hashDirReg([^/]*)/([^/]*))$!", $thumbRel, $m ) ) {
521 list( /*all*/, $archOrTemp, $rel, $filename, $thumbname ) = $m;
522 } else {
523 return null; // not a valid looking thumbnail request
524 }
525
526 $params = array( 'f' => $filename, 'rel404' => $rel );
527 if ( $archOrTemp === 'archive/' ) {
528 $params['archived'] = 1;
529 } elseif ( $archOrTemp === 'temp/' ) {
530 $params['temp'] = 1;
531 }
532
533 $params['thumbName'] = $thumbname;
534 return $params;
535 }
536
537 /**
538 * Convert a thumbnail name (122px-foo.png) to parameters, using
539 * file handler.
540 *
541 * @param File $file File object for file in question
542 * @param array $param Array of parameters so far
543 * @return array Parameters array with more parameters
544 */
545 function wfExtractThumbParams( $file, $params ) {
546 if ( !isset( $params['thumbName'] ) ) {
547 throw new MWException( "No thumbnail name passed to wfExtractThumbParams" );
548 }
549
550 $thumbname = $params['thumbName'];
551 unset( $params['thumbName'] );
552
553 // Do the hook first for older extensions that rely on it.
554 if ( !wfRunHooks( 'ExtractThumbParameters', array( $thumbname, &$params ) ) ) {
555 // Check hooks if parameters can be extracted
556 // Hooks return false if they manage to *resolve* the parameters
557 // This hook should be considered deprecated
558 wfDeprecated( 'ExtractThumbParameters', '1.22' );
559 return $params; // valid thumbnail URL (via extension or config)
560 }
561
562 // FIXME: Files in the temp zone don't set a mime type, which means
563 // they don't have a handler. Which means we can't parse the param
564 // string. However, not a big issue as what good is a param string
565 // if you have no handler to make use of the param string and
566 // actually generate the thumbnail.
567 $handler = $file->getHandler();
568
569 // Based on UploadStash::parseKey
570 $fileNamePos = strrpos( $thumbname, $params['f'] );
571 if ( $fileNamePos === false ) {
572 // Maybe using a short filename? (see FileRepo::nameForThumb)
573 $fileNamePos = strrpos( $thumbname, 'thumbnail' );
574 }
575
576 if ( $handler && $fileNamePos !== false ) {
577 $paramString = substr( $thumbname, 0, $fileNamePos - 1 );
578 $extraParams = $handler->parseParamString( $paramString );
579 if ( $extraParams !== false ) {
580 return $params + $extraParams;
581 }
582 }
583
584 // As a last ditch fallback, use the traditional common parameters
585 if ( preg_match( '!^(page(\d*)-)*(\d*)px-[^/]*$!', $thumbname, $matches ) ) {
586 list( /* all */, $pagefull, $pagenum, $size ) = $matches;
587 $params['width'] = $size;
588 if ( $pagenum ) {
589 $params['page'] = $pagenum;
590 }
591 return $params; // valid thumbnail URL
592 }
593 return null;
594 }
595
596 /**
597 * Output a thumbnail generation error message
598 *
599 * @param int $status
600 * @param string $msg
601 * @return void
602 */
603 function wfThumbError( $status, $msg ) {
604 global $wgShowHostnames;
605
606 header( 'Cache-Control: no-cache' );
607 header( 'Content-Type: text/html; charset=utf-8' );
608 if ( $status == 404 ) {
609 header( 'HTTP/1.1 404 Not found' );
610 } elseif ( $status == 403 ) {
611 header( 'HTTP/1.1 403 Forbidden' );
612 header( 'Vary: Cookie' );
613 } else {
614 header( 'HTTP/1.1 500 Internal server error' );
615 }
616 if ( $wgShowHostnames ) {
617 header( 'X-MW-Thumbnail-Renderer: ' . wfHostname() );
618 $url = htmlspecialchars( isset( $_SERVER['REQUEST_URI'] ) ? $_SERVER['REQUEST_URI'] : '' );
619 $hostname = htmlspecialchars( wfHostname() );
620 $debug = "<!-- $url -->\n<!-- $hostname -->\n";
621 } else {
622 $debug = '';
623 }
624 echo <<<EOT
625 <html><head><title>Error generating thumbnail</title></head>
626 <body>
627 <h1>Error generating thumbnail</h1>
628 <p>
629 $msg
630 </p>
631 $debug
632 </body>
633 </html>
634
635 EOT;
636 }