29 return ( $file->getWidth() && $file->getHeight() );
38 return [
'img_width' =>
'width' ];
46 return in_array( $name, [
'width',
'height' ] ) && $value > 0;
55 if ( isset( $params[
'physicalWidth'] ) ) {
56 $width = $params[
'physicalWidth'];
57 } elseif ( isset( $params[
'width'] ) ) {
58 $width = $params[
'width'];
63 # Removed for ProofreadPage
64 # $width = intval( $width );
74 if ( preg_match(
'/^(\d+)px$/', $str, $m ) ) {
75 return [
'width' => $m[1] ];
86 return [
'width' => $params[
'width'] ];
98 if ( !isset( $params[
'width'] ) ) {
102 if ( !isset( $params[
'page'] ) ) {
105 $params[
'page'] = (int)$params[
'page'];
106 if ( $params[
'page'] > $image->pageCount() ) {
107 $params[
'page'] = $image->pageCount();
110 if ( $params[
'page'] < 1 ) {
115 $srcWidth = $image->getWidth( $params[
'page'] );
116 $srcHeight = $image->getHeight( $params[
'page'] );
118 if ( isset( $params[
'height'] ) && $params[
'height'] !== -1 ) {
119 # Height & width were both set
120 if ( $params[
'width'] * $srcHeight > $params[
'height'] * $srcWidth ) {
121 # Height is the relative smaller dimension, so scale width accordingly
122 $params[
'width'] =
self::fitBoxWidth( $srcWidth, $srcHeight, $params[
'height'] );
124 if ( $params[
'width'] == 0 ) {
125 # Very small image, so we need to rely on client side scaling :(
126 $params[
'width'] = 1;
129 $params[
'physicalWidth'] = $params[
'width'];
131 # Height was crap, unset it so that it will be calculated later
132 unset( $params[
'height'] );
136 if ( !isset( $params[
'physicalWidth'] ) ) {
137 # Passed all validations, so set the physicalWidth
138 $params[
'physicalWidth'] = $params[
'width'];
141 # Because thumbs are only referred to by width, the height always needs
142 # to be scaled by the width to keep the thumbnail sizes consistent,
143 # even if it was set inside the if block above
144 $params[
'physicalHeight'] = File::scaleHeight( $srcWidth, $srcHeight,
145 $params[
'physicalWidth'] );
147 # Set the height if it was not validated in the if block higher up
148 if ( !isset( $params[
'height'] ) || $params[
'height'] === -1 ) {
149 $params[
'height'] = $params[
'physicalHeight'];
152 if ( !$this->validateThumbParams( $params[
'physicalWidth'],
153 $params[
'physicalHeight'], $srcWidth, $srcHeight )
170 private function validateThumbParams( &$width, &$height, $srcWidth, $srcHeight ) {
171 $width = (int)$width;
174 wfDebug( __METHOD__ .
": Invalid destination width: $width" );
178 if ( $srcWidth <= 0 ) {
179 wfDebug( __METHOD__ .
": Invalid source width: $srcWidth" );
184 $height = File::scaleHeight( $srcWidth, $srcHeight, $width );
185 if ( $height == 0 ) {
186 # Force height to be at least 1 pixel
207 if ( $image->mustRender() || $params[
'width'] < $image->getWidth() ) {
215 return @getimagesize(
$path );
221 $gis = @getimagesize(
$path );
227 if ( isset( $gis[
'bits'] ) ) {
228 $info[
'bits'] = $gis[
'bits'];
247 return $image->getWidth() * $image->getHeight();
258 $nbytes = htmlspecialchars(
$wgLang->formatSize( $file->getSize() ), ENT_QUOTES );
259 $widthheight =
wfMessage(
'widthheight' )
260 ->numParams( $file->getWidth(), $file->getHeight() )
263 return "$widthheight ($nbytes)";
273 $pages = $file->pageCount();
274 if ( $pages ===
false || $pages <= 1 ) {
276 ->numParams( $file->getWidth(), $file->getHeight() )
277 ->sizeParams( $file->getSize() )
278 ->params(
'<span class="mime-type">' . $file->getMimeType() .
'</span>' )
281 $msg =
wfMessage(
'file-info-size-pages' )
282 ->numParams( $file->getWidth(), $file->getHeight() )
283 ->sizeParams( $file->getSize() )
284 ->params(
'<span class="mime-type">' . $file->getMimeType() .
'</span>' )->numParams( $pages )
298 $pages = $file->pageCount();
301 ->numParams( $file->getWidth(), $file->getHeight(), $pages )->text();
304 ->numParams( $file->getWidth(), $file->getHeight() )->text();
312 $params = parent::sanitizeParamsForBucketing( $params );
316 unset( $params[
'height'] );
317 unset( $params[
'physicalHeight'] );
324class_alias( ImageHandler::class,
'ImageHandler' );
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(MW_ENTRY_POINT==='index') if(!defined( 'MW_NO_SESSION') &&MW_ENTRY_POINT !=='cli' $wgLang