r103575 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103574‎ | r103575 | r103576 >
Date:06:21, 18 November 2011
Author:tstarling
Status:ok
Tags:
Comment:
* Rewrote the proxy feature so that it actually works. Just reuse the same entry point, don't require some other script.
* Made the expiry time configurable.
* Use StreamFile::stream() instead of readfile() to get various good features like not gzipping the output.
Modified paths:
  • /trunk/extensions/VipsScaler/SpecialVipsTest.php (modified) (history)
  • /trunk/extensions/VipsScaler/VipsTest.php (modified) (history)

Diff [purge]

Index: trunk/extensions/VipsScaler/VipsTest.php
@@ -8,15 +8,15 @@
99 if ( !defined( 'MEDIAWIKI' ) ) exit( 1 );
1010
1111 /**
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.
1414 */
15 -$wgVipsThumbnailerUrl = null;
 15+$wgVipsThumbnailerHost = null;
1616
1717 /**
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.
1919 */
20 -$wgVipsThumbnailerProxy = null;
 20+$wgVipsTestExpiry = 3600;
2121
2222 /** Registration */
2323 $wgAutoloadClasses['SpecialVipsTest'] = "$dir/SpecialVipsTest.php";
Index: trunk/extensions/VipsScaler/SpecialVipsTest.php
@@ -235,7 +235,7 @@
236236 *
237237 */
238238 protected function streamThumbnail() {
239 - global $wgVipsThumbnailerUrl, $wgVipsThumbnailerProxy;
 239+ global $wgVipsThumbnailerHost, $wgVipsTestExpiry;
240240
241241 $request = $this->getRequest();
242242
@@ -263,7 +263,7 @@
264264
265265
266266 # Get the thumbnail
267 - if ( is_null( $wgVipsThumbnailerUrl ) ) {
 267+ if ( is_null( $wgVipsThumbnailerHost ) || $request->getBool( 'noproxy' ) ) {
268268 # No remote scaler, need to do it ourselves.
269269 # Emulate the BitmapHandlerTransform hook
270270
@@ -308,10 +308,11 @@
309309 VipsScaler::doTransform( $handler, $file, $scalerParams, $options, $mto );
310310 if ( $mto && !$mto->isError() ) {
311311 wfDebug( __METHOD__ . ": streaming thumbnail...\n" );
312 -
313312 $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+ ) );
316317 } else {
317318 $this->streamError( 500, $mto->getHtmlMsg() );
318319 }
@@ -323,28 +324,25 @@
324325
325326 } else {
326327 # 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' ) );
331330 wfDebug( __METHOD__ . ": Getting vips thumb from remote url $url\n" );
332331
333332 $options = array( 'method' => 'GET' );
334 - if ( $wgVipsThumbnailerProxy ) {
335 - $options['proxy'] = $wgVipsThumbnailerProxy;
336 - }
337333
338334 $req = MWHttpRequest::factory( $url, $options );
339335 $status = $req->execute();
340336 if ( $status->isOk() ) {
341337 # Disable output and stream the file
342338 $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 ) );
346344 print $req->getContent();
347345 } else {
348 - return $this->streamError( 500 );
 346+ return $this->streamError( 500, $req->getContent() );
349347 }
350348
351349 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r104623* Fix for r103575: actually use $wgVipsThumbnailerHost...tstarling00:04, 30 November 2011

Status & tagging log