MediaWiki REL1_37
ResourceLoaderImage Class Reference

Class encapsulating an image used in a ResourceLoaderImageModule. More...

Public Member Functions

 __construct ( $name, $module, $descriptor, $basePath, array $variants, $defaultColor=null)
 
 getDataUri (ResourceLoaderContext $context, $variant, $format)
 Get the data: URI that will produce this image.
 
 getExtension ( $format='original')
 Get the extension of the image.
 
 getImageData (ResourceLoaderContext $context, $variant=false, $format=false)
 Get actual image data for this image.
 
 getMimeType ( $format='original')
 Get the MIME type of the image.
 
 getModule ()
 Get name of the module this image belongs to.
 
 getName ()
 Get name of this image.
 
 getPath (ResourceLoaderContext $context)
 Get the path to image file for given context.
 
 getUrl (ResourceLoaderContext $context, $script, $variant, $format)
 Get the load.php URL that will produce this image.
 
 getVariants ()
 Get the list of variants this image can be converted to.
 
 sendResponseHeaders (ResourceLoaderContext $context)
 Send response headers (using the header() function) that are necessary to correctly serve the image data for this image, as returned by getImageData().
 

Protected Member Functions

 getLangFallbacks (string $lang)
 
 getLocalPath ( $path)
 
 massageSvgPathdata ( $svg)
 Massage the SVG image data for converters which don't understand some path data syntax.
 
 rasterize ( $svg)
 Convert passed image data, which is assumed to be SVG, to PNG.
 
 variantize (array $variantConf, ResourceLoaderContext $context)
 Convert this image, which is assumed to be SVG, to given variant.
 

Private Member Functions

 varyOnLanguage ()
 Check if the image depends on the language.
 

Private Attributes

string $basePath
 
string null $defaultColor
 
string array $descriptor
 
string $extension
 
string $module
 
string $name
 
array $variants
 

Detailed Description

Class encapsulating an image used in a ResourceLoaderImageModule.

Since
1.25

Definition at line 32 of file ResourceLoaderImage.php.

Constructor & Destructor Documentation

◆ __construct()

ResourceLoaderImage::__construct (   $name,
  $module,
  $descriptor,
  $basePath,
array  $variants,
  $defaultColor = null 
)
Parameters
string$nameSelf-name of the image as known to ResourceLoaderImageModule.
string$moduleSelf-name of the module containing this image. Used to find the image in the registry e.g. through a load.php url.
string | array$descriptorPath to image file, or array structure containing paths
string$basePathDirectory to which paths in descriptor refer
array$variants
string | null$defaultColorof the base variant
Exceptions
InvalidArgumentException

Definition at line 69 of file ResourceLoaderImage.php.

References $basePath, $defaultColor, $descriptor, $ext, $module, $name, $path, $variants, and getLocalPath().

Member Function Documentation

◆ getDataUri()

ResourceLoaderImage::getDataUri ( ResourceLoaderContext  $context,
  $variant,
  $format 
)

Get the data: URI that will produce this image.

Parameters
ResourceLoaderContext$contextAny context
string | null$variantVariant to get the URI for
string$formatFormat to get the URI for, 'original' or 'rasterized'
Returns
string

Definition at line 262 of file ResourceLoaderImage.php.

References $type.

Referenced by ResourceLoaderImageModule\getStyleDeclarations().

◆ getExtension()

ResourceLoaderImage::getExtension (   $format = 'original')

Get the extension of the image.

Parameters
string$formatFormat to get the extension for, 'original' or 'rasterized'
Returns
string Extension without leading dot, e.g. 'png'

Definition at line 209 of file ResourceLoaderImage.php.

◆ getImageData()

ResourceLoaderImage::getImageData ( ResourceLoaderContext  $context,
  $variant = false,
  $format = false 
)

Get actual image data for this image.

This can be saved to a file or sent to the browser to produce the converted image.

Call getExtension() or getMimeType() with the same $format argument to learn what file type the returned data uses.

Parameters
ResourceLoaderContext$contextImage context, or any context if $variant and $format given.
string | null$variantVariant to get the data for. Optional; if given, overrides the data from $context.
string$formatFormat to get the data for, 'original' or 'rasterized'. Optional; if given, overrides the data from $context.
Returns
string|false Possibly binary image data, or false on failure
Exceptions
MWExceptionIf the image file doesn't exist

Definition at line 284 of file ResourceLoaderImage.php.

References $path, ResourceLoaderContext\getFormat(), ResourceLoaderContext\getVariant(), and wfDebugLog().

◆ getLangFallbacks()

ResourceLoaderImage::getLangFallbacks ( string  $lang)
protected
Access: internal
For unit testing overrride
Parameters
string$lang
Returns
string[]

Definition at line 151 of file ResourceLoaderImage.php.

◆ getLocalPath()

ResourceLoaderImage::getLocalPath (   $path)
protected
Parameters
string | ResourceLoaderFilePath$path
Returns
string

Definition at line 195 of file ResourceLoaderImage.php.

References $path.

Referenced by __construct().

◆ getMimeType()

ResourceLoaderImage::getMimeType (   $format = 'original')

Get the MIME type of the image.

Parameters
string$formatFormat to get the MIME type for, 'original' or 'rasterized'
Returns
string

Definition at line 222 of file ResourceLoaderImage.php.

References $ext.

◆ getModule()

ResourceLoaderImage::getModule ( )

Get name of the module this image belongs to.

Returns
string

Definition at line 133 of file ResourceLoaderImage.php.

References $module.

◆ getName()

ResourceLoaderImage::getName ( )

Get name of this image.

Returns
string

Definition at line 124 of file ResourceLoaderImage.php.

References $name.

◆ getPath()

ResourceLoaderImage::getPath ( ResourceLoaderContext  $context)

Get the path to image file for given context.

Parameters
ResourceLoaderContext$contextAny context
Returns
string
Exceptions
MWExceptionIf no matching path is found

Definition at line 164 of file ResourceLoaderImage.php.

References $lang, ResourceLoaderContext\getDirection(), and ResourceLoaderContext\getLanguage().

◆ getUrl()

ResourceLoaderImage::getUrl ( ResourceLoaderContext  $context,
  $script,
  $variant,
  $format 
)

Get the load.php URL that will produce this image.

Parameters
ResourceLoaderContext$contextAny context
string$scriptURL to load.php
string | null$variantVariant to get the URL for
string$formatFormat to get the URL for, 'original' or 'rasterized'
Returns
string URL

Definition at line 236 of file ResourceLoaderImage.php.

References ResourceLoaderContext\getLanguage(), ResourceLoaderContext\getResourceLoader(), ResourceLoaderContext\getSkin(), and wfAppendQuery().

Referenced by ResourceLoaderImageModule\getStyleDeclarations().

◆ getVariants()

ResourceLoaderImage::getVariants ( )

Get the list of variants this image can be converted to.

Returns
string[]

Definition at line 142 of file ResourceLoaderImage.php.

◆ massageSvgPathdata()

ResourceLoaderImage::massageSvgPathdata (   $svg)
protected

Massage the SVG image data for converters which don't understand some path data syntax.

This is necessary for rsvg and ImageMagick when compiled with rsvg support. Upstream bug is https://bugzilla.gnome.org/show_bug.cgi?id=620923, fixed 2014-11-10, so this will be needed for a while. (T76852)

Parameters
string$svgSVG image data
Returns
string Massaged SVG image data

Definition at line 380 of file ResourceLoaderImage.php.

◆ rasterize()

ResourceLoaderImage::rasterize (   $svg)
protected

Convert passed image data, which is assumed to be SVG, to PNG.

Parameters
string$svgSVG image data
Returns
string|bool PNG image data, or false on failure

Definition at line 401 of file ResourceLoaderImage.php.

References $command, $res, $wgSVGConverter, $wgSVGConverterPath, SvgHandler\rasterize(), and wfTempDir().

◆ sendResponseHeaders()

ResourceLoaderImage::sendResponseHeaders ( ResourceLoaderContext  $context)

Send response headers (using the header() function) that are necessary to correctly serve the image data for this image, as returned by getImageData().

Note that the headers are independent of the language or image variant.

Parameters
ResourceLoaderContext$contextImage context

Definition at line 328 of file ResourceLoaderImage.php.

◆ variantize()

ResourceLoaderImage::variantize ( array  $variantConf,
ResourceLoaderContext  $context 
)
protected

Convert this image, which is assumed to be SVG, to given variant.

Parameters
array$variantConfArray with a 'color' key, its value will be used as fill color
ResourceLoaderContext$contextImage context
Returns
string New SVG file data

Definition at line 345 of file ResourceLoaderImage.php.

◆ varyOnLanguage()

ResourceLoaderImage::varyOnLanguage ( )
private

Check if the image depends on the language.

Returns
bool

Definition at line 484 of file ResourceLoaderImage.php.

Member Data Documentation

◆ $basePath

string ResourceLoaderImage::$basePath
private

Definition at line 51 of file ResourceLoaderImage.php.

Referenced by __construct().

◆ $defaultColor

string null ResourceLoaderImage::$defaultColor
private

Definition at line 55 of file ResourceLoaderImage.php.

Referenced by __construct().

◆ $descriptor

string array ResourceLoaderImage::$descriptor
private

Definition at line 49 of file ResourceLoaderImage.php.

Referenced by __construct().

◆ $extension

string ResourceLoaderImage::$extension
private

Definition at line 57 of file ResourceLoaderImage.php.

◆ $module

string ResourceLoaderImage::$module
private

Definition at line 47 of file ResourceLoaderImage.php.

Referenced by __construct(), and getModule().

◆ $name

string ResourceLoaderImage::$name
private
Initial value:
=[,,,,]
private const FILE_TYPES
'svg' => 'image/svg+xml'
'png' => 'image/png'
'gif' => 'image/gif'
'jpg' => 'image/jpg'

Definition at line 45 of file ResourceLoaderImage.php.

Referenced by __construct(), and getName().

◆ $variants

array ResourceLoaderImage::$variants
private

Definition at line 53 of file ResourceLoaderImage.php.

Referenced by __construct().


The documentation for this class was generated from the following file: