59 if ( is_array( $parameters ) ) {
60 $actualParams = $parameters + $defaults;
63 $numArgs = func_num_args();
66 'height' => $parameters,
67 'page' => ( $numArgs > 5 ) ? func_get_arg( 5 ) : false
69 $path = ( $numArgs > 4 ) ? func_get_arg( 4 ) :
false;
80 $this->width = (int)round( $actualParams[
'width'] );
81 $this->height = (int)round( $actualParams[
'height'] );
83 $this->page = $actualParams[
'page'];
84 $this->lang = $actualParams[
'lang'];
121 public function toHtml( $options = [] ) {
122 $services = MediaWikiServices::getInstance();
123 $mainConfig = $services->getMainConfig();
124 $nativeImageLazyLoading = $mainConfig->get( MainConfigNames::NativeImageLazyLoading );
125 $enableLegacyMediaDOM = $mainConfig->get( MainConfigNames::ParserEnableLegacyMediaDOM );
127 if ( func_num_args() === 2 ) {
128 throw new InvalidArgumentException( __METHOD__ .
' called in the old style' );
131 $query = $options[
'desc-query'] ??
'';
138 if ( isset( $options[
'alt'] ) ) {
139 $attribs[
'alt'] = $options[
'alt'];
145 !$enableLegacyMediaDOM &&
146 isset( $options[
'magnify-resource'] ) &&
147 !( $options[
'desc-link'] ??
false )
149 $attribs[
'resource'] = $options[
'magnify-resource'];
154 'decoding' =>
'async',
157 if ( $options[
'loading'] ?? $nativeImageLazyLoading ) {
158 $attribs[
'loading'] = $options[
'loading'] ??
'lazy';
161 if ( !empty( $options[
'custom-url-link'] ) ) {
162 $linkAttribs = [
'href' => $options[
'custom-url-link'] ];
163 if ( !empty( $options[
'title'] ) ) {
164 $linkAttribs[
'title'] = $options[
'title'];
166 if ( !empty( $options[
'custom-target-link'] ) ) {
167 $linkAttribs[
'target'] = $options[
'custom-target-link'];
168 } elseif ( !empty( $options[
'parser-extlink-target'] ) ) {
169 $linkAttribs[
'target'] = $options[
'parser-extlink-target'];
171 if ( !empty( $options[
'parser-extlink-rel'] ) ) {
172 $linkAttribs[
'rel'] = $options[
'parser-extlink-rel'];
174 } elseif ( !empty( $options[
'custom-title-link'] ) ) {
176 $title = $options[
'custom-title-link'];
178 'href' => $title->getLinkURL( $options[
'custom-title-link-query'] ??
null ),
179 'title' => empty( $options[
'title'] ) ? $title->getPrefixedText() : $options[
'title']
181 } elseif ( !empty( $options[
'desc-link'] ) ) {
183 empty( $options[
'title'] ) ?
null : $options[
'title'],
186 } elseif ( !empty( $options[
'file-link'] ) ) {
187 $linkAttribs = [
'href' => $this->file->getUrl() ];
189 $linkAttribs =
false;
190 if ( !empty( $options[
'title'] ) ) {
191 if ( $enableLegacyMediaDOM ) {
192 $attribs[
'title'] = $options[
'title'];
194 $linkAttribs = [
'title' => $options[
'title'] ];
199 if ( empty( $options[
'no-dimensions'] ) ) {
200 $attribs[
'width'] = $this->width;
201 $attribs[
'height'] = $this->height;
203 if ( !empty( $options[
'valign'] ) ) {
204 $attribs[
'style'] =
"vertical-align: {$options['valign']}";
206 if ( !empty( $options[
'img-class'] ) ) {
207 $attribs[
'class'] = $options[
'img-class'];
209 if ( isset( $options[
'override-height'] ) ) {
210 $attribs[
'height'] = $options[
'override-height'];
212 if ( isset( $options[
'override-width'] ) ) {
213 $attribs[
'width'] = $options[
'override-width'];
223 (
new HookRunner( $services->getHookContainer() ) )
224 ->onThumbnailBeforeProduceHTML( $this, $attribs, $linkAttribs );
226 return $this->
linkWrap( $linkAttribs, Xml::element(
'img', $attribs ) );