(bug 39297) Show a warning if thumbnails won't be animated
authorBrian Wolff <bawolff+wn@gmail.com>
Sun, 19 Aug 2012 01:19:53 +0000 (22:19 -0300)
committerCatrope <roan.kattouw@gmail.com>
Wed, 22 Aug 2012 01:31:51 +0000 (18:31 -0700)
This shows a warning on the image description page if the image
is animated, but thumbnails won't be. This includes
gif images that are too big, but also svg images that are animated,
and APNG files.

The message used is file-no-thumb-animation, but will also
check for file-no-thumb-animation-<image extension> so that
admins can do per image type explanations. Gif files have a built-in
explanation that is slightly different (Since its do to resolution).
Ideally one would pass the resolution limit to the gif message,
but I couldn't think of a clean way of doing that. (Also might be
complex to explain to user. They aren't used to resolution as a single
number but as a width x height type thing).

Moves isAnimatedImage from ImageHandler to MediaHandler, so I could
safely use it from any handler class.

Change-Id: I42ee11d889e0c41de53d0951f55a4338ca55311d

RELEASE-NOTES-1.20
includes/ImagePage.php
includes/filerepo/file/File.php
includes/media/GIF.php
includes/media/ImageHandler.php
includes/media/MediaHandler.php
includes/media/PNG.php
includes/media/SVG.php
languages/messages/MessagesEn.php
languages/messages/MessagesQqq.php
maintenance/language/messages.inc

index 2ef7b3e..3364519 100644 (file)
@@ -213,6 +213,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki.
 * (bug 36524) "Show" options on Special:RecentChanges and Special:RecentChangesLinked
   are now remembered between successive clicks.
 * (bug 26069) Page title is no longer "Error" for all error pages
+* (bug 39297) Show warning if thumbnail of animated image will not be animated.
 
 === API changes in 1.20 ===
 * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API.
index 7d45bcd..dad10c8 100644 (file)
@@ -510,6 +510,25 @@ EOT
                                }
                        }
 
+                       // Add cannot animate thumbnail warning
+                       if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
+                               // Include the extension so wiki admins can
+                               // customize it on a per file-type basis
+                               // (aka say things like use format X instead).
+                               // additionally have a specific message for
+                               // file-no-thumb-animation-gif
+                               $ext = $this->displayImg->getExtension();
+                               $noAnimMesg = wfMessageFallback(
+                                       'file-no-thumb-animation-' . $ext,
+                                       'file-no-thumb-animation'
+                               )->plain();
+
+                               $out->addWikiText( <<<EOT
+<div class="mw-noanimatethumb">{$noAnimMesg}</div>
+EOT
+                               );
+                       }
+
                        if ( !$this->displayImg->isLocal() ) {
                                $this->printSharedImageText();
                        }
index 133a956..dd54455 100644 (file)
@@ -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
index 028fbb0..84b9b8c 100644 (file)
@@ -93,6 +93,17 @@ class GIFHandler extends BitmapHandler {
                return false;
        }
 
+       /**
+        * We cannot animate thumbnails that are bigger than a particular size
+        * @param File $file
+        * @return bool
+        */
+       function canAnimateThumbnail( $file ) {
+               global $wgMaxAnimatedGifArea;
+               $answer = $this->getImageArea( $file ) <= $wgMaxAnimatedGifArea;
+               return $answer;
+       }
+
        function getMetadataType( $image ) {
                return 'parsed-gif';
        }
index 69f51be..65757c9 100644 (file)
@@ -204,10 +204,6 @@ abstract class ImageHandler extends MediaHandler {
                return $gis;
        }
 
-       function isAnimatedImage( $image ) {
-               return false;
-       }
-
        /**
         * @param $file File
         * @return string
index ab8fb06..965099f 100644 (file)
@@ -269,6 +269,19 @@ abstract class MediaHandler {
         * @return bool
         */
        function isVectorized( $file ) { return false; }
+       /**
+        * The material is an image, and is animated.
+        * In particular, video material need not return true.
+        * @note Before 1.20, this was a method of ImageHandler only
+        * @return bool
+        */
+       function isAnimatedImage( $file ) { return false; }
+       /**
+        * If the material is animated, we can animate the thumbnail
+        * @since 1.20
+        * @return bool If material is not animated, handler may return any value.
+        */
+       function canAnimateThumbnail( $file ) { return true; }
        /**
         * False if the handler is disabled for all files
         * @return bool
index 8289cd4..1b329e5 100644 (file)
@@ -80,6 +80,14 @@ class PNGHandler extends BitmapHandler {
                }
                return false;
        }
+       /**
+        * We do not support making APNG thumbnails, so always false
+        * @param $image File
+        * @return bool false
+        */
+       function canAnimateThumbnail( $image ) {
+               return false;
+       }
        
        function getMetadataType( $image ) {
                return 'parsed-png';
index a1e63c5..a5ce1fa 100644 (file)
@@ -63,6 +63,13 @@ class SvgHandler extends ImageHandler {
                return false;
        }
 
+       /**
+        * We do not support making animated svg thumbnails
+        */
+       function canAnimateThumb( $file ) {
+               return false;
+       }
+
        /**
         * @param $image File
         * @param  $params
index e2cfd7a..a66db04 100644 (file)
@@ -3829,6 +3829,8 @@ By executing it, your system may be compromised.",
 'file-info-png-looped'   => 'looped',
 'file-info-png-repeat'   => 'played $1 {{PLURAL:$1|time|times}}',
 'file-info-png-frames'   => '$1 {{PLURAL:$1|frame|frames}}',
+'file-no-thumb-animation'=> '\'\'\'Note: Due to technical limitations, thumbnails of this file will not be animated.\'\'\'',
+'file-no-thumb-animation-gif' => '\'\'\'Note: Due to technical limitations, thumbnails of high resolution GIF images such as this one will not be animated.\'\'\'',
 
 # Special:NewFiles
 'newimages'             => 'Gallery of new files',
index 2eaddff..bfe383e 100644 (file)
@@ -3559,6 +3559,8 @@ Parameters:
 The variable $1 is the number of individual frames in an animated gif file.
 
 For example of message in use see [[:File:Mouse10.gif]].',
+'file-no-thumb-animation' => 'We cannot animate thumbnails of this file. This notice is shown on the image description page on animated svg files just below {{msg-mw|file-info-size}}. This message may be overridden by a more specific message of the form file-no-thumb-animation-&lt;extension&gt; like {{msg-mw|file-no-thumb-animation-gif}}',
+'file-no-thumb-animation-gif' => 'Cannot animate thumbnails of this gif file, because it has to big a resolution. The cut off resolution can vary between wikis ([[mw:manual:$wgMaxAnimatedGifArea|$wgMaxAnimatedGifArea]]). Note that resolution is calculated as width times height times number of frames. See {{msg-mw|file-no-thumb-animation}}.',
 
 # Special:NewFiles
 'newimages' => 'Page title of [[Special:NewImages]].',
index 38ccee6..59e15a8 100644 (file)
@@ -2755,6 +2755,8 @@ $wgMessageStructure = array(
                'file-info-png-looped',
                'file-info-png-repeat',
                'file-info-png-frames',
+               'file-no-thumb-animation',
+               'file-no-thumb-animation-gif',
        ),
        'newfiles' => array(
                'newimages',