Index: trunk/extensions/VipsScaler/VipsTest.php |
— | — | @@ -8,15 +8,15 @@ |
9 | 9 | if ( !defined( 'MEDIAWIKI' ) ) exit( 1 ); |
10 | 10 | |
11 | 11 | /** |
12 | | - * The remote URL which will do the scaling. Use this to send scaling to an |
13 | | - * isolated set of servers. Set this to null to do the scaling locally. |
| 12 | + * The host to send the request to when doing the scaling remotely. Set this to |
| 13 | + * null to do the scaling on the same server that receives the request. |
14 | 14 | */ |
15 | | -$wgVipsThumbnailerUrl = null; |
| 15 | +$wgVipsThumbnailerHost = null; |
16 | 16 | |
17 | 17 | /** |
18 | | - * The host to send the request to when doing the scaling remotely. |
| 18 | + * The cache expiry time in seconds to use for images that we stream out. |
19 | 19 | */ |
20 | | -$wgVipsThumbnailerProxy = null; |
| 20 | +$wgVipsTestExpiry = 3600; |
21 | 21 | |
22 | 22 | /** Registration */ |
23 | 23 | $wgAutoloadClasses['SpecialVipsTest'] = "$dir/SpecialVipsTest.php"; |
Index: trunk/extensions/VipsScaler/SpecialVipsTest.php |
— | — | @@ -235,7 +235,7 @@ |
236 | 236 | * |
237 | 237 | */ |
238 | 238 | protected function streamThumbnail() { |
239 | | - global $wgVipsThumbnailerUrl, $wgVipsThumbnailerProxy; |
| 239 | + global $wgVipsThumbnailerHost, $wgVipsTestExpiry; |
240 | 240 | |
241 | 241 | $request = $this->getRequest(); |
242 | 242 | |
— | — | @@ -263,7 +263,7 @@ |
264 | 264 | |
265 | 265 | |
266 | 266 | # Get the thumbnail |
267 | | - if ( is_null( $wgVipsThumbnailerUrl ) ) { |
| 267 | + if ( is_null( $wgVipsThumbnailerHost ) || $request->getBool( 'noproxy' ) ) { |
268 | 268 | # No remote scaler, need to do it ourselves. |
269 | 269 | # Emulate the BitmapHandlerTransform hook |
270 | 270 | |
— | — | @@ -308,10 +308,11 @@ |
309 | 309 | VipsScaler::doTransform( $handler, $file, $scalerParams, $options, $mto ); |
310 | 310 | if ( $mto && !$mto->isError() ) { |
311 | 311 | wfDebug( __METHOD__ . ": streaming thumbnail...\n" ); |
312 | | - |
313 | 312 | $this->getOutput()->disable(); |
314 | | - header( "Content-Type: {$scalerParams['mimeType']}" ); |
315 | | - readfile( $dstPath ); |
| 313 | + StreamFile::stream( $dstPath, array( |
| 314 | + "Cache-Control: public, max-age=$wgVipsTestExpiry, s-maxage=$wgVipsTestExpiry", |
| 315 | + 'Expires: ' . gmdate( 'r ', time() + $wgVipsTestExpiry ) |
| 316 | + ) ); |
316 | 317 | } else { |
317 | 318 | $this->streamError( 500, $mto->getHtmlMsg() ); |
318 | 319 | } |
— | — | @@ -323,28 +324,25 @@ |
324 | 325 | |
325 | 326 | } else { |
326 | 327 | # Request the thumbnail at a remote scaler |
327 | | - $url = wfAppendQuery( $wgVipsThumbnailerUrl, array( |
328 | | - 'file' => $file->getName(), |
329 | | - 'thumb' => $handler->makeParamString( $params ) . '-' . $file->getName() |
330 | | - ) ); |
| 328 | + $url = wfExpandUrl( $request->getRequestURL(), PROTO_INTERNAL ); |
| 329 | + $url = wfAppendQuery( $url, array( 'noproxy' => '1' ) ); |
331 | 330 | wfDebug( __METHOD__ . ": Getting vips thumb from remote url $url\n" ); |
332 | 331 | |
333 | 332 | $options = array( 'method' => 'GET' ); |
334 | | - if ( $wgVipsThumbnailerProxy ) { |
335 | | - $options['proxy'] = $wgVipsThumbnailerProxy; |
336 | | - } |
337 | 333 | |
338 | 334 | $req = MWHttpRequest::factory( $url, $options ); |
339 | 335 | $status = $req->execute(); |
340 | 336 | if ( $status->isOk() ) { |
341 | 337 | # Disable output and stream the file |
342 | 338 | $this->getOutput()->disable(); |
343 | | - print 'Content-Type: ' . $file->getMimeType() . "\r\n"; |
344 | | - print 'Content-Length: ' . strlen( $req->getContent() ) . "\r\n"; |
345 | | - print "\r\n"; |
| 339 | + wfResetOutputBuffers(); |
| 340 | + header( 'Content-Type: ' . $file->getMimeType() ); |
| 341 | + header( 'Content-Length: ' . strlen( $req->getContent() ) ); |
| 342 | + header( "Cache-Control: public, max-age=$wgVipsTestExpiry, s-maxage=$wgVipsTestExpiry" ); |
| 343 | + header( 'Expires: ' . gmdate( 'r ', time() + $wgVipsTestExpiry ) ); |
346 | 344 | print $req->getContent(); |
347 | 345 | } else { |
348 | | - return $this->streamError( 500 ); |
| 346 | + return $this->streamError( 500, $req->getContent() ); |
349 | 347 | } |
350 | 348 | |
351 | 349 | } |