From 40ad4433ecfc625524f67762c478fb06a806293f Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Fri, 13 Apr 2018 12:45:32 +0200 Subject: [PATCH] Make ImageGallery more flexible for use in Wikibase Also add missing declaration/ documentation of ImageGalleryBase::mCaptionLength. Bug: T46727 Change-Id: I314061b224ff2921eb5532be53e0c9cdc4f52c01 --- includes/gallery/ImageGalleryBase.php | 9 +++++ includes/gallery/TraditionalImageGallery.php | 42 +++++++++++++++++--- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/includes/gallery/ImageGalleryBase.php b/includes/gallery/ImageGalleryBase.php index 318329726a..09e40a2821 100644 --- a/includes/gallery/ImageGalleryBase.php +++ b/includes/gallery/ImageGalleryBase.php @@ -58,6 +58,15 @@ abstract class ImageGalleryBase extends ContextSource { */ protected $mCaption = false; + /** + * Length to truncate filename to in caption when using "showfilename". + * A value of 'true' will truncate the filename to one line using CSS + * and will be the behaviour after deprecation. + * + * @var bool|int + */ + protected $mCaptionLength = true; + /** * @var bool Hide blacklisted images? */ diff --git a/includes/gallery/TraditionalImageGallery.php b/includes/gallery/TraditionalImageGallery.php index 7a520bcbd1..1cb7e6d24a 100644 --- a/includes/gallery/TraditionalImageGallery.php +++ b/includes/gallery/TraditionalImageGallery.php @@ -195,13 +195,13 @@ class TraditionalImageGallery extends ImageGalleryBase { Linker::linkKnown( $nt, htmlspecialchars( - $this->mCaptionLength !== true ? - $lang->truncate( $nt->getText(), $this->mCaptionLength ) : + is_int( $this->getCaptionLength() ) ? + $lang->truncate( $nt->getText(), $this->getCaptionLength() ) : $nt->getText() ), [ 'class' => 'galleryfilename' . - ( $this->mCaptionLength === true ? ' galleryfilename-truncate' : '' ) + ( $this->getCaptionLength() === true ? ' galleryfilename-truncate' : '' ) ] ) . "\n" : ''; @@ -209,11 +209,15 @@ class TraditionalImageGallery extends ImageGalleryBase { $galleryText = $textlink . $text . $meta; $galleryText = $this->wrapGalleryText( $galleryText, $thumb ); + $gbWidth = $this->getGBWidth( $thumb ) . 'px'; + if ( $this->getGBWidthOverwrite( $thumb ) ) { + $gbWidth = $this->getGBWidthOverwrite( $thumb ); + } # Weird double wrapping (the extra div inside the li) needed due to FF2 bug # Can be safely removed if FF2 falls completely out of existence $output .= "\n\t\t" . '
  • ' - . '
    ' + . $gbWidth . '">' + . '
    ' . $thumbhtml . $galleryText . "\n\t\t
  • "; @@ -272,6 +276,17 @@ class TraditionalImageGallery extends ImageGalleryBase { return 8; } + /** + * Length to truncate filename to in caption when using "showfilename" (if int). + * A value of 'true' will truncate the filename to one line using CSS, while + * 'false' will disable truncating. + * + * @return int|bool + */ + protected function getCaptionLength() { + return $this->mCaptionLength; + } + /** * Get total padding. * @@ -319,7 +334,7 @@ class TraditionalImageGallery extends ImageGalleryBase { } /** - * Width of gallerybox
  • . + * Computed width of gallerybox
  • . * * Generally is the width of the image, plus padding on image * plus padding on gallerybox. @@ -332,6 +347,21 @@ class TraditionalImageGallery extends ImageGalleryBase { return $this->mWidths + $this->getThumbPadding() + $this->getGBPadding(); } + /** + * Allows overwriting the computed width of the gallerybox
  • with a string, + * like '100%'. + * + * Generally is the width of the image, plus padding on image + * plus padding on gallerybox. + * + * @note Important: parameter will be false if no thumb used. + * @param MediaTransformOutput|bool $thumb MediaTransformObject object or false. + * @return bool|string Ignored if false. + */ + protected function getGBWidthOverwrite( $thumb ) { + return false; + } + /** * Get a list of modules to include in the page. * -- 2.20.1