40 $resolveFilesViaParser = $this->mParser instanceof
Parser;
41 if ( $resolveFilesViaParser ) {
44 $linkRenderer = $this->mParser->getLinkRenderer();
45 $badFileLookup = $this->mParser->getBadFileLookup();
48 $services = MediaWikiServices::getInstance();
49 $repoGroup = $services->getRepoGroup();
50 $linkRenderer = $services->getLinkRenderer();
51 $badFileLookup = $services->getBadFileLookup();
54 if ( $this->mPerRow > 0 ) {
55 $maxwidth = $this->mPerRow * ( $this->mWidths + $this->
getAllPadding() );
56 $oldStyle = $this->mAttribs[
'style'] ??
'';
57 $this->mAttribs[
'style'] =
"max-width: {$maxwidth}px;" . $oldStyle;
60 $attribs = Sanitizer::mergeAttributes(
61 [
'class' =>
'gallery mw-gallery-' . $this->mMode ], $this->mAttribs );
64 $out->addModuleStyles(
'mediawiki.page.gallery.styles' );
65 $output = Xml::openElement(
'ul', $attribs );
66 if ( $this->mCaption ) {
67 $output .=
"\n\t<li class='gallerycaption'>{$this->mCaption}</li>";
70 if ( $this->mShowFilename ) {
74 foreach ( $this->mImages as $img ) {
75 $lb->addObj( $img[0] );
81 # Output each image...
82 foreach ( $this->mImages as $pair ) {
85 list( $nt, $text, $alt, $link, $handlerOpts, $loading ) = $pair;
88 if ( $nt->getNamespace() ===
NS_FILE ) {
90 if ( $resolveFilesViaParser ) {
91 # Give extensions a chance to select the file revision for us
93 Hooks::runner()->onBeforeParserFetchFileAndTitle(
94 $this->mParser, $nt, $options, $descQuery );
95 # Fetch and register the file (file title may be different via hooks)
96 list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options );
98 $img = $repoGroup->findFile( $nt );
106 $transformOptions = $params + $pair[4];
111 # We're dealing with a non-image, spit out the name and be done with it.
112 $thumbhtml =
"\n\t\t\t" .
'<div class="thumb" style="height: '
114 . htmlspecialchars( $nt->getText() ) .
'</div>';
116 if ( $resolveFilesViaParser ) {
117 $this->mParser->addTrackingCategory(
'broken-file-category' );
119 } elseif ( $this->mHideBadImages &&
120 $badFileLookup->isBadFile( $nt->getDBkey(), $this->getContextTitle() )
122 # The image is blacklisted, just show it as a text link.
123 $thumbhtml =
"\n\t\t\t" .
'<div class="thumb" style="height: ' .
125 $linkRenderer->makeKnownLink( $nt, $nt->getText() ) .
128 $thumb = $img->transform( $transformOptions );
130 # Error generating thumbnail.
131 $thumbhtml =
"\n\t\t\t" .
'<div class="thumb" style="height: '
133 . htmlspecialchars( $img->getLastError() ) .
'</div>';
136 $vpad = $this->
getVPad( $this->mHeights, $thumb->getHeight() );
140 'desc-query' => $descQuery,
142 'custom-url-link' => $link
147 if ( $alt ==
'' && $text ==
'' ) {
148 $imageParameters[
'alt'] = $nt->getText();
152 $imageParameters[
'loading'] =
'lazy';
159 # Set both fixed width and min-height.
160 $thumbhtml =
"\n\t\t\t"
161 .
'<div class="thumb" style="width: '
163 # Auto-margin centering for block-level elements. Needed
164 # now that we have video handlers since they may emit block-
165 # level elements as opposed to simple <img> tags. ref
167 .
'<div style="margin:' . $vpad .
'px auto;">'
168 . $thumb->toHtml( $imageParameters ) .
'</div></div>';
172 $handler = $img->getHandler();
173 if ( $resolveFilesViaParser && $handler ) {
174 $handler->parserTransformHook( $this->mParser, $img );
181 if ( $this->mShowDimensions ) {
182 $meta[] = htmlspecialchars( $img->getDimensionsString() );
184 if ( $this->mShowBytes ) {
185 $meta[] = htmlspecialchars(
$lang->formatSize( $img->getSize() ) );
187 } elseif ( $this->mShowDimensions || $this->mShowBytes ) {
188 $meta[] = $this->
msg(
'filemissing' )->escaped();
190 $meta =
$lang->semicolonList( $meta );
195 $textlink = $this->mShowFilename ?
199 $galleryText = $textlink . $text . $meta;
202 $gbWidth = $this->
getGBWidth( $thumb ) .
'px';
206 # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
207 # Can be safely removed if FF2 falls completely out of existence
208 $output .=
"\n\t\t" .
'<li class="gallerybox" style="width: '
210 .
'<div style="width: ' . $gbWidth .
'">'
213 .
"\n\t\t</div></li>";
215 $output .=
"\n</ul>";