Gilles has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/402579 )
Change subject: Add ability to proxy thumbnail requests to a service ...................................................................... Add ability to proxy thumbnail requests to a service Bug: T169144 Change-Id: I4af09a8b75e7158d6ff15f97e8f067b66ac33d5c --- M includes/filerepo/FileRepo.php M thumb.php 2 files changed, 60 insertions(+), 2 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/79/402579/1 diff --git a/includes/filerepo/FileRepo.php b/includes/filerepo/FileRepo.php index 5d22b8d..b4fa11a 100644 --- a/includes/filerepo/FileRepo.php +++ b/includes/filerepo/FileRepo.php @@ -132,6 +132,11 @@ /** @var array callable|bool Override these in the base class */ protected $oldFileFactoryKey = false; + /** @var string URL of where to proxy thumb.php requests to */ + protected $thumbProxyUrl; + /** @var string Secret key to pass as an X-Swift-Secret header to the proxied thumb service */ + protected $thumbProxySecret; + /** * @param array|null $info * @throws MWException @@ -159,7 +164,7 @@ $optionalSettings = [ 'descBaseUrl', 'scriptDirUrl', 'articleUrl', 'fetchDescription', 'thumbScriptUrl', 'pathDisclosureProtection', 'descriptionCacheExpiry', - 'scriptExtension', 'favicon' + 'scriptExtension', 'favicon', 'thumbProxyUrl', 'thumbProxySecret' ]; foreach ( $optionalSettings as $var ) { if ( isset( $info[$var] ) ) { @@ -612,6 +617,24 @@ } /** + * Get the URL thumb.php requests are being proxied to + * + * @return string + */ + public function getThumbProxyUrl() { + return $this->thumbProxyUrl; + } + + /** + * Get the secret key for the proxied thumb service + * + * @return string + */ + public function getThumbProxySecret() { + return $this->thumbProxySecret; + } + + /** * Returns true if the repository can transform files via a 404 handler * * @return bool diff --git a/thumb.php b/thumb.php index 7c3e757..8127114 100644 --- a/thumb.php +++ b/thumb.php @@ -337,7 +337,42 @@ return; } - list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName, $thumbPath ); + $thumbProxyUrl = $img->getRepo()->getThumbProxyUrl(); + + if ( strlen( $thumbProxyUrl ) ) { + // Instead of generating the thumbnail ourselves, we proxy the request to another service + $thumbProxiedUrl = $thumbProxyUrl . $img->getThumbRel( $thumbName ); + + $req = MWHttpRequest::factory( $thumbProxiedUrl ); + $secret = $img->getRepo()->getThumbProxySecret(); + + // Pass a secret key shared with the proxied service if any + if ( strlen( $secret ) ) { + $req->setHeader( 'X-Swift-Secret', $secret ); + } + + // Send request to proxied service + $status = $req->execute(); + + // Simply serve the response from the proxied service as-is + header( 'HTTP/1.1 ' . $req->getStatus() ); + + $headers = $req->getResponseHeaders(); + + foreach ( $headers as $key => $values ) { + foreach ( $values as $value ) { + header( $key . ': ' . $value, false ); + } + } + + echo $req->getContent(); + + // No local fallback when in proxy mode + return; + } else { + // Generate the thumbnail locally + list( $thumb, $errorMsg ) = wfGenerateThumbnail( $img, $params, $thumbName, $thumbPath ); + } /** @var MediaTransformOutput|MediaTransformError|bool $thumb */ -- To view, visit https://gerrit.wikimedia.org/r/402579 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I4af09a8b75e7158d6ff15f97e8f067b66ac33d5c Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Gilles <gdu...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits