47 # Previous parameters:
48 # $file, $url, $width, $height, $path = false, $page = false
55 if ( is_array( $parameters ) ) {
56 $actualParams = $parameters + $defaults;
58 # Using old format, should convert. Later a warning could be added here.
59 $numArgs = func_num_args();
62 'height' => $parameters,
63 'page' => ( $numArgs > 5 ) ? func_get_arg( 5 ) : false
65 $path = ( $numArgs > 4 ) ? func_get_arg( 4 ) :
false;
72 # These should be integers when they get here.
73 # If not, there's a bug somewhere. But let's at
74 # least produce valid HTML code regardless.
76 $this->width = (int)round( $actualParams[
'width'] );
77 $this->height = (int)round( $actualParams[
'height'] );
79 $this->page = $actualParams[
'page'];
80 $this->lang = $actualParams[
'lang'];
116 public function toHtml( $options = [] ) {
117 $mainConfig = MediaWikiServices::getInstance()->getMainConfig();
118 $nativeImageLazyLoading = $mainConfig->get( MainConfigNames::NativeImageLazyLoading );
119 $enableLegacyMediaDOM = $mainConfig->get( MainConfigNames::ParserEnableLegacyMediaDOM );
121 if ( func_num_args() == 2 ) {
122 throw new MWException( __METHOD__ .
' called in the old style' );
125 $alt = $options[
'alt'] ??
'';
126 $query = $options[
'desc-query'] ??
'';
131 'decoding' =>
'async',
134 if ( $options[
'loading'] ?? $nativeImageLazyLoading ) {
135 $attribs[
'loading'] = $options[
'loading'] ??
'lazy';
138 if ( !empty( $options[
'custom-url-link'] ) ) {
139 $linkAttribs = [
'href' => $options[
'custom-url-link'] ];
140 if ( !empty( $options[
'title'] ) ) {
141 $linkAttribs[
'title'] = $options[
'title'];
143 if ( !empty( $options[
'custom-target-link'] ) ) {
144 $linkAttribs[
'target'] = $options[
'custom-target-link'];
145 } elseif ( !empty( $options[
'parser-extlink-target'] ) ) {
146 $linkAttribs[
'target'] = $options[
'parser-extlink-target'];
148 if ( !empty( $options[
'parser-extlink-rel'] ) ) {
149 $linkAttribs[
'rel'] = $options[
'parser-extlink-rel'];
151 } elseif ( !empty( $options[
'custom-title-link'] ) ) {
153 $title = $options[
'custom-title-link'];
155 'href' =>
$title->getLinkURL( $options[
'custom-title-link-query'] ??
null ),
156 'title' => empty( $options[
'title'] ) ?
$title->getPrefixedText() : $options[
'title']
158 } elseif ( !empty( $options[
'desc-link'] ) ) {
160 empty( $options[
'title'] ) ?
null : $options[
'title'],
163 } elseif ( !empty( $options[
'file-link'] ) ) {
164 $linkAttribs = [
'href' => $this->file->getUrl() ];
166 $linkAttribs =
false;
167 if ( !empty( $options[
'title'] ) ) {
168 if ( $enableLegacyMediaDOM ) {
169 $attribs[
'title'] = $options[
'title'];
171 $linkAttribs = [
'title' => $options[
'title'] ];
176 if ( empty( $options[
'no-dimensions'] ) ) {
177 $attribs[
'width'] = $this->width;
178 $attribs[
'height'] = $this->height;
180 if ( !empty( $options[
'valign'] ) ) {
181 $attribs[
'style'] =
"vertical-align: {$options['valign']}";
183 if ( !empty( $options[
'img-class'] ) ) {
184 $attribs[
'class'] = $options[
'img-class'];
186 if ( isset( $options[
'override-height'] ) ) {
187 $attribs[
'height'] = $options[
'override-height'];
189 if ( isset( $options[
'override-width'] ) ) {
190 $attribs[
'width'] = $options[
'override-width'];
200 Hooks::runner()->onThumbnailBeforeProduceHTML( $this, $attribs, $linkAttribs );
202 return $this->
linkWrap( $linkAttribs, Xml::element(
'img', $attribs ) );