Show dimensions in TraditionalImageGallery
authorMatthias Mullie <git@mullie.eu>
Mon, 6 Mar 2017 12:32:38 +0000 (13:32 +0100)
committerMatthias Mullie <git@mullie.eu>
Tue, 7 Mar 2017 12:09:00 +0000 (13:09 +0100)
Bug: T121869
Change-Id: Ie2cb3f1594302f1726ae3d9d2d668c81b7e6b0f1

includes/DefaultSettings.php
includes/gallery/ImageGalleryBase.php
includes/gallery/TraditionalImageGallery.php
includes/parser/Parser.php
includes/specials/SpecialUpload.php

index a3d68c6..89f7b0d 100644 (file)
@@ -1455,6 +1455,8 @@ $wgGalleryOptions = [
        'captionLength' => true,
        // Show the filesize in bytes in categories
        'showBytes' => true,
+       // Show the dimensions (width x height) in categories
+       'showDimensions' => true,
        'mode' => 'traditional',
 ];
 
index 6884f65..eeb8a8f 100644 (file)
@@ -38,6 +38,11 @@ abstract class ImageGalleryBase extends ContextSource {
         */
        protected $mShowBytes;
 
+       /**
+        * @var bool Whether to show the dimensions in categories
+        */
+       protected $mShowDimensions;
+
        /**
         * @var bool Whether to show the filename. Default: true
         */
@@ -136,6 +141,7 @@ abstract class ImageGalleryBase extends ContextSource {
                $galleryOptions = $this->getConfig()->get( 'GalleryOptions' );
                $this->mImages = [];
                $this->mShowBytes = $galleryOptions['showBytes'];
+               $this->mShowDimensions = $galleryOptions['showDimensions'];
                $this->mShowFilename = true;
                $this->mParser = false;
                $this->mHideBadImages = false;
@@ -283,6 +289,16 @@ abstract class ImageGalleryBase extends ContextSource {
                return empty( $this->mImages );
        }
 
+       /**
+        * Enable/Disable showing of the dimensions of an image in the gallery.
+        * Enabled by default.
+        *
+        * @param bool $f Set to false to disable
+        */
+       function setShowDimensions( $f ) {
+               $this->mShowDimensions = (bool)$f;
+       }
+
        /**
         * Enable/Disable showing of the file size of an image in the gallery.
         * Enabled by default.
index 1fd7b0a..a0059ce 100644 (file)
@@ -174,15 +174,20 @@ class TraditionalImageGallery extends ImageGalleryBase {
                        // ":{$ut}" );
                        // $ul = Linker::link( $linkTarget, $ut );
 
-                       if ( $this->mShowBytes ) {
-                               if ( $img ) {
-                                       $fileSize = htmlspecialchars( $lang->formatSize( $img->getSize() ) );
-                               } else {
-                                       $fileSize = $this->msg( 'filemissing' )->escaped();
+                       $meta = [];
+                       if ( $img ) {
+                               if ( $this->mShowDimensions ) {
+                                       $meta[] = $img->getDimensionsString();
                                }
-                               $fileSize = "$fileSize<br />\n";
-                       } else {
-                               $fileSize = '';
+                               if ( $this->mShowBytes ) {
+                                       $meta[] = htmlspecialchars( $lang->formatSize( $img->getSize() ) );
+                               }
+                       } elseif ( $this->mShowDimensions || $this->mShowBytes ) {
+                               $meta[] = $this->msg( 'filemissing' )->escaped();
+                       }
+                       $meta = $lang->semicolonList( $meta );
+                       if ( $meta ) {
+                               $meta .= "<br />\n";
                        }
 
                        $textlink = $this->mShowFilename ?
@@ -201,7 +206,7 @@ class TraditionalImageGallery extends ImageGalleryBase {
                                ) . "\n" :
                                '';
 
-                       $galleryText = $textlink . $text . $fileSize;
+                       $galleryText = $textlink . $text . $meta;
                        $galleryText = $this->wrapGalleryText( $galleryText, $thumb );
 
                        # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
index 8db1fe3..4a7db99 100644 (file)
@@ -4971,6 +4971,7 @@ class Parser {
 
                $ig->setContextTitle( $this->mTitle );
                $ig->setShowBytes( false );
+               $ig->setShowDimensions( false );
                $ig->setShowFilename( false );
                $ig->setParser( $this );
                $ig->setHideBadImages();
index f4a4818..def639d 100644 (file)
@@ -821,6 +821,7 @@ class SpecialUpload extends SpecialPage {
 
                $gallery = ImageGalleryBase::factory( false, $this->getContext() );
                $gallery->setShowBytes( false );
+               $gallery->setShowDimensions( false );
                foreach ( $dupes as $file ) {
                        $gallery->add( $file->getTitle() );
                }