From: Brian Wolff Date: Sun, 19 Aug 2012 01:19:53 +0000 (-0300) Subject: (bug 39297) Show a warning if thumbnails won't be animated X-Git-Tag: 1.31.0-rc.0~22648 X-Git-Url: http://git.cyclocoop.org/%24href?a=commitdiff_plain;h=876128f8c9f0ce6a8424336fd9374f29b5e6a001;p=lhc%2Fweb%2Fwiklou.git (bug 39297) Show a warning if thumbnails won't be animated 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- 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 --- diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index 2ef7b3e07f..3364519630 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -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. diff --git a/includes/ImagePage.php b/includes/ImagePage.php index 7d45bcdcf4..dad10c85a5 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -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( <<{$noAnimMesg} +EOT + ); + } + if ( !$this->displayImg->isLocal() ) { $this->printSharedImageText(); } diff --git a/includes/filerepo/file/File.php b/includes/filerepo/file/File.php index 133a956859..dd54455233 100644 --- a/includes/filerepo/file/File.php +++ b/includes/filerepo/file/File.php @@ -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 diff --git a/includes/media/GIF.php b/includes/media/GIF.php index 028fbb002a..84b9b8ca7d 100644 --- a/includes/media/GIF.php +++ b/includes/media/GIF.php @@ -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'; } diff --git a/includes/media/ImageHandler.php b/includes/media/ImageHandler.php index 69f51bea0e..65757c933d 100644 --- a/includes/media/ImageHandler.php +++ b/includes/media/ImageHandler.php @@ -204,10 +204,6 @@ abstract class ImageHandler extends MediaHandler { return $gis; } - function isAnimatedImage( $image ) { - return false; - } - /** * @param $file File * @return string diff --git a/includes/media/MediaHandler.php b/includes/media/MediaHandler.php index ab8fb0664d..965099fdad 100644 --- a/includes/media/MediaHandler.php +++ b/includes/media/MediaHandler.php @@ -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 diff --git a/includes/media/PNG.php b/includes/media/PNG.php index 8289cd4e16..1b329e57b5 100644 --- a/includes/media/PNG.php +++ b/includes/media/PNG.php @@ -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'; diff --git a/includes/media/SVG.php b/includes/media/SVG.php index a1e63c5776..a5ce1fa6cd 100644 --- a/includes/media/SVG.php +++ b/includes/media/SVG.php @@ -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 diff --git a/languages/messages/MessagesEn.php b/languages/messages/MessagesEn.php index e2cfd7a34b..a66db049e8 100644 --- a/languages/messages/MessagesEn.php +++ b/languages/messages/MessagesEn.php @@ -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', diff --git a/languages/messages/MessagesQqq.php b/languages/messages/MessagesQqq.php index 2eaddff942..bfe383ef02 100644 --- a/languages/messages/MessagesQqq.php +++ b/languages/messages/MessagesQqq.php @@ -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-<extension> 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]].', diff --git a/maintenance/language/messages.inc b/maintenance/language/messages.inc index 38ccee68d8..59e15a8a72 100644 --- a/maintenance/language/messages.inc +++ b/maintenance/language/messages.inc @@ -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',