12use InvalidArgumentException;
50 if ( is_array( $parameters ) ) {
51 $actualParams = $parameters + $defaults;
54 $numArgs = func_num_args();
57 'height' => $parameters,
58 'page' => ( $numArgs > 5 ) ? func_get_arg( 5 ) : false
60 $path = ( $numArgs > 4 ) ? func_get_arg( 4 ) :
false;
63 if ( $actualParams[
'usePhysicalSize'] ??
false ) {
64 $actualParams[
'width'] = $actualParams[
'physicalWidth'];
65 $actualParams[
'height'] = $actualParams[
'physicalHeight'];
75 $this->width = (int)round( $actualParams[
'width'] );
76 $this->height = (int)round( $actualParams[
'height'] );
78 $this->page = $actualParams[
'page'];
79 $this->lang = $actualParams[
'lang'];
83 public function getAttribs( array $options = [] ): array {
88 $attribs = parent::getAttribs( $options );
93 if ( isset( $options[
'alt'] ) ) {
94 $attribs[
'alt'] = $options[
'alt'];
100 isset( $options[
'magnify-resource'] ) &&
101 !( $options[
'desc-link'] ??
false )
103 $attribs[
'resource'] = $options[
'magnify-resource'];
108 'decoding' =>
'async',
111 if ( $options[
'loading'] ?? $nativeImageLazyLoading ) {
112 $attribs[
'loading'] = $options[
'loading'] ??
'lazy';
115 if ( empty( $options[
'no-dimensions'] ) ) {
120 if ( !empty( $options[
'valign'] ) ) {
121 $style .=
"vertical-align: {$options['valign']};";
123 if ( !empty( $options[
'style'] ) ) {
124 $style .= $options[
'style'];
126 $style = trim( $style );
128 $attribs[
'style'] = $style;
130 if ( !empty( $options[
'img-class'] ) ) {
131 $attribs[
'class'] = $options[
'img-class'];
133 if ( isset( $options[
'override-height'] ) ) {
134 $attribs[
'height'] = $options[
'override-height'];
136 if ( isset( $options[
'override-width'] ) ) {
137 $attribs[
'width'] = $options[
'override-width'];
184 public function toHtml( $options = [] ) {
185 if ( func_num_args() === 2 ) {
186 throw new InvalidArgumentException( __METHOD__ .
' called in the old style' );
189 $query = $options[
'desc-query'] ??
'';
191 $attribs = $this->getAttribs( $options );
193 if ( !empty( $options[
'custom-url-link'] ) ) {
194 $linkAttribs = [
'href' => $options[
'custom-url-link'] ];
195 if ( !empty( $options[
'title'] ) ) {
196 $linkAttribs[
'title'] = $options[
'title'];
198 if ( !empty( $options[
'custom-target-link'] ) ) {
199 $linkAttribs[
'target'] = $options[
'custom-target-link'];
200 } elseif ( !empty( $options[
'parser-extlink-target'] ) ) {
201 $linkAttribs[
'target'] = $options[
'parser-extlink-target'];
203 if ( !empty( $options[
'parser-extlink-rel'] ) ) {
204 $linkAttribs[
'rel'] = $options[
'parser-extlink-rel'];
206 } elseif ( !empty( $options[
'custom-title-link'] ) ) {
208 $title = $options[
'custom-title-link'];
210 'href' => $title->getLinkURL( $options[
'custom-title-link-query'] ??
null ),
211 'title' => empty( $options[
'title'] ) ? $title->getPrefixedText() : $options[
'title']
213 } elseif ( !empty( $options[
'desc-link'] ) ) {
214 $linkAttribs = $this->getDescLinkAttribs(
215 empty( $options[
'title'] ) ?
null : $options[
'title'],
218 } elseif ( !empty( $options[
'file-link'] ) ) {
219 $linkAttribs = [
'href' => $this->file->getUrl() ];
221 $linkAttribs =
false;
222 if ( !empty( $options[
'title'] ) ) {
223 $linkAttribs = [
'title' => $options[
'title'] ];
228 (
new HookRunner( $services->getHookContainer() ) )
229 ->onThumbnailBeforeProduceHTML( $this, $attribs, $linkAttribs );
231 return $this->linkWrap( $linkAttribs,
Html::element(
'img', $attribs ) );
236class_alias( ThumbnailImage::class,
'ThumbnailImage' );
A class containing constants representing the names of configuration variables.
const NativeImageLazyLoading
Name constant for the NativeImageLazyLoading setting, for use with Config::get()