Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / gallery / PackedImageGallery.php
blob978d8d5663afaca10e4b30a8f5f3eae8af7bcd48
1 <?php
2 /**
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
20 * @file
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.
29 $this->mPerRow = 0;
32 /**
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() {
44 return 0;
47 protected function getGBPadding() {
48 return 2;
51 /**
52 * @param File|false $img The file being transformed. May be false
53 * @return array
55 protected function getThumbParams( $img ) {
56 if ( $img && $img->getMediaType() === MEDIATYPE_AUDIO ) {
57 $width = $this->mWidths;
58 } else {
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.
65 return [
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();
80 /**
81 * @param MediaTransformOutput|false $thumb The thumbnail, or false if no
82 * thumb (which can happen)
83 * @return float
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 );
97 /**
98 * Add javascript which auto-justifies the rows by manipulating the image sizes.
99 * Also ensures that the hover version of this degrades gracefully.
100 * @return array
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.
109 * @param int $num
111 public function setPerRow( $num ) {