mParser instanceof Parser;
if ( $resolveFilesViaParser ) {
$parserOutput = $this->mParser->getOutput();
$repoGroup = null;
$linkRenderer = $this->mParser->getLinkRenderer();
$badFileLookup = $this->mParser->getBadFileLookup();
} else {
$parserOutput = $this->getOutput();
$services = MediaWikiServices::getInstance();
$repoGroup = $services->getRepoGroup();
$linkRenderer = $services->getLinkRenderer();
$badFileLookup = $services->getBadFileLookup();
}
if ( $this->mPerRow > 0 ) {
$maxwidth = $this->mPerRow * ( $this->mWidths + $this->getAllPadding() );
$oldStyle = $this->mAttribs['style'] ?? '';
$this->mAttribs['style'] = "max-width: {$maxwidth}px;" . $oldStyle;
}
$attribs = Sanitizer::mergeAttributes(
[ 'class' => 'gallery mw-gallery-' . $this->mMode ], $this->mAttribs );
$parserOutput->addModules( $this->getModules() );
$parserOutput->addModuleStyles( [ 'mediawiki.page.gallery.styles' ] );
$output = Xml::openElement( 'ul', $attribs );
if ( $this->mCaption ) {
$output .= "\n\t
'
. htmlspecialchars( $nt->getText() ) . '
';
if ( $resolveFilesViaParser ) {
$this->mParser->addTrackingCategory( 'broken-file-category' );
}
} elseif ( $this->mHideBadImages &&
$badFileLookup->isBadFile( $nt->getDBkey(), $this->getContextTitle() )
) {
# The image is bad, so just show it as a text link.
$thumbhtml = "\n\t\t\t" . ''
. htmlspecialchars( $img->getLastError() ) . '
';
} else {
/** @var MediaTransformOutput $thumb */
$vpad = $this->getVPad( $this->mHeights, $thumb->getHeight() );
$imageParameters = [
'desc-link' => true,
'desc-query' => $descQuery,
'alt' => $alt,
'custom-url-link' => $link
];
// In the absence of both alt text and caption, fall back on
// providing screen readers with the filename as alt text
if ( $alt == '' && $text == '' ) {
$imageParameters['alt'] = $nt->getText();
}
if ( $loading === ImageGalleryBase::LOADING_LAZY ) {
$imageParameters['loading'] = 'lazy';
}
$this->adjustImageParameters( $thumb, $imageParameters );
Linker::processResponsiveImages( $img, $thumb, $transformOptions );
switch ( $img->getMediaType() ) {
case 'AUDIO':
$rdfaType = 'mw:Audio';
break;
case 'VIDEO':
$rdfaType = 'mw:Video';
break;
default:
$rdfaType = 'mw:Image';
}
$thumbhtml = $thumb->toHtml( $imageParameters );
if ( !$enableLegacyMediaDOM ) {
$thumbhtml = Html::rawElement(
'span', [ 'typeof' => $rdfaType ], $thumbhtml
);
}
if ( $enableLegacyMediaDOM ) {
$thumbhtml = Html::rawElement( 'div', [
# Auto-margin centering for block-level elements. Needed
# now that we have video handlers since they may emit block-
# level elements as opposed to simple is needed to
# accommodate htmltidy which in version 4.8.6 generated crackpot html in
# its absence, see: https://phabricator.wikimedia.org/T3765
# -Ævar
return "\n\t\t\t" . '
' . "\n"
. $galleryText
. "\n\t\t\t
";
}
/**
* How much padding the thumb has between the image and the inner div
* that contains the border. This is for both vertical and horizontal
* padding. (However, it is cut in half in the vertical direction).
* @return float
*/
protected function getThumbPadding() {
return 30;
}
/**
* @note GB stands for gallerybox (as in the
element)
*
* @return int
*/
protected function getGBPadding() {
return 5;
}
/**
* Get how much extra space the borders around the image takes up.
*
* For this mode, it is 2px borders on each side + 2px implied padding on
* each side from the stylesheet, giving us 2*2+2*2 = 8.
* @return int
*/
protected function getGBBorders() {
return 8;
}
/**
* Length (in characters) to truncate filename to in caption when using "showfilename" (if int).
* A value of 'true' will truncate the filename to one line using CSS, while
* 'false' will disable truncating.
*
* @return int|bool
*/
protected function getCaptionLength() {
return $this->mCaptionLength;
}
/**
* Get total padding.
*
* @return int Number of pixels of whitespace surrounding the thumbnail.
*/
protected function getAllPadding() {
return $this->getThumbPadding() + $this->getGBPadding() + $this->getGBBorders();
}
/**
* Get vertical padding for a thumbnail
*
* Generally this is the total height minus how high the thumb is.
*
* @param int $boxHeight How high we want the box to be.
* @param int $thumbHeight How high the thumbnail is.
* @return float Vertical padding to add on each side.
*/
protected function getVPad( $boxHeight, $thumbHeight ) {
return ( $this->getThumbPadding() + $boxHeight - $thumbHeight ) / 2;
}
/**
* Get the transform parameters for a thumbnail.
*
* @param File $img The file in question. May be false for invalid image
* @return array
*/
protected function getThumbParams( $img ) {
return [
'width' => $this->mWidths,
'height' => $this->mHeights
];
}
/**
* Get the width of the inner div that contains the thumbnail in
* question. This is the div with the class of "thumb".
*
* @param int $thumbWidth The width of the thumbnail.
* @return float Width of inner thumb div.
*/
protected function getThumbDivWidth( $thumbWidth ) {
return $this->mWidths + $this->getThumbPadding();
}
/**
* Computed width of gallerybox .
*
* Generally is the width of the image, plus padding on image
* plus padding on gallerybox.
*
* @note Important: parameter will be false if no thumb used.
* @param MediaTransformOutput|false $thumb MediaTransformObject object or false.
* @return float Width of gallerybox element
*/
protected function getGBWidth( $thumb ) {
return $this->mWidths + $this->getThumbPadding() + $this->getGBPadding();
}
/**
* Allows overwriting the computed width of the gallerybox with a string,
* like '100%'.
*
* Generally is the width of the image, plus padding on image
* plus padding on gallerybox.
*
* @note Important: parameter will be false if no thumb used.
* @param MediaTransformOutput|false $thumb MediaTransformObject object or false.
* @return string|false Ignored if false.
*/
protected function getGBWidthOverwrite( $thumb ) {
return false;
}
/**
* Get a list of modules to include in the page.
*
* Primarily intended for subclasses.
*
* @return array Modules to include
*/
protected function getModules() {
return [];
}
/**
* Adjust the image parameters for a thumbnail.
*
* Used by a subclass to insert extra high resolution images.
* @param MediaTransformOutput $thumb The thumbnail
* @param array &$imageParameters Array of options
*/
protected function adjustImageParameters( $thumb, &$imageParameters ) {
}
}