(bug 39297) Show a warning if thumbnails won't be animated
[lhc/web/wiklou.git] / includes / filerepo / file / File.php
index 3fa8166..dd54455 100644 (file)
@@ -246,15 +246,15 @@ abstract class File {
        }
 
        /**
-        * Callback for usort() to do file sorts by title
+        * Callback for usort() to do file sorts by name
         *
         * @param $a File
         * @param $b File
         *
-        * @return Integer: result of title comparison
+        * @return Integer: result of name comparison
         */
        public static function compare( File $a, File $b ) {
-               return Title::compare( $a->getTitle(), $b->getTitle() );
+               return strcmp( $a->getName(), $b->getName() );
        }
 
        /**
@@ -464,6 +464,39 @@ abstract class File {
                }
        }
 
+       /**
+        * Will the thumbnail be animated if one would expect it to be.
+        *
+        * Currently used to add a warning to the image description page
+        *
+        * @return bool false if the main image is both animated
+        *   and the thumbnail is not. In all other cases must return
+        *   true. If image is not renderable whatsoever, should
+        *   return true.
+        */
+       public function canAnimateThumbIfAppropriate() {
+               $handler = $this->getHandler();
+               if ( !$handler ) {
+                       // We cannot handle image whatsoever, thus
+                       // one would not expect it to be animated
+                       // so true.
+                       return true;
+               } else {
+                       if ( $this->allowInlineDisplay()
+                               && $handler->isAnimatedImage( $this )
+                               && !$handler->canAnimateThumbnail( $this )
+                       ) {
+                               // Image is animated, but thumbnail isn't.
+                               // This is unexpected to the user.
+                               return false;
+                       } else {
+                               // Image is not animated, so one would
+                               // not expect thumb to be
+                               return true;
+                       }
+               }
+       }
+
        /**
         * Get handler-specific metadata
         * Overridden by LocalFile, UnregisteredLocalFile
@@ -804,7 +837,7 @@ abstract class File {
                        return $this->handler->getTransform( $this, $thumbPath, $thumbUrl, $params );
                } else {
                        return new MediaTransformError( 'thumbnail_error',
-                               $params['width'], 0, wfMsg( 'thumbnail-dest-create' ) );
+                               $params['width'], 0, wfMessage( 'thumbnail-dest-create' )->text() );
                }
        }
 
@@ -894,7 +927,9 @@ abstract class File {
                        $tmpThumbPath = $tmpFile->getPath(); // path of 0-byte temp file
 
                        // Actually render the thumbnail...
+                       wfProfileIn( __METHOD__ . '-doTransform' );
                        $thumb = $this->handler->doTransform( $this, $tmpThumbPath, $thumbUrl, $params );
+                       wfProfileOut( __METHOD__ . '-doTransform' );
                        $tmpFile->bind( $thumb ); // keep alive with $thumb
 
                        if ( !$thumb ) { // bad params?