Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 10
CRAP
0.00% covered (danger)
0.00%
0 / 1
PackedImageGallery
0.00% covered (danger)
0.00%
0 / 21
0.00% covered (danger)
0.00%
0 / 10
210
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getVPad
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getThumbPadding
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getGBPadding
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getThumbParams
0.00% covered (danger)
0.00%
0 / 7
0.00% covered (danger)
0.00%
0 / 1
12
 getThumbDivWidth
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
6
 getGBWidth
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
6
 adjustImageParameters
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 getModules
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setPerRow
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
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
23use MediaWiki\Context\IContextSource;
24use MediaWiki\FileRepo\File\File;
25
26class PackedImageGallery extends TraditionalImageGallery {
27    public function __construct( $mode = 'traditional', ?IContextSource $context = null ) {
28        parent::__construct( $mode, $context );
29        // Does not support per row option.
30        $this->mPerRow = 0;
31    }
32
33    /**
34     * We artificially have 1.5 the resolution necessary so that
35     * we can scale it up by that much on the client side, without
36     * worrying about requesting a new image.
37     */
38    private const SCALE_FACTOR = 1.5;
39
40    protected function getVPad( $boxHeight, $thumbHeight ) {
41        return ( $this->getThumbPadding() + $boxHeight - $thumbHeight / self::SCALE_FACTOR ) / 2;
42    }
43
44    protected function getThumbPadding() {
45        return 0;
46    }
47
48    protected function getGBPadding() {
49        return 2;
50    }
51
52    /**
53     * @param File|false $img The file being transformed. May be false
54     * @return array
55     */
56    protected function getThumbParams( $img ) {
57        if ( $img && $img->getMediaType() === MEDIATYPE_AUDIO ) {
58            $width = $this->mWidths;
59        } else {
60            // We want the width not to be the constraining
61            // factor, so use random big number.
62            $width = $this->mHeights * 10 + 100;
63        }
64
65        // self::SCALE_FACTOR so the js has some room to manipulate sizes.
66        return [
67            'width' => (int)floor( $width * self::SCALE_FACTOR ),
68            'height' => (int)floor( $this->mHeights * self::SCALE_FACTOR ),
69        ];
70    }
71
72    protected function getThumbDivWidth( $thumbWidth ) {
73        // Require at least 60px wide, so caption is wide enough to work.
74        if ( $thumbWidth < 60 * self::SCALE_FACTOR ) {
75            $thumbWidth = 60 * self::SCALE_FACTOR;
76        }
77
78        return $thumbWidth / self::SCALE_FACTOR + $this->getThumbPadding();
79    }
80
81    /**
82     * @param MediaTransformOutput|false $thumb The thumbnail, or false if no
83     *   thumb (which can happen)
84     * @return float
85     */
86    protected function getGBWidth( $thumb ) {
87        $thumbWidth = $thumb ? $thumb->getWidth() : $this->mWidths * self::SCALE_FACTOR;
88
89        return $this->getThumbDivWidth( $thumbWidth ) + $this->getGBPadding();
90    }
91
92    protected function adjustImageParameters( $thumb, &$imageParameters ) {
93        // Re-adjust back to normal size.
94        $imageParameters['override-width'] = ceil( $thumb->getWidth() / self::SCALE_FACTOR );
95        $imageParameters['override-height'] = ceil( $thumb->getHeight() / self::SCALE_FACTOR );
96    }
97
98    /**
99     * Add javascript which auto-justifies the rows by manipulating the image sizes.
100     * Also ensures that the hover version of this degrades gracefully.
101     * @return array
102     */
103    protected function getModules() {
104        return [ 'mediawiki.page.gallery' ];
105    }
106
107    /**
108     * Do not support per-row on packed. It really doesn't work
109     * since the images have varying widths.
110     * @param int $num
111     */
112    public function setPerRow( $num ) {
113    }
114}