Fixed and normalized content-disposition for thumbs.
* Previously, thumbnails could have a hex tmp file name as the disposition. Change-Id: I495860dc54c02d2b3e053e998a41674cd6d07f2f
This commit is contained in:
parent
7fae5812cd
commit
d22c890890
3 changed files with 40 additions and 25 deletions
|
|
@ -79,8 +79,6 @@ class StreamFile {
|
|||
public static function prepareForStream(
|
||||
$path, $info, $headers = array(), $sendErrors = true
|
||||
) {
|
||||
global $wgLanguageCode;
|
||||
|
||||
if ( !is_array( $info ) ) {
|
||||
if ( $sendErrors ) {
|
||||
header( 'HTTP/1.0 404 Not Found' );
|
||||
|
|
@ -121,9 +119,6 @@ class StreamFile {
|
|||
return false;
|
||||
}
|
||||
|
||||
header( "Content-Disposition: inline;filename*=utf-8'$wgLanguageCode'" .
|
||||
urlencode( basename( $path ) ) );
|
||||
|
||||
// Send additional headers
|
||||
foreach ( $headers as $header ) {
|
||||
header( $header );
|
||||
|
|
|
|||
|
|
@ -943,7 +943,7 @@ abstract class File {
|
|||
}
|
||||
} elseif ( $this->repo && $thumb->hasFile() && !$thumb->fileIsSource() ) {
|
||||
// Copy the thumbnail from the file system into storage...
|
||||
$disposition = FileBackend::makeContentDisposition( 'inline', $this->name );
|
||||
$disposition = $this->getThumbDisposition( $thumbName );
|
||||
$status = $this->repo->quickImport( $tmpThumbPath, $thumbPath, $disposition );
|
||||
if ( $status->isOK() ) {
|
||||
$thumb->setStoragePath( $thumbPath );
|
||||
|
|
@ -968,6 +968,19 @@ abstract class File {
|
|||
return is_object( $thumb ) ? $thumb : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $thumbName string Thumbnail name
|
||||
* @return string Content-Disposition header value
|
||||
*/
|
||||
function getThumbDisposition( $thumbName ) {
|
||||
$fileName = $this->name; // file name to suggest
|
||||
$thumbExt = FileBackend::extensionFromPath( $thumbName );
|
||||
if ( $thumbExt != '' && $thumbExt !== $this->getExtension() ) {
|
||||
$fileName .= ".$thumbExt";
|
||||
}
|
||||
return FileBackend::makeContentDisposition( 'inline', $fileName );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook into transform() to allow migration of thumbnail files
|
||||
* STUB
|
||||
|
|
|
|||
45
thumb.php
45
thumb.php
|
|
@ -205,27 +205,34 @@ function wfStreamThumb( array $params ) {
|
|||
}
|
||||
}
|
||||
|
||||
$thumbName = $img->thumbName( $params );
|
||||
if ( !strlen( $thumbName ) ) { // invalid params?
|
||||
wfThumbError( 400, 'The specified thumbnail parameters are not valid.' );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return;
|
||||
}
|
||||
|
||||
$disposition = $img->getThumbDisposition( $thumbName );
|
||||
$headers[] = "Content-Disposition: $disposition";
|
||||
|
||||
// Stream the file if it exists already...
|
||||
try {
|
||||
$thumbName = $img->thumbName( $params );
|
||||
if ( strlen( $thumbName ) ) { // valid params?
|
||||
// For 404 handled thumbnails, we only use the the base name of the URI
|
||||
// for the thumb params and the parent directory for the source file name.
|
||||
// Check that the zone relative path matches up so squid caches won't pick
|
||||
// up thumbs that would not be purged on source file deletion (bug 34231).
|
||||
if ( isset( $params['rel404'] ) // thumbnail was handled via 404
|
||||
&& urldecode( $params['rel404'] ) !== $img->getThumbRel( $thumbName ) )
|
||||
{
|
||||
wfThumbError( 404, 'The source file for the specified thumbnail does not exist.' );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return;
|
||||
}
|
||||
$thumbPath = $img->getThumbPath( $thumbName );
|
||||
if ( $img->getRepo()->fileExists( $thumbPath ) ) {
|
||||
$img->getRepo()->streamFile( $thumbPath, $headers );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return;
|
||||
}
|
||||
// For 404 handled thumbnails, we only use the the base name of the URI
|
||||
// for the thumb params and the parent directory for the source file name.
|
||||
// Check that the zone relative path matches up so squid caches won't pick
|
||||
// up thumbs that would not be purged on source file deletion (bug 34231).
|
||||
if ( isset( $params['rel404'] ) // thumbnail was handled via 404
|
||||
&& urldecode( $params['rel404'] ) !== $img->getThumbRel( $thumbName ) )
|
||||
{
|
||||
wfThumbError( 404, 'The source file for the specified thumbnail does not exist.' );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return;
|
||||
}
|
||||
$thumbPath = $img->getThumbPath( $thumbName );
|
||||
if ( $img->getRepo()->fileExists( $thumbPath ) ) {
|
||||
$img->getRepo()->streamFile( $thumbPath, $headers );
|
||||
wfProfileOut( __METHOD__ );
|
||||
return;
|
||||
}
|
||||
} catch ( MWException $e ) {
|
||||
wfThumbError( 500, $e->getHTML() );
|
||||
|
|
|
|||
Loading…
Reference in a new issue