45 # Previous parameters:
46 # $file, $url, $width, $height, $path = false, $page = false
53 if ( is_array( $parameters ) ) {
54 $actualParams = $parameters + $defaults;
56 # Using old format, should convert. Later a warning could be added here.
57 $numArgs = func_num_args();
60 'height' => $parameters,
61 'page' => ( $numArgs > 5 ) ? func_get_arg( 5 ) : false
63 $path = ( $numArgs > 4 ) ? func_get_arg( 4 ) :
false;
70 # These should be integers when they get here.
71 # If not, there's a bug somewhere. But let's at
72 # least produce valid HTML code regardless.
73 $this->width = round( $actualParams[
'width'] );
74 $this->height = round( $actualParams[
'height'] );
76 $this->page = $actualParams[
'page'];
77 $this->lang = $actualParams[
'lang'];
115 if ( func_num_args() == 2 ) {
116 throw new MWException( __METHOD__ .
' called in the old style' );
119 $alt = $options[
'alt'] ??
'';
121 $query = $options[
'desc-query'] ??
'';
126 'decoding' =>
'async',
130 $attribs[
'loading'] =
'lazy';
133 $elementTimingName =
'thumbnail';
136 && !self::$firstNonIconImageRendered
137 && $this->width * $this->height > 100 * 100 ) {
138 self::$firstNonIconImageRendered =
true;
141 $random = rand( 1, 100 ) / 100.0;
144 $attribs[
'importance'] =
'high';
145 $elementTimingName =
'thumbnail-high';
148 $elementTimingName =
'thumbnail-top';
153 $attribs[
'elementtiming'] = $elementTimingName;
156 if ( !empty( $options[
'custom-url-link'] ) ) {
157 $linkAttribs = [
'href' => $options[
'custom-url-link'] ];
158 if ( !empty( $options[
'title'] ) ) {
159 $linkAttribs[
'title'] = $options[
'title'];
161 if ( !empty( $options[
'custom-target-link'] ) ) {
162 $linkAttribs[
'target'] = $options[
'custom-target-link'];
163 } elseif ( !empty( $options[
'parser-extlink-target'] ) ) {
164 $linkAttribs[
'target'] = $options[
'parser-extlink-target'];
166 if ( !empty( $options[
'parser-extlink-rel'] ) ) {
167 $linkAttribs[
'rel'] = $options[
'parser-extlink-rel'];
169 } elseif ( !empty( $options[
'custom-title-link'] ) ) {
171 $title = $options[
'custom-title-link'];
173 'href' =>
$title->getLinkURL(),
174 'title' => empty( $options[
'title'] ) ?
$title->getFullText() : $options[
'title']
176 } elseif ( !empty( $options[
'desc-link'] ) ) {
178 empty( $options[
'title'] ) ?
null : $options[
'title'],
181 } elseif ( !empty( $options[
'file-link'] ) ) {
182 $linkAttribs = [
'href' => $this->file->getUrl() ];
184 $linkAttribs =
false;
185 if ( !empty( $options[
'title'] ) ) {
186 $attribs[
'title'] = $options[
'title'];
190 if ( empty( $options[
'no-dimensions'] ) ) {
194 if ( !empty( $options[
'valign'] ) ) {
195 $attribs[
'style'] =
"vertical-align: {$options['valign']}";
197 if ( !empty( $options[
'img-class'] ) ) {
198 $attribs[
'class'] = $options[
'img-class'];
200 if ( isset( $options[
'override-height'] ) ) {
201 $attribs[
'height'] = $options[
'override-height'];
203 if ( isset( $options[
'override-width'] ) ) {
204 $attribs[
'width'] = $options[
'override-width'];
214 Hooks::run(
'ThumbnailBeforeProduceHTML', [ $this, &$attribs, &$linkAttribs ] );
216 return $this->
linkWrap( $linkAttribs, Xml::element(
'img', $attribs ) );