Debian Codegraph @

includes/gallery/PackedImageGallery.php

raw symbols SCIP
1 <?php
2 /**
3 * Packed image gallery. All images adjusted to be same height.
4 *
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.
9 *
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.
14 *
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
19 *
20 * @file
21 */
22
23 use MediaWiki\Context\IContextSource;
24
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;
30 }
31
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.
36 */
37 private const SCALE_FACTOR = 1.5;
38
39 protected function getVPad( $boxHeight, $thumbHeight ) {
40 return ( $this->getThumbPadding() + $boxHeight - $thumbHeight / self::SCALE_FACTOR ) / 2;
41 }
42
43 protected function getThumbPadding() {
44 return 0;
45 }
46
47 protected function getGBPadding() {
48 return 2;
49 }
50
51 /**
52 * @param File|false $img The file being transformed. May be false
53 * @return array
54 */
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;
62 }
63
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 ),
68 ];
69 }
70
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;
75 }
76
77 return $thumbWidth / self::SCALE_FACTOR + $this->getThumbPadding();
78 }
79
80 /**
81 * @param MediaTransformOutput|false $thumb The thumbnail, or false if no
82 * thumb (which can happen)
83 * @return float
84 */
85 protected function getGBWidth( $thumb ) {
86 $thumbWidth = $thumb ? $thumb->getWidth() : $this->mWidths * self::SCALE_FACTOR;
87
88 return $this->getThumbDivWidth( $thumbWidth ) + $this->getGBPadding();
89 }
90
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 );
95 }
96
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
101 */
102 protected function getModules() {
103 return [ 'mediawiki.page.gallery' ];
104 }
105
106 /**
107 * Do not support per-row on packed. It really doesn't work
108 * since the images have varying widths.
109 * @param int $num
110 */
111 public function setPerRow( $num ) {
112 }
113 }