58 if ( is_array( $parameters ) ) {
59 $actualParams = $parameters + $defaults;
62 $numArgs = func_num_args();
65 'height' => $parameters,
66 'page' => ( $numArgs > 5 ) ? func_get_arg( 5 ) : false
68 $path = ( $numArgs > 4 ) ? func_get_arg( 4 ) :
false;
79 $this->width = (int)round( $actualParams[
'width'] );
80 $this->height = (int)round( $actualParams[
'height'] );
82 $this->page = $actualParams[
'page'];
83 $this->lang = $actualParams[
'lang'];
120 public function toHtml( $options = [] ) {
121 $services = MediaWikiServices::getInstance();
122 $mainConfig = $services->getMainConfig();
123 $nativeImageLazyLoading = $mainConfig->get( MainConfigNames::NativeImageLazyLoading );
124 $enableLegacyMediaDOM = $mainConfig->get( MainConfigNames::ParserEnableLegacyMediaDOM );
126 if ( func_num_args() === 2 ) {
127 throw new InvalidArgumentException( __METHOD__ .
' called in the old style' );
130 $query = $options[
'desc-query'] ??
'';
137 if ( isset( $options[
'alt'] ) ) {
138 $attribs[
'alt'] = $options[
'alt'];
144 !$enableLegacyMediaDOM &&
145 isset( $options[
'magnify-resource'] ) &&
146 !( $options[
'desc-link'] ??
false )
148 $attribs[
'resource'] = $options[
'magnify-resource'];
153 'decoding' =>
'async',
156 if ( $options[
'loading'] ?? $nativeImageLazyLoading ) {
157 $attribs[
'loading'] = $options[
'loading'] ??
'lazy';
160 if ( !empty( $options[
'custom-url-link'] ) ) {
161 $linkAttribs = [
'href' => $options[
'custom-url-link'] ];
162 if ( !empty( $options[
'title'] ) ) {
163 $linkAttribs[
'title'] = $options[
'title'];
165 if ( !empty( $options[
'custom-target-link'] ) ) {
166 $linkAttribs[
'target'] = $options[
'custom-target-link'];
167 } elseif ( !empty( $options[
'parser-extlink-target'] ) ) {
168 $linkAttribs[
'target'] = $options[
'parser-extlink-target'];
170 if ( !empty( $options[
'parser-extlink-rel'] ) ) {
171 $linkAttribs[
'rel'] = $options[
'parser-extlink-rel'];
173 } elseif ( !empty( $options[
'custom-title-link'] ) ) {
175 $title = $options[
'custom-title-link'];
177 'href' => $title->getLinkURL( $options[
'custom-title-link-query'] ??
null ),
178 'title' => empty( $options[
'title'] ) ? $title->getPrefixedText() : $options[
'title']
180 } elseif ( !empty( $options[
'desc-link'] ) ) {
182 empty( $options[
'title'] ) ?
null : $options[
'title'],
185 } elseif ( !empty( $options[
'file-link'] ) ) {
186 $linkAttribs = [
'href' => $this->file->getUrl() ];
188 $linkAttribs =
false;
189 if ( !empty( $options[
'title'] ) ) {
190 if ( $enableLegacyMediaDOM ) {
191 $attribs[
'title'] = $options[
'title'];
193 $linkAttribs = [
'title' => $options[
'title'] ];
198 if ( empty( $options[
'no-dimensions'] ) ) {
199 $attribs[
'width'] = $this->width;
200 $attribs[
'height'] = $this->height;
202 if ( !empty( $options[
'valign'] ) ) {
203 $attribs[
'style'] =
"vertical-align: {$options['valign']}";
205 if ( !empty( $options[
'img-class'] ) ) {
206 $attribs[
'class'] = $options[
'img-class'];
208 if ( isset( $options[
'override-height'] ) ) {
209 $attribs[
'height'] = $options[
'override-height'];
211 if ( isset( $options[
'override-width'] ) ) {
212 $attribs[
'width'] = $options[
'override-width'];
222 (
new HookRunner( $services->getHookContainer() ) )
223 ->onThumbnailBeforeProduceHTML( $this, $attribs, $linkAttribs );
225 return $this->
linkWrap( $linkAttribs, Xml::element(
'img', $attribs ) );