MediaWiki  1.28.1
ResourceLoaderImage Class Reference

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

Inheritance diagram for ResourceLoaderImage:

Public Member Functions

static array __construct ($name, $module, $descriptor, $basePath, $variants)
 
 getDataUri (ResourceLoaderContext $context, $variant, $format)
 Get the data: URI that will produce this image. More...
 
 getExtension ($format= 'original')
 Get the extension of the image. More...
 
 getImageData (ResourceLoaderContext $context, $variant=false, $format=false)
 Get actual image data for this image. More...
 
 getMimeType ($format= 'original')
 Get the MIME type of the image. More...
 
 getModule ()
 Get name of the module this image belongs to. More...
 
 getName ()
 Get name of this image. More...
 
 getPath (ResourceLoaderContext $context)
 Get the path to image file for given context. More...
 
 getUrl (ResourceLoaderContext $context, $script, $variant, $format)
 Get the load.php URL that will produce this image. More...
 
 getVariants ()
 Get the list of variants this image can be converted to. More...
 
 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(). More...
 

Protected Member Functions

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

Static Protected Attributes

static array $fileTypes
 Map of allowed file extensions to their MIME types. More...
 

Detailed Description

Class encapsulating an image used in a ResourceLoaderImageModule.

Since
1.25

Definition at line 28 of file ResourceLoaderImage.php.

Constructor & Destructor Documentation

static array ResourceLoaderImage::__construct (   $name,
  $module,
  $descriptor,
  $basePath,
  $variants 
)
Parameters
string$nameImage name
string$moduleModule name
string | array$descriptorPath to image file, or array structure containing paths
string$basePathDirectory to which paths in descriptor refer
array$variants
Exceptions
InvalidArgumentException

Definition at line 49 of file ResourceLoaderImage.php.

References $basePath, $ext, $extensions, $name, $path, array(), as, name, and use.

Member Function Documentation

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 193 of file ResourceLoaderImage.php.

References $type, CSSMin\encodeStringAsDataURI(), getImageData(), and getMimeType().

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 144 of file ResourceLoaderImage.php.

Referenced by getImageData(), getMimeType(), and sendResponseHeaders().

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 215 of file ResourceLoaderImage.php.

References $path, getExtension(), ResourceLoaderContext\getFormat(), getPath(), ResourceLoaderContext\getVariant(), rasterize(), variantize(), and wfDebugLog().

Referenced by getDataUri().

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 158 of file ResourceLoaderImage.php.

References $ext, and getExtension().

Referenced by getDataUri(), and sendResponseHeaders().

ResourceLoaderImage::getModule ( )

Get name of the module this image belongs to.

Returns
string

Definition at line 106 of file ResourceLoaderImage.php.

Referenced by getUrl().

ResourceLoaderImage::getName ( )

Get name of this image.

Returns
string

Definition at line 97 of file ResourceLoaderImage.php.

References $name.

Referenced by getUrl(), and sendResponseHeaders().

ResourceLoaderImage::getPath ( ResourceLoaderContext  $context)

Get the path to image file for given context.

Parameters
ResourceLoaderContext$contextAny context
Returns
string

Definition at line 125 of file ResourceLoaderImage.php.

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

Referenced by getImageData(), and variantize().

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

Definition at line 172 of file ResourceLoaderImage.php.

References $query, ResourceLoaderContext\getLanguage(), getModule(), getName(), ResourceLoaderContext\getVersion(), and wfAppendQuery().

ResourceLoaderImage::getVariants ( )

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

Returns
string[]

Definition at line 115 of file ResourceLoaderImage.php.

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 296 of file ResourceLoaderImage.php.

References as.

Referenced by 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 317 of file ResourceLoaderImage.php.

References $command, $handler, $res, $wgSVGConverter, $wgSVGConverterPath, SVGMetadataExtractor\getMetadata(), global, massageSvgPathdata(), wfEscapeShellArg(), and wfTempDir().

Referenced by getImageData().

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 256 of file ResourceLoaderImage.php.

References $mime, getExtension(), ResourceLoaderContext\getFormat(), getMimeType(), getName(), and FileBackend\makeContentDisposition().

ResourceLoaderImage::variantize (   $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 273 of file ResourceLoaderImage.php.

References getPath().

Referenced by getImageData().

Member Data Documentation

array ResourceLoaderImage::$fileTypes
staticprotected
Initial value:
= [
'svg' => 'image/svg+xml'

Map of allowed file extensions to their MIME types.

Definition at line 34 of file ResourceLoaderImage.php.


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