From: Gilles Dubuc Date: Mon, 24 Mar 2014 23:31:21 +0000 (+0100) Subject: Have ?download parameter trigger Content-Disposition: attachment X-Git-Tag: 1.31.0-rc.0~16481^2 X-Git-Url: http://git.cyclocoop.org/data/Fool?a=commitdiff_plain;h=4d9e07056ed0185183d9f80ab3b0353b503edfbe;p=lhc%2Fweb%2Fwiklou.git Have ?download parameter trigger Content-Disposition: attachment This parameter triggers Content-Disposition: Attachment which makes the browser download the image instead of displaying it. This is needed by Media Viewer to allow users to click a button in order to download an image at a given resolution or the original. Change-Id: I470a24a09139ac65588312104995e34d97a89b0f --- diff --git a/img_auth.php b/img_auth.php index 391fb291b8..a0976af3b0 100644 --- a/img_auth.php +++ b/img_auth.php @@ -150,6 +150,10 @@ function wfImageAuthMain() { return; } + if ( $wgRequest->getCheck( 'download' ) ) { + header( 'Content-Disposition: attachment' ); + } + // Stream the requested file wfDebugLog( 'img_auth', "Streaming `" . $filename . "`." ); $repo->streamFile( $filename, array( 'Cache-Control: private', 'Vary: Cookie' ) ); diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 950baea11b..c19a51df2c 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -1066,16 +1066,17 @@ abstract class File { /** * @param string $thumbName Thumbnail name + * @param string $dispositionType Type of disposition (either "attachment" or "inline") * @return string Content-Disposition header value */ - function getThumbDisposition( $thumbName ) { + function getThumbDisposition( $thumbName, $dispositionType = 'inline' ) { $fileName = $this->name; // file name to suggest $thumbExt = FileBackend::extensionFromPath( $thumbName ); if ( $thumbExt != '' && $thumbExt !== $this->getExtension() ) { $fileName .= ".$thumbExt"; } - return FileBackend::makeContentDisposition( 'inline', $fileName ); + return FileBackend::makeContentDisposition( $dispositionType, $fileName ); } /** diff --git a/thumb.php b/thumb.php index 88aecbdbf9..b0d9f10edd 100644 --- a/thumb.php +++ b/thumb.php @@ -289,8 +289,10 @@ function wfStreamThumb( array $params ) { } } + $dispositionType = isset( $params['download'] ) ? 'attachment' : 'inline'; + // Suggest a good name for users downloading this thumbnail - $headers[] = "Content-Disposition: {$img->getThumbDisposition( $thumbName )}"; + $headers[] = "Content-Disposition: {$img->getThumbDisposition( $thumbName, $dispositionType )}"; if ( count( $varyHeader ) ) { $headers[] = 'Vary: ' . implode( ', ', $varyHeader );