40 $resolveFilesViaParser = $this->mParser instanceof
Parser;
41 if ( $resolveFilesViaParser ) {
42 $parserOutput = $this->mParser->
getOutput();
44 $linkRenderer = $this->mParser->getLinkRenderer();
45 $badFileLookup = $this->mParser->getBadFileLookup();
49 $repoGroup = $services->getRepoGroup();
50 $linkRenderer = $services->getLinkRenderer();
51 $badFileLookup = $services->getBadFileLookup();
54 Html::addClass( $this->mAttribs[
'class'],
'gallery' );
55 Html::addClass( $this->mAttribs[
'class'],
'mw-gallery-' . $this->mMode );
57 if ( $this->mPerRow > 0 ) {
58 $maxwidth = $this->mPerRow * ( $this->mWidths + $this->
getAllPadding() );
59 $oldStyle = $this->mAttribs[
'style'] ??
'';
60 $this->mAttribs[
'style'] =
"max-width: {$maxwidth}px;" . $oldStyle;
63 $parserOutput->addModules( $this->
getModules() );
64 $parserOutput->addModuleStyles( [
'mediawiki.page.gallery.styles' ] );
65 $output = Html::openElement(
'ul', $this->mAttribs );
66 if ( $this->mCaption ) {
67 $output .=
"\n\t" . Html::rawElement(
'li', [
'class' =>
'gallerycaption' ], $this->mCaption );
70 if ( $this->mShowFilename ) {
74 $lb = $linkBatchFactory->newLinkBatch()->setCaller( __METHOD__ );
75 foreach ( $this->mImages as [ $title, ] ) {
76 $lb->addObj( $title );
84 # Output each image...
85 foreach ( $this->mImages as [ $nt, $text, $alt, $link, $handlerOpts, $loading, $imageOptions ] ) {
90 if ( $nt->inNamespace(
NS_FILE ) && !$nt->isExternal() ) {
92 if ( $resolveFilesViaParser ) {
93 # Give extensions a chance to select the file revision for us
95 $hookRunner->onBeforeParserFetchFileAndTitle(
97 $this->mParser, $nt, $options, $descQuery );
98 # Fetch and register the file (file title may be different via hooks)
99 [ $img, $nt ] = $this->mParser->fetchFileAndTitle( $nt, $options );
101 $img = $repoGroup->findFile( $nt );
108 $thumb = $img ? $img->transform( $transformOptions ) :
false;
110 $rdfaType =
'mw:File';
112 $isBadFile = $img && $thumb && $this->mHideBadImages &&
113 $badFileLookup->isBadFile( $nt->getDBkey(), $this->getContextTitle() );
115 if ( !$img || !$thumb || $thumb->isError() || $isBadFile ) {
116 $rdfaType =
'mw:Error ' . $rdfaType;
118 $currentExists = $img && $img->exists();
119 if ( $currentExists && !$thumb ) {
120 $label =
wfMessage(
'thumbnail_error',
'' )->text();
121 } elseif ( $thumb && $thumb->isError() ) {
124 'Unknown MediaTransformOutput: ' . get_class( $thumb )
126 $label = $thumb->toText();
130 $thumbhtml = Linker::makeBrokenImageLinkObj(
131 $nt, $label,
'',
'',
'',
false, $transformOptions, $currentExists
133 $thumbhtml = Html::rawElement(
'span', [
'typeof' => $rdfaType ], $thumbhtml );
135 $thumbhtml =
"\n\t\t\t" . Html::rawElement(
139 'style' =>
'height: ' . ( $this->
getThumbPadding() + $this->mHeights ) .
'px;'
144 if ( !$img && $resolveFilesViaParser ) {
145 $this->mParser->addTrackingCategory(
'broken-file-category' );
149 $vpad = $this->
getVPad( $this->mHeights, $thumb->getHeight() );
152 if ( $imageOptions ===
null ) {
155 'desc-query' => $descQuery,
157 'custom-url-link' => $link
165 if ( $alt !==
null ) {
166 $params[
'alt'] = $alt;
168 $params[
'title'] = $imageOptions[
'title'];
169 $params[
'img-class'] =
'mw-file-element';
170 $imageParameters = Linker::getImageLinkMTOParams(
171 $imageOptions, $descQuery, $this->mParser
176 $imageParameters[
'loading'] =
'lazy';
181 Linker::processResponsiveImages( $img, $thumb, $transformOptions );
183 $thumbhtml = $thumb->toHtml( $imageParameters );
184 $thumbhtml = Html::rawElement(
185 'span', [
'typeof' => $rdfaType ], $thumbhtml
188 # Set both fixed width and min-height.
191 $thumbhtml =
"\n\t\t\t" . Html::rawElement(
'div', [
193 'style' =>
"width: {$width}px;" .
194 ( $this->mMode ===
'traditional' ?
" height: {$height}px;" :
'' ),
198 if ( $resolveFilesViaParser ) {
200 $handler = $img->getHandler();
202 $handler->parserTransformHook( $this->mParser, $img );
204 $this->mParser->modifyImageHtml(
205 $img, [
'handler' => $imageParameters ], $thumbhtml );
211 if ( $this->mShowDimensions ) {
212 $meta[] = htmlspecialchars( $img->getDimensionsString() );
214 if ( $this->mShowBytes ) {
215 $meta[] = htmlspecialchars( $lang->formatSize( $img->getSize() ) );
217 } elseif ( $this->mShowDimensions || $this->mShowBytes ) {
218 $meta[] = $this->
msg(
'filemissing' )->escaped();
220 $meta = $lang->semicolonList( $meta );
222 $meta .= Html::rawElement(
'br', [] ) .
"\n";
225 $textlink = $this->mShowFilename ?
229 $galleryText = $this->
wrapGalleryText( $textlink . $text . $meta, $thumb );
232 # Weird double wrapping (the extra div inside the li) needed due to FF2 bug
233 # Can be safely removed if FF2 falls completely out of existence
234 $output .=
"\n\t\t" .
237 [
'class' =>
'gallerybox',
'style' =>
'width: ' . $gbWidth ],
243 $output .=
"\n" . Html::closeElement(
'ul' );