57 if ( is_array( $parameters ) ) {
58 $actualParams = $parameters + $defaults;
61 $numArgs = func_num_args();
64 'height' => $parameters,
65 'page' => ( $numArgs > 5 ) ? func_get_arg( 5 ) : false
67 $path = ( $numArgs > 4 ) ? func_get_arg( 4 ) :
false;
78 $this->width = (int)round( $actualParams[
'width'] );
79 $this->height = (int)round( $actualParams[
'height'] );
81 $this->page = $actualParams[
'page'];
82 $this->lang = $actualParams[
'lang'];
119 public function toHtml( $options = [] ) {
120 $mainConfig = MediaWikiServices::getInstance()->getMainConfig();
121 $nativeImageLazyLoading = $mainConfig->get( MainConfigNames::NativeImageLazyLoading );
122 $enableLegacyMediaDOM = $mainConfig->get( MainConfigNames::ParserEnableLegacyMediaDOM );
124 if ( func_num_args() === 2 ) {
125 throw new MWException( __METHOD__ .
' called in the old style' );
128 $query = $options[
'desc-query'] ??
'';
135 if ( isset( $options[
'alt'] ) ) {
136 $attribs[
'alt'] = $options[
'alt'];
141 'decoding' =>
'async',
144 if ( $options[
'loading'] ?? $nativeImageLazyLoading ) {
145 $attribs[
'loading'] = $options[
'loading'] ??
'lazy';
148 if ( !empty( $options[
'custom-url-link'] ) ) {
149 $linkAttribs = [
'href' => $options[
'custom-url-link'] ];
150 if ( !empty( $options[
'title'] ) ) {
151 $linkAttribs[
'title'] = $options[
'title'];
153 if ( !empty( $options[
'custom-target-link'] ) ) {
154 $linkAttribs[
'target'] = $options[
'custom-target-link'];
155 } elseif ( !empty( $options[
'parser-extlink-target'] ) ) {
156 $linkAttribs[
'target'] = $options[
'parser-extlink-target'];
158 if ( !empty( $options[
'parser-extlink-rel'] ) ) {
159 $linkAttribs[
'rel'] = $options[
'parser-extlink-rel'];
161 } elseif ( !empty( $options[
'custom-title-link'] ) ) {
163 $title = $options[
'custom-title-link'];
165 'href' =>
$title->getLinkURL( $options[
'custom-title-link-query'] ??
null ),
166 'title' => empty( $options[
'title'] ) ?
$title->getPrefixedText() : $options[
'title']
168 } elseif ( !empty( $options[
'desc-link'] ) ) {
170 empty( $options[
'title'] ) ?
null : $options[
'title'],
173 } elseif ( !empty( $options[
'file-link'] ) ) {
174 $linkAttribs = [
'href' => $this->file->getUrl() ];
176 $linkAttribs =
false;
177 if ( !empty( $options[
'title'] ) ) {
178 if ( $enableLegacyMediaDOM ) {
179 $attribs[
'title'] = $options[
'title'];
181 $linkAttribs = [
'title' => $options[
'title'] ];
186 if ( empty( $options[
'no-dimensions'] ) ) {
187 $attribs[
'width'] = $this->width;
188 $attribs[
'height'] = $this->height;
190 if ( !empty( $options[
'valign'] ) ) {
191 $attribs[
'style'] =
"vertical-align: {$options['valign']}";
193 if ( !empty( $options[
'img-class'] ) ) {
194 $attribs[
'class'] = $options[
'img-class'];
196 if ( isset( $options[
'override-height'] ) ) {
197 $attribs[
'height'] = $options[
'override-height'];
199 if ( isset( $options[
'override-width'] ) ) {
200 $attribs[
'width'] = $options[
'override-width'];
210 Hooks::runner()->onThumbnailBeforeProduceHTML( $this, $attribs, $linkAttribs );
212 return $this->
linkWrap( $linkAttribs, Xml::element(
'img', $attribs ) );