Merge "fix sidebar HTML escaping in CologneBlue"
[lhc/web/wiklou.git] / includes / filerepo / file / File.php
index 4cc47f0..557609d 100644 (file)
@@ -68,6 +68,9 @@ abstract class File {
        const FOR_THIS_USER = 2;
        const RAW = 3;
 
+       // Options for File::thumbName()
+       const THUMB_FULL_NAME = 1;
+
        /**
         * Some member variables can be lazy-initialised using __get(). The
         * initialisation function for these variables is always a function named
@@ -759,15 +762,18 @@ abstract class File {
        }
 
        /**
-        * Return the file name of a thumbnail with the specified parameters
+        * Return the file name of a thumbnail with the specified parameters.
+        * Use File::THUMB_FULL_NAME to always get a name like "<params>-<source>".
+        * Otherwise, the format may be "<params>-<source>" or "<params>-thumbnail.<ext>".
         *
         * @param $params Array: handler-specific parameters
-        * @private -ish
-        *
+        * @param $flags integer Bitfield that supports THUMB_* constants
         * @return string
         */
-       function thumbName( $params ) {
-               $name = $this->repo ? $this->repo->nameForThumb( $this->getName() ) : $this->getName();
+       public function thumbName( $params, $flags = 0 ) {
+               $name = ( $this->repo && !( $flags & self::THUMB_FULL_NAME ) )
+                       ? $this->repo->nameForThumb( $this->getName() )
+                       : $this->getName();
                return $this->generateThumbName( $name, $params );
        }
 
@@ -779,7 +785,7 @@ abstract class File {
         *
         * @return string
         */
-       function generateThumbName( $name, $params ) {
+       public function generateThumbName( $name, $params ) {
                if ( !$this->getHandler() ) {
                        return null;
                }
@@ -943,7 +949,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 +974,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
@@ -1000,7 +1019,8 @@ abstract class File {
                        $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;