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 ) {
73 $linkBatchFactory = MediaWikiServices::getInstance()->getLinkBatchFactory();
74 $lb = $linkBatchFactory->newLinkBatch();
75 foreach ( $this->mImages as [
$title, ] ) {
82 $enableLegacyMediaDOM = $this->
getConfig()->get(
'ParserEnableLegacyMediaDOM' );
84 # Output each image...
85 foreach ( $this->mImages as [ $nt, $text, $alt, $link, $handlerOpts, $loading ] ) {
90 if ( $nt->getNamespace() ===
NS_FILE ) {
92 if ( $resolveFilesViaParser ) {
93 # Give extensions a chance to select the file revision for us
95 Hooks::runner()->onBeforeParserFetchFileAndTitle(
96 $this->mParser, $nt, $options, $descQuery );
97 # Fetch and register the file (file title may be different via hooks)
98 list( $img, $nt ) = $this->mParser->fetchFileAndTitle( $nt, $options );
100 $img = $repoGroup->findFile( $nt );
107 $transformOptions = $params + $handlerOpts;
112 # We're dealing with a non-image, spit out the name and be done with it.
113 $thumbhtml =
"\n\t\t\t" .
'<div class="thumb" style="height: '
115 . htmlspecialchars( $nt->getText() ) .
'</div>';
117 if ( $resolveFilesViaParser ) {
118 $this->mParser->addTrackingCategory(
'broken-file-category' );
120 } elseif ( $this->mHideBadImages &&
121 $badFileLookup->isBadFile( $nt->getDBkey(), $this->getContextTitle() )
123 # The image is bad, so just show it as a text link.
124 $thumbhtml =
"\n\t\t\t" .
'<div class="thumb" style="height: ' .
126 $linkRenderer->makeKnownLink( $nt, $nt->getText() ) .
129 $thumb = $img->transform( $transformOptions );
131 # Error generating thumbnail.
132 $thumbhtml =
"\n\t\t\t" .
'<div class="thumb" style="height: '
134 . htmlspecialchars( $img->getLastError() ) .
'</div>';
137 $vpad = $this->
getVPad( $this->mHeights, $thumb->getHeight() );
141 'desc-query' => $descQuery,
143 'custom-url-link' => $link
148 if ( $alt ==
'' && $text ==
'' ) {
149 $imageParameters[
'alt'] = $nt->getText();
153 $imageParameters[
'loading'] =
'lazy';
160 switch ( $img->getMediaType() ) {
162 $rdfaType =
'mw:Audio';
165 $rdfaType =
'mw:Video';
168 $rdfaType =
'mw:Image';
171 $thumbhtml = $thumb->toHtml( $imageParameters );
173 if ( !$enableLegacyMediaDOM ) {
174 $thumbhtml = Html::rawElement(
175 'span', [
'typeof' => $rdfaType ], $thumbhtml
179 $thumbhtml = Html::rawElement(
'div', [
180 # Auto-margin centering
for block-level elements. Needed
181 # now that we have video handlers since they may emit block-
182 # level elements as opposed to simple <img> tags. ref
184 'style' =>
"margin:{$vpad}px auto;",
187 # Set both fixed width and min-height.
189 $thumbhtml =
"\n\t\t\t" . Html::rawElement(
'div', [
191 'style' =>
"width: {$width}px;",
196 $handler = $img->getHandler();
197 if ( $resolveFilesViaParser && $handler ) {
198 $handler->parserTransformHook( $this->mParser, $img );
205 if ( $this->mShowDimensions ) {
206 $meta[] = htmlspecialchars( $img->getDimensionsString() );
208 if ( $this->mShowBytes ) {
209 $meta[] = htmlspecialchars(
$lang->formatSize( $img->getSize() ) );
211 } elseif ( $this->mShowDimensions || $this->mShowBytes ) {
212 $meta[] = $this->
msg(
'filemissing' )->escaped();
214 $meta =
$lang->semicolonList( $meta );
219 $textlink = $this->mShowFilename ?
223 $galleryText = $textlink . $text . $meta;
226 $gbWidth = $this->
getGBWidth( $thumb ) .
'px';
230 # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
231 # Can be safely removed if FF2 falls completely out of existence
232 $output .=
"\n\t\t" .
'<li class="gallerybox" style="width: '
234 .
'<div style="width: ' . $gbWidth .
'">'
237 .
"\n\t\t</div></li>";
239 $output .=
"\n</ul>";