MediaWiki master
PackedImageGallery.php
Go to the documentation of this file.
1<?php
7namespace MediaWiki\Gallery;
8
12
18 public function __construct( $mode = 'traditional', ?IContextSource $context = null ) {
19 parent::__construct( $mode, $context );
20 // Does not support per row option.
21 $this->mPerRow = 0;
22 }
23
29 private const SCALE_FACTOR = 1.5;
30
32 protected function getVPad( $boxHeight, $thumbHeight ) {
33 return ( $this->getThumbPadding() + $boxHeight - $thumbHeight / self::SCALE_FACTOR ) / 2;
34 }
35
37 protected function getThumbPadding() {
38 return 0;
39 }
40
42 protected function getGBPadding() {
43 return 2;
44 }
45
50 protected function getThumbParams( $img ) {
51 if ( $img && $img->getMediaType() === MEDIATYPE_AUDIO ) {
52 $width = $this->mWidths;
53 } else {
54 // We want the width not to be the constraining
55 // factor, so use random big number.
56 $width = $this->mHeights * 10 + 100;
57 }
58
59 // self::SCALE_FACTOR so the js has some room to manipulate sizes.
60 return [
61 'width' => (int)floor( $width * self::SCALE_FACTOR ),
62 'height' => (int)floor( $this->mHeights * self::SCALE_FACTOR ),
63 ];
64 }
65
67 protected function getThumbDivWidth( $thumbWidth ) {
68 // Require at least 60px wide, so caption is wide enough to work.
69 if ( $thumbWidth < 60 * self::SCALE_FACTOR ) {
70 $thumbWidth = 60 * self::SCALE_FACTOR;
71 }
72
73 return $thumbWidth / self::SCALE_FACTOR + $this->getThumbPadding();
74 }
75
81 protected function getGBWidth( $thumb ) {
82 $thumbWidth = $thumb ? $thumb->getWidth() : $this->mWidths * self::SCALE_FACTOR;
83
84 return $this->getThumbDivWidth( $thumbWidth ) + $this->getGBPadding();
85 }
86
88 protected function adjustImageParameters( $thumb, &$imageParameters ) {
89 // Re-adjust back to normal size.
90 $imageParameters['override-width'] = ceil( $thumb->getWidth() / self::SCALE_FACTOR );
91 $imageParameters['override-height'] = ceil( $thumb->getHeight() / self::SCALE_FACTOR );
92 }
93
99 protected function getModules() {
100 return [ 'mediawiki.page.gallery' ];
101 }
102
108 public function setPerRow( $num ) {
109 }
110}
111
113class_alias( PackedImageGallery::class, 'PackedImageGallery' );
const MEDIATYPE_AUDIO
Definition defines.php:19
Implements some public methods and some protected utility functions which are required by multiple ch...
Definition File.php:80
__construct( $mode='traditional', ?IContextSource $context=null)
Create a new image gallery object.You should not call this directly, but instead use ImageGalleryBase...
getModules()
Add javascript which auto-justifies the rows by manipulating the image sizes.
setPerRow( $num)
Do not support per-row on packed.
getThumbDivWidth( $thumbWidth)
Get the width of the inner div that contains the thumbnail in question.This is the div with the class...
adjustImageParameters( $thumb, &$imageParameters)
Adjust the image parameters for a thumbnail.Used by a subclass to insert extra high resolution images...
getThumbPadding()
How much padding the thumb has between the image and the inner div that contains the border....
getVPad( $boxHeight, $thumbHeight)
Get vertical padding for a thumbnail.Generally this is the total height minus how high the thumb is....
getGBPadding()
GB stands for gallerybox (as in the element)int
Base class for the output of MediaHandler::doTransform() and File::transform().
Interface for objects which can provide a MediaWiki context on request.