From ebb168035933dac7f8f4da6f88ee3ed5b5148b8e Mon Sep 17 00:00:00 2001 From: Matthias Mullie Date: Mon, 6 Mar 2017 13:32:38 +0100 Subject: [PATCH] Show dimensions in TraditionalImageGallery Bug: T121869 Change-Id: Ie2cb3f1594302f1726ae3d9d2d668c81b7e6b0f1 --- includes/DefaultSettings.php | 2 ++ includes/gallery/ImageGalleryBase.php | 16 ++++++++++++++ includes/gallery/TraditionalImageGallery.php | 23 ++++++++++++-------- includes/parser/Parser.php | 1 + includes/specials/SpecialUpload.php | 1 + 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index a3d68c6bfe..89f7b0da88 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -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', ]; diff --git a/includes/gallery/ImageGalleryBase.php b/includes/gallery/ImageGalleryBase.php index 6884f65626..eeb8a8ff84 100644 --- a/includes/gallery/ImageGalleryBase.php +++ b/includes/gallery/ImageGalleryBase.php @@ -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. diff --git a/includes/gallery/TraditionalImageGallery.php b/includes/gallery/TraditionalImageGallery.php index 1fd7b0a362..a0059cea1f 100644 --- a/includes/gallery/TraditionalImageGallery.php +++ b/includes/gallery/TraditionalImageGallery.php @@ -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
\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 .= "
\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 diff --git a/includes/parser/Parser.php b/includes/parser/Parser.php index 8db1fe3794..4a7db997df 100644 --- a/includes/parser/Parser.php +++ b/includes/parser/Parser.php @@ -4971,6 +4971,7 @@ class Parser { $ig->setContextTitle( $this->mTitle ); $ig->setShowBytes( false ); + $ig->setShowDimensions( false ); $ig->setShowFilename( false ); $ig->setParser( $this ); $ig->setHideBadImages(); diff --git a/includes/specials/SpecialUpload.php b/includes/specials/SpecialUpload.php index f4a4818b32..def639d83b 100644 --- a/includes/specials/SpecialUpload.php +++ b/includes/specials/SpecialUpload.php @@ -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() ); } -- 2.20.1