49 # Obtain the source, pre-rotation dimensions
53 # Don't make an image bigger than the source
54 if (
$params[
'physicalWidth'] >= $srcWidth ) {
55 $params[
'physicalWidth'] = $srcWidth;
56 $params[
'physicalHeight'] = $srcHeight;
58 # Skip scaling limit checks if no scaling is required
59 # due to requested size being bigger than source.
60 if ( !
$image->mustRender() ) {
81 if ( $rotation == 90 || $rotation == 270 ) {
82 # We'll resize before rotation, so swap the dimensions again
83 $width =
$params[
'physicalHeight'];
84 $height =
$params[
'physicalWidth'];
86 $width =
$params[
'physicalWidth'];
87 $height =
$params[
'physicalHeight'];
90 return [ $width, $height ];
111 # Create a parameter array to pass to the scaler
113 # The size to which the image will be resized
114 'physicalWidth' =>
$params[
'physicalWidth'],
115 'physicalHeight' =>
$params[
'physicalHeight'],
116 'physicalDimensions' =>
"{$params['physicalWidth']}x{$params['physicalHeight']}",
117 # The size of the image on the page
118 'clientWidth' =>
$params[
'width'],
119 'clientHeight' =>
$params[
'height'],
120 # Comment as will be added to the Exif of the thumbnail
121 'comment' => isset(
$params[
'descriptionUrl'] )
122 ?
"File source: {$params['descriptionUrl']}"
124 # Properties of the original image
125 'srcWidth' =>
$image->getWidth(),
126 'srcHeight' =>
$image->getHeight(),
127 'mimeType' =>
$image->getMimeType(),
128 'dstPath' => $dstPath,
130 'interlace' => isset(
$params[
'interlace'] ) ?
$params[
'interlace'] :
false,
133 if ( isset(
$params[
'quality'] ) &&
$params[
'quality'] ===
'low' ) {
134 $scalerParams[
'quality'] = 30;
139 $scalerParams[
'page'] = intval(
$params[
'page'] );
142 # Determine scaler type
145 if ( is_array( $scaler ) ) {
146 $scalerName = get_class( $scaler[0] );
148 $scalerName = $scaler;
151 wfDebug( __METHOD__ .
": creating {$scalerParams['physicalDimensions']} " .
152 "thumbnail at $dstPath using scaler $scalerName\n" );
154 if ( !
$image->mustRender() &&
155 $scalerParams[
'physicalWidth'] == $scalerParams[
'srcWidth']
156 && $scalerParams[
'physicalHeight'] == $scalerParams[
'srcHeight']
157 && !isset( $scalerParams[
'quality'] )
159 # normaliseParams (or the user) wants us to return the unscaled image
160 wfDebug( __METHOD__ .
": returning unscaled image\n" );
165 if ( $scaler ==
'client' ) {
166 # Client-side image scaling, use the source URL
167 # Using the destination URL in a TRANSFORM_LATER request would be incorrect
171 if (
$image->isTransformedLocally() && !$this->isImageAreaOkForThumbnaling(
$image,
$params ) ) {
176 if (
$flags & self::TRANSFORM_LATER ) {
177 wfDebug( __METHOD__ .
": Transforming later per flags.\n" );
179 'width' => $scalerParams[
'clientWidth'],
180 'height' => $scalerParams[
'clientHeight']
182 if ( isset(
$params[
'quality'] ) ) {
183 $newParams[
'quality'] =
$params[
'quality'];
186 $newParams[
'page'] =
$params[
'page'];
191 # Try to make a target path for the thumbnail
193 wfDebug( __METHOD__ .
": Unable to create thumbnail destination " .
194 "directory, falling back to client scaling\n" );
199 # Transform functions and binaries need a FS source file
203 if ( $scalerParams[
'srcWidth'] != $thumbnailSource[
'width']
204 || $scalerParams[
'srcHeight'] != $thumbnailSource[
'height'] ) {
205 $scalerParams[
'disableRotation'] =
true;
208 $scalerParams[
'srcPath'] = $thumbnailSource[
'path'];
209 $scalerParams[
'srcWidth'] = $thumbnailSource[
'width'];
210 $scalerParams[
'srcHeight'] = $thumbnailSource[
'height'];
212 if ( $scalerParams[
'srcPath'] ===
false ) {
214 sprintf(
'Thumbnail failed on %s: could not get local copy of "%s"',
218 $scalerParams[
'clientWidth'], $scalerParams[
'clientHeight'],
223 # Try a hook. Called "Bitmap" for historical reasons.
226 Hooks::run(
'BitmapHandlerTransform', [ $this,
$image, &$scalerParams, &$mto ] );
227 if ( !is_null( $mto ) ) {
228 wfDebug( __METHOD__ .
": Hook to BitmapHandlerTransform created an mto\n" );
229 $scaler =
'hookaborted';
235 if ( is_array( $scaler ) && is_callable( $scaler ) ) {
237 $err = call_user_func( $scaler,
$image, $scalerParams );
241 # Handled by the hook above
242 $err = $mto->isError() ? $mto :
false;
260 # Remove the file if a zero-byte thumbnail was created, or if there was an error
263 # transform returned MediaTransforError
265 } elseif ( $removed ) {
266 # Thumbnail was zero-byte and had to be removed
268 $scalerParams[
'clientWidth'], $scalerParams[
'clientHeight'],
275 'width' => $scalerParams[
'clientWidth'],
276 'height' => $scalerParams[
'clientHeight']
278 if ( isset(
$params[
'quality'] ) ) {
279 $newParams[
'quality'] =
$params[
'quality'];
282 $newParams[
'page'] =
$params[
'page'];
296 return $file->getThumbnailSource(
$params );
320 abstract protected function getScalerType( $dstPath, $checkDstPath =
true );
334 'width' => $scalerParams[
'clientWidth'],
335 'height' => $scalerParams[
'clientHeight']
392 $params[
'clientHeight'], $errMsg );
417 $s = str_replace(
'\\',
'\\\\',
$s );
419 $s = str_replace(
'%',
'%%',
$s );
421 if ( strlen(
$s ) > 0 && (
$s[0] ===
'-' ||
$s[0] ===
'@' ) ) {
446 # Die on initial metacharacters (caller should prepend path)
447 $firstChar = substr( $path, 0, 1 );
448 if ( $firstChar ===
'~' || $firstChar ===
'@' ) {
449 throw new MWException( __METHOD__ .
': cannot escape this path name' );
453 $path = preg_replace(
'/[*?\[\]{}]/',
'\\\\\0', $path );
466 $path = str_replace(
'%',
'%%', $path );
481 # Die on format specifiers (other than drive letters). The regex is
482 # meant to match all the formats you get from "convert -list format"
483 if ( preg_match(
'/^([a-zA-Z0-9-]+):/', $path, $m ) ) {
488 throw new MWException( __METHOD__ .
': unexpected colon character in path name' );
492 # If there are square brackets, add a do-nothing scene specification
493 # to force a literal interpretation
494 if ( $scene ===
false ) {
495 if ( strpos( $path,
'[' ) !==
false ) {
512 $cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
513 $method = __METHOD__;
514 return $cache->getWithSetCallback(
515 'imagemagick-version',
517 function () use ( $method ) {
521 wfDebug( $method .
": Running convert -version\n" );
525 '/Version: ImageMagick ([0-9]*\.[0-9]*\.[0-9]*)/', $return,
$matches
528 wfDebug( $method .
": ImageMagick version check failed\n" );
571 static::class .
' rotation not implemented' );
598 # For historical reasons, hook starts with BitmapHandler
599 $checkImageAreaHookResult =
null;
601 'BitmapHandlerCheckImageArea',
602 [ $file, &
$params, &$checkImageAreaHookResult ]
605 if ( !is_null( $checkImageAreaHookResult ) ) {
607 return (
bool)$checkImageAreaHookResult;
610 $srcWidth = $file->getWidth(
$params[
'page'] );
611 $srcHeight = $file->getHeight(
$params[
'page'] );
614 && !( $file->getMimeType() ==
'image/jpeg'
615 && $this->getScalerType(
false,
false ) ==
'im' )
617 # Only ImageMagick can efficiently downsize jpg images without loading
618 # the entire file in memory
$wgMaxImageArea
The maximum number of pixels a source image can have if it is to be scaled down by a scaler that requ...
$wgImageMagickConvertCommand
The convert command shipped with ImageMagick.
wfDebug( $text, $dest='all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
wfHostname()
Fetch server name for use in error reporting etc.
wfEscapeShellArg()
Version of escapeshellarg() that works better on Windows.
wfShellExecWithStderr( $cmd, &$retval=null, $environ=[], $limits=[])
Execute a shell command, returning both stdout and stderr.
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfIsWindows()
Check if the operating system is Windows.
wfMkdirParents( $dir, $mode=null, $caller=null)
Make directory, and make all parent directories if they don't exist.
Media handler abstract base class for images.
Media transform output for images.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account incomplete not yet checked for validity & $retval
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check $image
either a unescaped string or a HtmlArmor object after in associative array form externallinks including delete and has completed for all link tables whether this was an auto creation default is conds Array Extra conditions for the No matching items in log is displayed if loglist is empty msgKey Array If you want a nice box with a set this to the key of the message First element is the message additional optional elements are parameters for the key that are processed with wfMessage() -> params() ->parseAsBlock() - offset Set to overwrite offset parameter in $wgRequest set to '' to unset offset - wrap String Wrap the message in html(usually something like "<div ...>$1</div>"). - flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException':Called before an exception(or PHP error) is logged. This is meant for integration with external error aggregation services
it s the revision text itself In either if gzip is the revision text is gzipped $flags