Merge "Fixed and normalized content-disposition for thumbs."
authorAaron Schulz <aschulz@wikimedia.org>
Tue, 4 Sep 2012 20:59:16 +0000 (20:59 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Tue, 4 Sep 2012 20:59:16 +0000 (20:59 +0000)
1  2 
includes/filerepo/file/File.php

@@@ -943,7 -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 );
                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
                        $path = '/common/images/icons/' . $icon;
                        $filepath = $wgStyleDirectory . $path;
                        if ( file_exists( $filepath ) ) { // always FS
 -                              return new ThumbnailImage( $this, $wgStylePath . $path, 120, 120 );
 +                              $params = array( 'width' => 120, 'height' => 120 );
 +                              return new ThumbnailImage( $this, $wgStylePath . $path, false, $params );
                        }
                }
                return null;