42 if ( !$dstPath && $checkDstPath ) {
43 # No output path available, client side scaling only
45 } elseif ( !$wgUseImageResize ) {
47 } elseif ( $wgUseImageMagick ) {
49 } elseif ( $wgCustomConvertCommand ) {
51 } elseif ( function_exists(
'imagecreatetruecolor' ) ) {
53 } elseif ( class_exists(
'Imagick' ) ) {
65 return "interlaced-{$res}";
72 $remainder = preg_replace(
'/^interlaced-/',
'', $str );
73 $params = parent::parseParamString( $remainder );
77 $params[
'interlace'] = $str !== $remainder;
82 if (
$name ===
'interlace' ) {
99 $mimeType =
$image->getMimeType();
100 $interlace = isset(
$params[
'interlace'] ) &&
$params[
'interlace']
101 && isset( $wgMaxInterlacingAreas[$mimeType] )
103 $params[
'interlace'] = $interlace;
114 switch ( $pixelFormat ) {
116 return [
'1x1',
'1x1',
'1x1' ];
118 return [
'2x1',
'1x1',
'1x1' ];
120 return [
'2x2',
'1x1',
'1x1' ];
122 throw new MWException(
'Invalid pixel format for JPEG output' );
143 $animation_post = [];
147 if (
$params[
'mimeType'] ==
'image/jpeg' ) {
149 $quality = [
'-quality', $qualityVal ?:
'80' ];
151 $animation_post = [
'-interlace',
'JPEG' ];
153 # Sharpening, see bug 6193
156 < $wgSharpenReductionThreshold
162 $decoderHint = [
'-define',
"jpeg:size={$params['physicalDimensions']}" ];
164 if ( $wgJpegPixelFormat ) {
166 $subsampling = [
'-sampling-factor', implode(
',', $factors ) ];
168 } elseif (
$params[
'mimeType'] ==
'image/png' ) {
169 $quality = [
'-quality',
'95' ];
171 $animation_post = [
'-interlace',
'PNG' ];
173 } elseif (
$params[
'mimeType'] ==
'image/webp' ) {
174 $quality = [
'-quality',
'95' ];
175 } elseif (
$params[
'mimeType'] ==
'image/gif' ) {
182 $animation_pre = [
'-coalesce' ];
186 $animation_post = [
'-fuzz',
'5%',
'-layers',
'optimizeTransparency' ];
191 $animation_post[] =
'-interlace';
192 $animation_post[] =
'GIF';
194 } elseif (
$params[
'mimeType'] ==
'image/x-xcf' ) {
202 '-background',
'transparent',
204 '-background',
'white',
206 MediaWiki\suppressWarnings();
208 MediaWiki\restoreWarnings();
210 && isset( $xcfMeta[
'colorType'] )
211 && $xcfMeta[
'colorType'] ===
'greyscale-alpha'
216 $channelOnly = [
'-channel',
'R',
'-separate' ];
217 $animation_pre = array_merge( $animation_pre, $channelOnly );
222 $env = [
'OMP_NUM_THREADS' => 1 ];
223 if ( strval( $wgImageMagickTempDir ) !==
'' ) {
230 $cmd = call_user_func_array(
'wfEscapeShellArg', array_merge(
231 [ $wgImageMagickConvertCommand ],
235 [
'-background',
'white' ],
242 [
'-thumbnail',
"{$width}x{$height}!" ],
248 [
'+set',
'Thumb::URI' ],
251 [
'-rotate',
"-$rotation" ],
256 wfDebug( __METHOD__ .
": running ImageMagick: $cmd\n" );
266 return false; # No error
283 $im->readImage(
$params[
'srcPath'] );
285 if (
$params[
'mimeType'] ==
'image/jpeg' ) {
289 < $wgSharpenReductionThreshold
292 list( $radius, $sigma ) = explode(
'x', $wgSharpenParameter );
293 $im->sharpenImage( $radius, $sigma );
296 $im->setCompressionQuality( $qualityVal ?: 80 );
298 $im->setInterlaceScheme( Imagick::INTERLACE_JPEG );
300 if ( $wgJpegPixelFormat ) {
302 $im->setSamplingFactors( $factors );
304 } elseif (
$params[
'mimeType'] ==
'image/png' ) {
305 $im->setCompressionQuality( 95 );
307 $im->setInterlaceScheme( Imagick::INTERLACE_PNG );
309 } elseif (
$params[
'mimeType'] ==
'image/gif' ) {
313 $im->setImageScene( 0 );
316 $im = $im->coalesceImages();
319 $v = Imagick::getVersion();
320 preg_match(
'/ImageMagick ([0-9]+\.[0-9]+\.[0-9]+)/', $v[
'versionString'], $v );
322 if (
$params[
'interlace'] && version_compare( $v[1],
'6.3.4' ) >= 0 ) {
323 $im->setInterlaceScheme( Imagick::INTERLACE_GIF );
330 $im->setImageBackgroundColor(
new ImagickPixel(
'white' ) );
333 foreach ( $im
as $i => $frame ) {
334 if ( !$frame->thumbnailImage( $width, $height,
false ) ) {
338 $im->setImageDepth( 8 );
341 if ( !$im->rotateImage(
new ImagickPixel(
'white' ), 360 - $rotation ) ) {
347 wfDebug( __METHOD__ .
": Writing animated thumbnail\n" );
355 "Unable to write thumbnail to {$params['dstPath']}" );
357 }
catch ( ImagickException
$e ) {
373 # Use a custom convert command
376 # Variables: %s %d %w %h
380 $cmd = str_replace(
'%s', $src, str_replace(
'%d', $dst, $cmd ) ); # Filenames
383 wfDebug( __METHOD__ .
": Running custom convert command $cmd\n" );
393 return false; # No error
405 # Use PHP's builtin GD library functions.
406 # First find out what kind of file this is, and select the correct
407 # input routine for this.
410 'image/gif' => [
'imagecreatefromgif',
'palette',
false,
'imagegif' ],
411 'image/jpeg' => [
'imagecreatefromjpeg',
'truecolor',
true,
412 [ __CLASS__,
'imageJpegWrapper' ] ],
413 'image/png' => [
'imagecreatefrompng',
'bits',
false,
'imagepng' ],
414 'image/vnd.wap.wbmp' => [
'imagecreatefromwbmp',
'palette',
false,
'imagewbmp' ],
415 'image/xbm' => [
'imagecreatefromxbm',
'palette',
false,
'imagexbm' ],
418 if ( !isset( $typemap[
$params[
'mimeType']] ) ) {
419 $err =
'Image type not supported';
421 $errMsg =
wfMessage(
'thumbnail_image-type' )->text();
425 list( $loader, $colorStyle, $useQuality, $saveType ) = $typemap[$params[
'mimeType']];
427 if ( !function_exists( $loader ) ) {
428 $err =
"Incomplete GD library configuration: missing function $loader";
430 $errMsg =
wfMessage(
'thumbnail_gd-library', $loader )->text();
435 if ( !file_exists( $params[
'srcPath'] ) ) {
436 $err =
"File seems to be missing: {$params['srcPath']}";
438 $errMsg =
wfMessage(
'thumbnail_image-missing', $params[
'srcPath'] )->text();
443 $src_image = call_user_func( $loader, $params[
'srcPath'] );
445 $rotation = function_exists(
'imagerotate' ) && !isset( $params[
'disableRotation'] ) ?
449 $dst_image = imagecreatetruecolor( $width, $height );
453 $background = imagecolorallocate( $dst_image, 0, 0, 0 );
454 imagecolortransparent( $dst_image, $background );
455 imagealphablending( $dst_image,
false );
457 if ( $colorStyle ==
'palette' ) {
460 imagecopyresized( $dst_image, $src_image,
463 imagesx( $src_image ), imagesy( $src_image ) );
465 imagecopyresampled( $dst_image, $src_image,
468 imagesx( $src_image ), imagesy( $src_image ) );
471 if ( $rotation % 360 != 0 && $rotation % 90 == 0 ) {
472 $rot_image = imagerotate( $dst_image, $rotation, 0 );
473 imagedestroy( $dst_image );
474 $dst_image = $rot_image;
477 imagesavealpha( $dst_image,
true );
479 $funcParams = [ $dst_image, $params[
'dstPath'] ];
480 if ( $useQuality && isset( $params[
'quality'] ) ) {
481 $funcParams[] = $params[
'quality'];
483 call_user_func_array( $saveType, $funcParams );
485 imagedestroy( $dst_image );
486 imagedestroy( $src_image );
488 return false; # No error
496 imageinterlace( $dst_image );
497 imagejpeg( $dst_image, $thumbPath, $quality );
509 # ImageMagick supports autorotation
512 # Imagick::rotateImage
515 # GD's imagerotate function is used to rotate images, but not
516 # all precompiled PHP versions have that function
517 return function_exists(
'imagerotate' );
519 # Other scalers don't support rotation
531 if ( $wgEnableAutoRotation === null ) {
559 wfDebug( __METHOD__ .
": running ImageMagick: $cmd\n" );
571 $im->readImage(
$params[
'srcPath'] );
572 if ( !$im->rotateImage(
new ImagickPixel(
'white' ), 360 - $rotation ) ) {
574 "Error rotating $rotation degrees" );
579 "Unable to write image to {$params['dstPath']}" );
585 "$scaler rotation not implemented" );
imageMagickSubsampling($pixelFormat)
Get ImageMagick subsampling factors for the target JPEG pixel format.
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
$wgImageMagickConvertCommand
The convert command shipped with ImageMagick.
div flags Integer display flags(NO_ACTION_LINK, NO_EXTRA_USER_LINKS) 'LogException'returning false will NOT prevent logging $e
static imageJpegWrapper($dst_image, $thumbPath, $quality=95)
Callback for transformGd when transforming jpeg images.
$wgImageMagickTempDir
Temporary directory used for ImageMagick.
transformImageMagickExt($image, $params)
Transform an image using the Imagick PHP extension.
transformImageMagick($image, $params)
Transform an image using ImageMagick.
This code would result in ircNotify being run twice when an article is and once for brion Hooks can return three possible true was required This is the default since MediaWiki *some string
$wgUseImageResize
Whether to enable server-side image thumbnailing.
$wgJpegPixelFormat
At default setting of 'yuv420', JPEG thumbnails will use 4:2:0 chroma subsampling to reduce file size...
transformGd($image, $params)
Transform an image using the built in GD library.
when a variable name is used in a it is silently declared as a new local masking the global
wfDebug($text, $dest= 'all', array $context=[])
Sends a line to the debug log if enabled or, optionally, to a comment in output.
The index of the header message $result[1]=The index of the body text message $result[2 through n]=Parameters passed to body text message.Please note the header message cannot receive/use parameters. 'ImportHandleLogItemXMLTag':When parsing a XML tag in a log item.Return false to stop further processing of the tag $reader:XMLReader object $logInfo:Array of information 'ImportHandlePageXMLTag':When parsing a XML tag in a page.Return false to stop further processing of the tag $reader:XMLReader object &$pageInfo:Array of information 'ImportHandleRevisionXMLTag':When parsing a XML tag in a page revision.Return false to stop further processing of the tag $reader:XMLReader object $pageInfo:Array of page information $revisionInfo:Array of revision information 'ImportHandleToplevelXMLTag':When parsing a top level XML tag.Return false to stop further processing of the tag $reader:XMLReader object 'ImportHandleUploadXMLTag':When parsing a XML tag in a file upload.Return false to stop further processing of the tag $reader:XMLReader object $revisionInfo:Array of information 'ImportLogInterwikiLink':Hook to change the interwiki link used in log entries and edit summaries for transwiki imports.&$fullInterwikiPrefix:Interwiki prefix, may contain colons.&$pageTitle:String that contains page title. 'ImportSources':Called when reading from the $wgImportSources configuration variable.Can be used to lazy-load the import sources list.&$importSources:The value of $wgImportSources.Modify as necessary.See the comment in DefaultSettings.php for the detail of how to structure this array. 'InfoAction':When building information to display on the action=info page.$context:IContextSource object &$pageInfo:Array of information 'InitializeArticleMaybeRedirect':MediaWiki check to see if title is a redirect.&$title:Title object for the current page &$request:WebRequest &$ignoreRedirect:boolean to skip redirect check &$target:Title/string of redirect target &$article:Article object 'InternalParseBeforeLinks':during Parser's internalParse method before links but after nowiki/noinclude/includeonly/onlyinclude and other processings.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InternalParseBeforeSanitize':during Parser's internalParse method just before the parser removes unwanted/dangerous HTML tags and after nowiki/noinclude/includeonly/onlyinclude and other processings.Ideal for syntax-extensions after template/parser function execution which respect nowiki and HTML-comments.&$parser:Parser object &$text:string containing partially parsed text &$stripState:Parser's internal StripState object 'InterwikiLoadPrefix':When resolving if a given prefix is an interwiki or not.Return true without providing an interwiki to continue interwiki search.$prefix:interwiki prefix we are looking for.&$iwData:output array describing the interwiki with keys iw_url, iw_local, iw_trans and optionally iw_api and iw_wikiid. 'InvalidateEmailComplete':Called after a user's email has been invalidated successfully.$user:user(object) whose email is being invalidated 'IRCLineURL':When constructing the URL to use in an IRC notification.Callee may modify $url and $query, URL will be constructed as $url.$query &$url:URL to index.php &$query:Query string $rc:RecentChange object that triggered url generation 'IsFileCacheable':Override the result of Article::isFileCacheable()(if true) &$article:article(object) being checked 'IsTrustedProxy':Override the result of IP::isTrustedProxy() &$ip:IP being check &$result:Change this value to override the result of IP::isTrustedProxy() 'IsUploadAllowedFromUrl':Override the result of UploadFromUrl::isAllowedUrl() $url:URL used to upload from &$allowed:Boolean indicating if uploading is allowed for given URL 'isValidEmailAddr':Override the result of Sanitizer::validateEmail(), for instance to return false if the domain name doesn't match your organization.$addr:The e-mail address entered by the user &$result:Set this and return false to override the internal checks 'isValidPassword':Override the result of User::isValidPassword() $password:The password entered by the user &$result:Set this and return false to override the internal checks $user:User the password is being validated for 'Language::getMessagesFileName':$code:The language code or the language we're looking for a messages file for &$file:The messages file path, you can override this to change the location. 'LanguageGetMagic':DEPRECATED!Use $magicWords in a file listed in $wgExtensionMessagesFiles instead.Use this to define synonyms of magic words depending of the language &$magicExtensions:associative array of magic words synonyms $lang:language code(string) 'LanguageGetNamespaces':Provide custom ordering for namespaces or remove namespaces.Do not use this hook to add namespaces.Use CanonicalNamespaces for that.&$namespaces:Array of namespaces indexed by their numbers 'LanguageGetSpecialPageAliases':DEPRECATED!Use $specialPageAliases in a file listed in $wgExtensionMessagesFiles instead.Use to define aliases of special pages names depending of the language &$specialPageAliases:associative array of magic words synonyms $lang:language code(string) 'LanguageGetTranslatedLanguageNames':Provide translated language names.&$names:array of language code=> language name $code:language of the preferred translations 'LanguageLinks':Manipulate a page's language links.This is called in various places to allow extensions to define the effective language links for a page.$title:The page's Title.&$links:Associative array mapping language codes to prefixed links of the form"language:title".&$linkFlags:Associative array mapping prefixed links to arrays of flags.Currently unused, but planned to provide support for marking individual language links in the UI, e.g.for featured articles. 'LanguageSelector':Hook to change the language selector available on a page.$out:The output page.$cssClassName:CSS class name of the language selector. 'LinkBegin':DEPRECATED!Use HtmlPageLinkRendererBegin instead.Used when generating internal and interwiki links in Linker::link(), before processing starts.Return false to skip default processing and return $ret.See documentation for Linker::link() for details on the expected meanings of parameters.$skin:the Skin object $target:the Title that the link is pointing to &$html:the contents that the< a > tag should have(raw HTML) $result
$wgSharpenParameter
Sharpening parameter to ImageMagick.
$wgUseImageMagick
Resizing can be done using PHP's internal image libraries or using ImageMagick or another third-party...
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 unsetoffset-wrap String Wrap the message in html(usually something like"<
canRotate()
Returns whether the current scaler supports rotation (im and gd do)
$wgMaxInterlacingAreas
Array of max pixel areas for interlacing per MIME type.
$wgCustomConvertCommand
Use another resizing converter, e.g.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getScalerType($dstPath, $checkDstPath=true)
Returns which scaler type should be used.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
$wgMaxAnimatedGifArea
Force thumbnailing of animated GIFs above this size to a single frame instead of an animated thumbnai...
validateParam($name, $value)
Generic handler for bitmap images.
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
wfEscapeShellArg()
Version of escapeshellarg() that works better on Windows.
getImageArea($image)
Function that returns the number of pixels to be thumbnailed.
$wgSharpenReductionThreshold
Reduction in linear dimensions below which sharpening will be enabled.
wfShellExecWithStderr($cmd, &$retval=null, $environ=[], $limits=[])
Execute a shell command, returning both stdout and stderr.
normaliseParams($image, &$params)
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
transformCustom($image, $params)
Transform an image using a custom command.
$wgEnableAutoRotation
If set to true, images that contain certain the exif orientation tag will be rotated accordingly...
Allows to change the fields on the form that will be generated $name