From 486027d7d5bec36728aa17130d32fe98cf58947f Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Fri, 8 Jul 2016 17:41:51 +0100 Subject: [PATCH] Truncate gallery caption filenames with CSS Bug: T139766 Change-Id: Iba7efb8f89e132b8eb39f3c9ba76d2b1a9181b2f --- includes/DefaultSettings.php | 5 ++++- includes/gallery/TraditionalImageGallery.php | 12 ++++++++++-- resources/src/mediawiki/page/gallery.css | 10 ++++++++++ tests/parser/parserTests.txt | 8 ++++---- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index f6611acad0..50884458f5 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -1444,7 +1444,10 @@ $wgGalleryOptions = [ 'imagesPerRow' => 0, // Default number of images per-row in the gallery. 0 -> Adapt to screensize 'imageWidth' => 120, // Width of the cells containing images in galleries (in "px") 'imageHeight' => 120, // Height of the cells containing images in galleries (in "px") - 'captionLength' => 25, // Length to truncate filename to in caption when using "showfilename" + 'captionLength' => true, // Deprecated @since 1.28 + // 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. 'showBytes' => true, // Show the filesize in bytes in categories 'mode' => 'traditional', ]; diff --git a/includes/gallery/TraditionalImageGallery.php b/includes/gallery/TraditionalImageGallery.php index 2fb22815d5..f6527b820e 100644 --- a/includes/gallery/TraditionalImageGallery.php +++ b/includes/gallery/TraditionalImageGallery.php @@ -189,8 +189,16 @@ class TraditionalImageGallery extends ImageGalleryBase { // Preloaded into LinkCache above Linker::linkKnown( $nt, - htmlspecialchars( $lang->truncate( $nt->getText(), $this->mCaptionLength ) ) - ) . "
\n" : + htmlspecialchars( + $this->mCaptionLength !== true ? + $lang->truncate( $nt->getText(), $this->mCaptionLength ) : + $nt->getText() + ), + [ + 'class' => 'galleryfilename' . + ( $this->mCaptionLength === true ? ' galleryfilename-truncate' : '' ) + ] + ) . "\n" : ''; $galleryText = $textlink . $text . $fileSize; diff --git a/resources/src/mediawiki/page/gallery.css b/resources/src/mediawiki/page/gallery.css index 4d43e6af83..d765144294 100644 --- a/resources/src/mediawiki/page/gallery.css +++ b/resources/src/mediawiki/page/gallery.css @@ -45,6 +45,16 @@ div.gallerytext { word-wrap: break-word; } +.galleryfilename { + display: block; +} + +.galleryfilename-truncate { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + /* new gallery stuff */ ul.mw-gallery-nolines li.gallerybox div.thumb { background-color: transparent; diff --git a/tests/parser/parserTests.txt b/tests/parser/parserTests.txt index 2e059d7423..aa5ed05967 100644 --- a/tests/parser/parserTests.txt +++ b/tests/parser/parserTests.txt @@ -18816,7 +18816,7 @@ File:Foobar.jpg
  • Nonexistent.jpg
    @@ -18824,14 +18824,14 @@ caption
  • Nonexistent.jpg
  • @@ -18839,7 +18839,7 @@ some caption Main Page
  • Foobar.jpg
  • -- 2.20.1