44 $resolveFilesViaParser = $this->mParser instanceof
Parser;
45 if ( $resolveFilesViaParser ) {
46 $parserOutput = $this->mParser->
getOutput();
48 $linkRenderer = $this->mParser->getLinkRenderer();
49 $badFileLookup = $this->mParser->getBadFileLookup();
52 $services = MediaWikiServices::getInstance();
53 $repoGroup = $services->getRepoGroup();
54 $linkRenderer = $services->getLinkRenderer();
55 $badFileLookup = $services->getBadFileLookup();
58 if ( $this->mPerRow > 0 ) {
59 $maxwidth = $this->mPerRow * ( $this->mWidths + $this->
getAllPadding() );
60 $oldStyle = $this->mAttribs[
'style'] ??
'';
61 $this->mAttribs[
'style'] =
"max-width: {$maxwidth}px;" . $oldStyle;
65 [
'class' =>
'gallery mw-gallery-' . $this->mMode ], $this->mAttribs );
67 $parserOutput->addModules( $this->
getModules() );
68 $parserOutput->addModuleStyles( [
'mediawiki.page.gallery.styles' ] );
70 if ( $this->mCaption ) {
71 $output .=
"\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
74 if ( $this->mShowFilename ) {
77 $linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory();
78 $lb = $linkBatchFactory->newLinkBatch();
79 foreach ( $this->mImages as [
$title, ] ) {
86 $enableLegacyMediaDOM =
87 $this->
getConfig()->get( MainConfigNames::ParserEnableLegacyMediaDOM );
89 # Output each image...
90 foreach ( $this->mImages as [ $nt, $text, $alt, $link, $handlerOpts, $loading, $imageOptions ] ) {
95 if ( $nt->inNamespace(
NS_FILE ) && !$nt->isExternal() ) {
97 if ( $resolveFilesViaParser ) {
98 # Give extensions a chance to select the file revision for us
102 $this->mParser, $nt, $options, $descQuery );
103 # Fetch and register the file (file title may be different via hooks)
104 [ $img, $nt ] = $this->mParser->fetchFileAndTitle( $nt, $options );
106 $img = $repoGroup->findFile( $nt );
113 $thumb = $img ? $img->transform( $transformOptions ) :
false;
115 $rdfaType =
'mw:File';
117 $isBadFile = $img && $thumb && $this->mHideBadImages &&
118 $badFileLookup->isBadFile( $nt->getDBkey(), $this->getContextTitle() );
120 if ( !$img || !$thumb || $isBadFile ) {
121 $rdfaType =
'mw:Error ' . $rdfaType;
123 if ( $enableLegacyMediaDOM ) {
125 $thumbhtml = $linkRenderer->makeKnownLink( $nt, $nt->getText() );
127 $thumbhtml = htmlspecialchars( $img ? $img->getLastError() : $nt->getText() );
132 $thumbhtml = Linker::makeBrokenImageLinkObj(
133 $nt, $label,
'',
'',
'',
false, $transformOptions
135 $thumbhtml = Html::rawElement(
'span', [
'typeof' => $rdfaType ], $thumbhtml );
138 $thumbhtml =
"\n\t\t\t" .
'<div class="thumb" style="height: '
140 . $thumbhtml .
'</div>';
142 if ( !$img && $resolveFilesViaParser ) {
143 $this->mParser->addTrackingCategory(
'broken-file-category' );
147 $vpad = $this->
getVPad( $this->mHeights, $thumb->getHeight() );
150 if ( $imageOptions ===
null ) {
153 'desc-query' => $descQuery,
155 'custom-url-link' => $link
163 if ( $alt !==
null ) {
164 $params[
'alt'] = $alt;
166 $params[
'title'] = $imageOptions[
'title'];
167 $imageParameters = Linker::getImageLinkMTOParams(
168 $imageOptions, $descQuery, $this->mParser
173 $imageParameters[
'loading'] =
'lazy';
178 Linker::processResponsiveImages( $img, $thumb, $transformOptions );
180 $thumbhtml = $thumb->toHtml( $imageParameters );
182 if ( !$enableLegacyMediaDOM ) {
183 $thumbhtml = Html::rawElement(
184 'span', [
'typeof' => $rdfaType ], $thumbhtml
187 $thumbhtml = Html::rawElement(
'div', [
188 # Auto-margin centering
for block-level elements. Needed
189 # now that we have video handlers since they may emit block-
190 # level elements as opposed to simple <img> tags. ref
192 'style' =>
"margin:{$vpad}px auto;",
196 # Set both fixed width and min-height.
199 $thumbhtml =
"\n\t\t\t" . Html::rawElement(
'div', [
201 'style' =>
"width: {$width}px;" .
202 ( !$enableLegacyMediaDOM && $this->mMode ===
'traditional' ?
203 " height: {$height}px;" :
'' ),
207 if ( $resolveFilesViaParser ) {
209 $handler = $img->getHandler();
211 $handler->parserTransformHook( $this->mParser, $img );
213 $this->mParser->modifyImageHtml(
214 $img, [
'handler' => $imageParameters ], $thumbhtml );
220 if ( $this->mShowDimensions ) {
221 $meta[] = htmlspecialchars( $img->getDimensionsString() );
223 if ( $this->mShowBytes ) {
224 $meta[] = htmlspecialchars(
$lang->formatSize( $img->getSize() ) );
226 } elseif ( $this->mShowDimensions || $this->mShowBytes ) {
227 $meta[] = $this->
msg(
'filemissing' )->escaped();
229 $meta =
$lang->semicolonList( $meta );
234 $textlink = $this->mShowFilename ?
238 $galleryText = $this->
wrapGalleryText( $textlink . $text . $meta, $thumb );
241 # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
242 # Can be safely removed if FF2 falls completely out of existence
243 $output .=
"\n\t\t" .
'<li class="gallerybox" style="width: '
245 . ( $enableLegacyMediaDOM ?
'<div style="width: ' . $gbWidth .
'">' :
'' )
249 . ( $enableLegacyMediaDOM ?
'</div>' :
'' )
252 $output .=
"\n</ul>";
271 'class' =>
'galleryfilename' .
272 ( $this->getCaptionLength() ===
true ?
' galleryfilename-truncate' :
'' )
286 # ATTENTION: The newline after <div class="gallerytext"> is needed to
287 # accommodate htmltidy which in version 4.8.6 generated crackpot html in
288 # its absence, see: https:
291 return "\n\t\t\t" .
'<div class="gallerytext">' .
"\n"
355 protected function getVPad( $boxHeight, $thumbHeight ) {
msg( $key,... $params)
Get a Message object with context set Parameters are the same as wfMessage()
static runner()
Get a HookRunner instance for calling hooks using the new interfaces.
bool int $mCaptionLength
Length to truncate filename to in caption when using "showfilename".
getRenderLang()
Determines the correct language to be used for this image gallery.
Base class for language-specific code.
truncateForVisual( $string, $length, $ellipsis='...', $adjustLength=true)
Truncate a string to a specified number of characters, appending an optional string (e....
A class containing constants representing the names of configuration variables.
PHP Parser - Processes wiki markup (which uses a more user-friendly syntax, such as "[[link]]" for ma...
static mergeAttributes( $a, $b)
Merge two sets of HTML attributes.
getThumbPadding()
How much padding the thumb has between the image and the inner div that contains the border.
getCaptionLength()
Length (in characters) to truncate filename to in caption when using "showfilename" (if int).
getVPad( $boxHeight, $thumbHeight)
Get vertical padding for a thumbnail.
getCaptionHtml(Title $nt, Language $lang, LinkRenderer $linkRenderer)
getThumbParams( $img)
Get the transform parameters for a thumbnail.
toHTML()
Return a HTML representation of the image gallery.
getGBWidth( $thumb)
Computed width of gallerybox .
getModules()
Get a list of modules to include in the page.
getGBBorders()
Get how much extra space the borders around the image takes up.
wrapGalleryText( $galleryText, $thumb)
Add the wrapper html around the thumb's caption.
adjustImageParameters( $thumb, &$imageParameters)
Adjust the image parameters for a thumbnail.
getGBWidthOverwrite( $thumb)
Allows overwriting the computed width of the gallerybox with a string, like '100'.
getAllPadding()
Get total padding.
getThumbDivWidth( $thumbWidth)
Get the width of the inner div that contains the thumbnail in question.
static openElement( $element, $attribs=null)
This opens an XML element.
if(!isset( $args[0])) $lang