Show different message if image thumb in different format than img
authorBrian Wolff <bawolff+wn@gmail.com>
Sun, 19 Jul 2015 08:16:23 +0000 (02:16 -0600)
committerBrian Wolff <bawolff+wn@gmail.com>
Sat, 10 Oct 2015 19:32:59 +0000 (13:32 -0600)
Users on commons feel that the other resolution links on the image
page can be confusing to users if they are in a different format
than the original image. Use a different message in that case
to clarify the situation.

See discussion at https://commons.wikimedia.org/?oldid=165672017

Change-Id: I76d7155e1c1e48a9824819135943d2385a0ee41a

includes/page/ImagePage.php
languages/i18n/en.json
languages/i18n/qqq.json

index e1cd76c..7957e65 100644 (file)
@@ -382,13 +382,8 @@ class ImagePage extends Article {
                                        }
                                        $otherSizes = array_unique( $otherSizes );
 
-                                       $msgsmall = '';
                                        $sizeLinkBigImagePreview = $this->makeSizeLink( $params, $width, $height );
-                                       if ( $sizeLinkBigImagePreview ) {
-                                               $msgsmall .= $this->getContext()->msg( 'show-big-image-preview' )->
-                                                       rawParams( $sizeLinkBigImagePreview )->
-                                                       parse();
-                                       }
+                                       $msgsmall = $this->getThumbPrevText( $params, $sizeLinkBigImagePreview );
                                        if ( count( $otherSizes ) ) {
                                                $msgsmall .= ' ' .
                                                Html::rawElement(
@@ -632,6 +627,44 @@ EOT
                $out->setFileVersion( $this->displayImg );
        }
 
+       /**
+        * Make the text under the image to say what size preview
+        *
+        * @param $params Array parameters for thumbnail
+        * @param $sizeLinkBigImagePreview HTML for the current size
+        * @return string HTML output
+        */
+       private function getThumbPrevText( $params, $sizeLinkBigImagePreview ) {
+               if ( $sizeLinkBigImagePreview ) {
+                       // Show a different message of preview is different format from original.
+                       $previewTypeDiffers = false;
+                       $origExt = $thumbExt = $this->displayImg->getExtension();
+                       if ( $this->displayImg->getHandler() ) {
+                               $origMime = $this->displayImg->getMimeType();
+                               $typeParams = $params;
+                               $this->displayImg->getHandler()->normaliseParams( $this->displayImg, $typeParams );
+                               list( $thumbExt, $thumbMime ) = $this->displayImg->getHandler()->getThumbType(
+                                       $origExt, $origMime, $typeParams );
+                               if ( $thumbMime !== $origMime ) {
+                                       $previewTypeDiffers = true;
+                               }
+                       }
+                       if ( $previewTypeDiffers ) {
+                               return $this->getContext()->msg( 'show-big-image-preview-differ' )->
+                                       rawParams( $sizeLinkBigImagePreview )->
+                                       params( strtoupper( $origExt ) )->
+                                       params( strtoupper( $thumbExt ) )->
+                                       parse();
+                       } else {
+                               return $this->getContext()->msg( 'show-big-image-preview' )->
+                                       rawParams( $sizeLinkBigImagePreview )->
+                               parse();
+                       }
+               } else {
+                       return '';
+               }
+       }
+
        /**
         * Creates an thumbnail of specified size and returns an HTML link to it
         * @param array $params Scaler parameters
index 8dbf024..b284d09 100644 (file)
        "svg-long-error": "Invalid SVG file: $1",
        "show-big-image": "Original file",
        "show-big-image-preview": "Size of this preview: $1.",
+       "show-big-image-preview-differ": "Size of this $3 preview of this $2 file: $1.",
        "show-big-image-other": "Other {{PLURAL:$2|resolution|resolutions}}: $1.",
        "show-big-image-size": "$1 × $2 pixels",
        "file-info-gif-looped": "looped",
index bb248bd..996685e 100644 (file)
        "svg-long-error": "Displayed for invalid SVG file metadata. Parameters:\n* $1 - the error message\nSee also:\n* {{msg-mw|Thumbnail error}}",
        "show-big-image": "Displayed under the file on file description pages, when a reduced-size thumbnail of the original file is being displayed.\n{{Identical|Original file}}",
        "show-big-image-preview": "Message shown under the image description page thumbnail.\n\nCan be followed by {{msg-mw|Show-big-image-other}}.\n\nParameters:\n* $1 - a link which points to the thumbnail. Its text is {{msg-mw|Show-big-image-size}}",
+       "show-big-image-preview-differ": "Like {{msg-mw|show-big-image-preview}}, but used in the case where the thumbnail of the file is in a different format than the original image (e.g. For SVG or DjVu files).\n\n* $1 - a link which points to the thumbnail. Its text is {{msg-mw|Show-big-image-size}}\n* $2 Uppercase normalized extension of original file.\n* $3 Uppercased extension of thumbnail.",
        "show-big-image-other": "Message shown under the image description page thumbnail.\n\nPreceded by {{msg-mw|Show-big-image-preview}}, if the image is in high resolution.\n\nParameters:\n* $1 - list of resolutions (pipe-separated)\n* $2 - number of resolutions",
        "show-big-image-size": "Parameters:\n* $1 - the width of the image(s) in pixels\n* $2 - the height of the image(s) in pixels",
        "file-info-gif-looped": "Part of the information provided about a [[w:Gif|.gif file]] on its file description page. Looped means repeating in the context of an animated gif. It is a sequence of images, each displayed after the other, and the first one displayed after the last, in a never ending loop. For example of message in use see [[:File:Mouse10.gif]].\n{{Identical|Looped}}",