11use Wikimedia\AtEase\AtEase;
28 return ( $file->getWidth() && $file->getHeight() );
37 return [
'img_width' =>
'width' ];
45 return in_array( $name, [
'width',
'height' ] ) && $value > 0;
54 if ( isset( $params[
'physicalWidth'] ) ) {
55 $width = $params[
'physicalWidth'];
56 } elseif ( isset( $params[
'width'] ) ) {
57 $width = $params[
'width'];
62 # Removed for ProofreadPage
63 # $width = intval( $width );
73 if ( preg_match(
'/^(\d+)px$/', $str, $m ) ) {
74 return [
'width' => $m[1] ];
85 return [
'width' => $params[
'width'] ];
97 if ( !isset( $params[
'width'] ) ) {
101 if ( !isset( $params[
'page'] ) ) {
104 $params[
'page'] = (int)$params[
'page'];
105 if ( $params[
'page'] > $image->pageCount() ) {
106 $params[
'page'] = $image->pageCount();
109 if ( $params[
'page'] < 1 ) {
114 $srcWidth = $image->getWidth( $params[
'page'] );
115 $srcHeight = $image->getHeight( $params[
'page'] );
117 if ( isset( $params[
'height'] ) && $params[
'height'] !== -1 ) {
118 # Height & width were both set
119 if ( $params[
'width'] * $srcHeight > $params[
'height'] * $srcWidth ) {
120 # Height is the relative smaller dimension, so scale width accordingly
121 $params[
'width'] =
self::fitBoxWidth( $srcWidth, $srcHeight, $params[
'height'] );
123 if ( $params[
'width'] == 0 ) {
124 # Very small image, so we need to rely on client side scaling :(
125 $params[
'width'] = 1;
128 $params[
'physicalWidth'] = $params[
'width'];
130 # Height was crap, unset it so that it will be calculated later
131 unset( $params[
'height'] );
135 if ( !isset( $params[
'physicalWidth'] ) ) {
136 # 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() ) {
214 AtEase::suppressWarnings();
215 $gis = getimagesize(
$path );
216 AtEase::restoreWarnings();
224 $gis = @getimagesize(
$path );
230 if ( isset( $gis[
'bits'] ) ) {
231 $info[
'bits'] = $gis[
'bits'];
250 return $image->getWidth() * $image->getHeight();
261 $nbytes = htmlspecialchars(
$wgLang->formatSize( $file->getSize() ), ENT_QUOTES );
262 $widthheight =
wfMessage(
'widthheight' )
263 ->numParams( $file->getWidth(), $file->getHeight() )
266 return "$widthheight ($nbytes)";
276 $pages = $file->pageCount();
277 if ( $pages ===
false || $pages <= 1 ) {
279 ->numParams( $file->getWidth(), $file->getHeight() )
280 ->sizeParams( $file->getSize() )
281 ->params(
'<span class="mime-type">' . $file->getMimeType() .
'</span>' )
284 $msg =
wfMessage(
'file-info-size-pages' )
285 ->numParams( $file->getWidth(), $file->getHeight() )
286 ->sizeParams( $file->getSize() )
287 ->params(
'<span class="mime-type">' . $file->getMimeType() .
'</span>' )->numParams( $pages )
301 $pages = $file->pageCount();
304 ->numParams( $file->getWidth(), $file->getHeight(), $pages )->text();
307 ->numParams( $file->getWidth(), $file->getHeight() )->text();
315 $params = parent::sanitizeParamsForBucketing( $params );
319 unset( $params[
'height'] );
320 unset( $params[
'physicalHeight'] );
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
Media handler abstract base class for images.
canRender( $file)
True if the handled types can be transformed.to overridebool
getImageSize( $image, $path)
Get an image size array like that returned by getimagesize(), or false if it can't be determined....
sanitizeParamsForBucketing( $params)
Returns a normalised params array for which parameters have been cleaned up for bucketing purposes....
getImageArea( $image)
Function that returns the number of pixels to be thumbnailed.
getParamMap()
Get an associative array mapping magic word IDs to parameter names.Will be used by the parser to iden...
getSizeAndMetadata( $state, $path)
Get image size information and metadata array.If this returns null, the caller will fall back to getI...
normaliseParams( $image, &$params)
Changes the parameter array as necessary, ready for transformation.Should be idempotent....
parseParamString( $str)
Parse a param string made with makeParamString back into an array.array|false Array of parameters or ...
makeParamString( $params)
Merge a parameter array into a string appropriate for inclusion in filenames.string
getLongDesc( $file)
Long description.Shown under image on image description page surrounded by ().Until MediaWiki 1....
validateParam( $name, $value)
Validate a thumbnail parameter at parse time.Return true to accept the parameter, and false to reject...
getScriptedTransform( $image, $script, $params)
Get a MediaTransformOutput object representing an alternate of the transformed output which will call...
getScriptParams( $params)
getDimensionsString( $file)
Shown in file history box on image description page.to overridestring Dimensions (plain text)
getShortDesc( $file)
Short description.Shown on Special:Search results.Until MediaWiki 1.45, the return value was poorly d...
Media transform output for images.