3 * Packed image gallery. All images adjusted to be same height.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
23 use MediaWiki\Context\IContextSource
;
25 class PackedImageGallery
extends TraditionalImageGallery
{
26 public function __construct( $mode = 'traditional', ?IContextSource
$context = null ) {
27 parent
::__construct( $mode, $context );
28 // Does not support per row option.
33 * We artificially have 1.5 the resolution necessary so that
34 * we can scale it up by that much on the client side, without
35 * worrying about requesting a new image.
37 private const SCALE_FACTOR
= 1.5;
39 protected function getVPad( $boxHeight, $thumbHeight ) {
40 return ( $this->getThumbPadding() +
$boxHeight - $thumbHeight / self
::SCALE_FACTOR
) / 2;
43 protected function getThumbPadding() {
47 protected function getGBPadding() {
52 * @param File|false $img The file being transformed. May be false
55 protected function getThumbParams( $img ) {
56 if ( $img && $img->getMediaType() === MEDIATYPE_AUDIO
) {
57 $width = $this->mWidths
;
59 // We want the width not to be the constraining
60 // factor, so use random big number.
61 $width = $this->mHeights
* 10 +
100;
64 // self::SCALE_FACTOR so the js has some room to manipulate sizes.
66 'width' => (int)floor( $width * self
::SCALE_FACTOR
),
67 'height' => (int)floor( $this->mHeights
* self
::SCALE_FACTOR
),
71 protected function getThumbDivWidth( $thumbWidth ) {
72 // Require at least 60px wide, so caption is wide enough to work.
73 if ( $thumbWidth < 60 * self
::SCALE_FACTOR
) {
74 $thumbWidth = 60 * self
::SCALE_FACTOR
;
77 return $thumbWidth / self
::SCALE_FACTOR +
$this->getThumbPadding();
81 * @param MediaTransformOutput|false $thumb The thumbnail, or false if no
82 * thumb (which can happen)
85 protected function getGBWidth( $thumb ) {
86 $thumbWidth = $thumb ?
$thumb->getWidth() : $this->mWidths
* self
::SCALE_FACTOR
;
88 return $this->getThumbDivWidth( $thumbWidth ) +
$this->getGBPadding();
91 protected function adjustImageParameters( $thumb, &$imageParameters ) {
92 // Re-adjust back to normal size.
93 $imageParameters['override-width'] = ceil( $thumb->getWidth() / self
::SCALE_FACTOR
);
94 $imageParameters['override-height'] = ceil( $thumb->getHeight() / self
::SCALE_FACTOR
);
98 * Add javascript which auto-justifies the rows by manipulating the image sizes.
99 * Also ensures that the hover version of this degrades gracefully.
102 protected function getModules() {
103 return [ 'mediawiki.page.gallery' ];
107 * Do not support per-row on packed. It really doesn't work
108 * since the images have varying widths.
111 public function setPerRow( $num ) {