Skip to content

Commit

Permalink
Show dimensions in TraditionalImageGallery
Browse files Browse the repository at this point in the history
Bug: T121869
Change-Id: Ie2cb3f1594302f1726ae3d9d2d668c81b7e6b0f1
  • Loading branch information
matthiasmullie committed Mar 7, 2017
1 parent 167f6f2 commit ebb1680
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 9 deletions.
2 changes: 2 additions & 0 deletions includes/DefaultSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,8 @@
'captionLength' => true,
// Show the filesize in bytes in categories
'showBytes' => true,
// Show the dimensions (width x height) in categories
'showDimensions' => true,
'mode' => 'traditional',
];

Expand Down
16 changes: 16 additions & 0 deletions includes/gallery/ImageGalleryBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -136,6 +141,7 @@ function __construct( $mode = 'traditional', IContextSource $context = null ) {
$galleryOptions = $this->getConfig()->get( 'GalleryOptions' );
$this->mImages = [];
$this->mShowBytes = $galleryOptions['showBytes'];
$this->mShowDimensions = $galleryOptions['showDimensions'];
$this->mShowFilename = true;
$this->mParser = false;
$this->mHideBadImages = false;
Expand Down Expand Up @@ -283,6 +289,16 @@ function isEmpty() {
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.
Expand Down
23 changes: 14 additions & 9 deletions includes/gallery/TraditionalImageGallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,20 @@ function toHTML() {
// ":{$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 ?
Expand All @@ -201,7 +206,7 @@ function toHTML() {
) . "\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
Expand Down
1 change: 1 addition & 0 deletions includes/parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -4971,6 +4971,7 @@ public function renderImageGallery( $text, $params ) {

$ig->setContextTitle( $this->mTitle );
$ig->setShowBytes( false );
$ig->setShowDimensions( false );
$ig->setShowFilename( false );
$ig->setParser( $this );
$ig->setHideBadImages();
Expand Down
1 change: 1 addition & 0 deletions includes/specials/SpecialUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -821,6 +821,7 @@ public function getDupeWarning( $dupes ) {

$gallery = ImageGalleryBase::factory( false, $this->getContext() );
$gallery->setShowBytes( false );
$gallery->setShowDimensions( false );
foreach ( $dupes as $file ) {
$gallery->add( $file->getTitle() );
}
Expand Down

0 comments on commit ebb1680

Please sign in to comment.