MediaWiki REL1_34
|
Class encapsulating an image used in a ResourceLoaderImageModule. More...
Public Member Functions | |
__construct ( $name, $module, $descriptor, $basePath, $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 | |
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 ( $variantConf, ResourceLoaderContext $context) | |
Convert this image, which is assumed to be SVG, to given variant. | |
Static Protected Attributes | |
static array | $fileTypes |
Map of allowed file extensions to their MIME types. | |
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 |
Class encapsulating an image used in a ResourceLoaderImageModule.
Definition at line 29 of file ResourceLoaderImage.php.
ResourceLoaderImage::__construct | ( | $name, | |
$module, | |||
$descriptor, | |||
$basePath, | |||
$variants, | |||
$defaultColor = null |
|||
) |
string | $name | Self-name of the image as known to ResourceLoaderImageModule. |
string | $module | Self-name of the module containing this image. Used to find the image in the registry e.g. through a load.php url. |
string | array | $descriptor | Path to image file, or array structure containing paths |
string | $basePath | Directory to which paths in descriptor refer |
array | $variants | |
string | null | $defaultColor | of the base variant |
InvalidArgumentException |
Definition at line 67 of file ResourceLoaderImage.php.
References $basePath, $defaultColor, $descriptor, $ext, $module, $name, $path, $variants, and getLocalPath().
ResourceLoaderImage::getDataUri | ( | ResourceLoaderContext | $context, |
$variant, | |||
$format | |||
) |
Get the data: URI that will produce this image.
ResourceLoaderContext | $context | Any context |
string | null | $variant | Variant to get the URI for |
string | $format | Format to get the URI for, 'original' or 'rasterized' |
Definition at line 249 of file ResourceLoaderImage.php.
References $type, CSSMin\encodeStringAsDataURI(), getImageData(), and getMimeType().
Referenced by ResourceLoaderImageModule\getStyleDeclarations().
ResourceLoaderImage::getExtension | ( | $format = 'original' | ) |
Get the extension of the image.
string | $format | Format to get the extension for, 'original' or 'rasterized' |
Definition at line 196 of file ResourceLoaderImage.php.
References $extension.
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.
ResourceLoaderContext | $context | Image context, or any context if $variant and $format given. |
string | null | $variant | Variant to get the data for. Optional; if given, overrides the data from $context. |
string | $format | Format to get the data for, 'original' or 'rasterized'. Optional; if given, overrides the data from $context. |
MWException | If the image file doesn't exist |
Definition at line 271 of file ResourceLoaderImage.php.
References $context, $defaultColor, $path, getExtension(), getPath(), rasterize(), variantize(), and wfDebugLog().
Referenced by getDataUri().
|
protected |
string | ResourceLoaderFilePath | $path |
Definition at line 182 of file ResourceLoaderImage.php.
References $path.
Referenced by __construct(), and getPath().
ResourceLoaderImage::getMimeType | ( | $format = 'original' | ) |
Get the MIME type of the image.
string | $format | Format to get the MIME type for, 'original' or 'rasterized' |
Definition at line 209 of file ResourceLoaderImage.php.
References $ext, and getExtension().
Referenced by getDataUri(), and sendResponseHeaders().
ResourceLoaderImage::getModule | ( | ) |
Get name of the module this image belongs to.
Definition at line 131 of file ResourceLoaderImage.php.
References $module.
Referenced by ResourceLoaderContext\getImageObj(), and getUrl().
ResourceLoaderImage::getName | ( | ) |
Get name of this image.
Definition at line 122 of file ResourceLoaderImage.php.
References $name.
Referenced by getUrl(), and sendResponseHeaders().
ResourceLoaderImage::getPath | ( | ResourceLoaderContext | $context | ) |
Get the path to image file for given context.
ResourceLoaderContext | $context | Any context |
MWException | If no matching path is found |
Definition at line 151 of file ResourceLoaderImage.php.
References $context, $descriptor, $lang, and getLocalPath().
Referenced by getImageData(), and variantize().
ResourceLoaderImage::getUrl | ( | ResourceLoaderContext | $context, |
$script, | |||
$variant, | |||
$format | |||
) |
Get the load.php URL that will produce this image.
ResourceLoaderContext | $context | Any context |
string | $script | URL to load.php |
string | null | $variant | Variant to get the URL for |
string | $format | Format to get the URL for, 'original' or 'rasterized' |
Definition at line 223 of file ResourceLoaderImage.php.
References $context, getModule(), getName(), varyOnLanguage(), and wfAppendQuery().
Referenced by ResourceLoaderImageModule\getStyleDeclarations().
ResourceLoaderImage::getVariants | ( | ) |
Get the list of variants this image can be converted to.
Definition at line 140 of file ResourceLoaderImage.php.
|
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)
string | $svg | SVG image data |
Definition at line 367 of file ResourceLoaderImage.php.
Referenced by rasterize().
|
protected |
Convert passed image data, which is assumed to be SVG, to PNG.
string | $svg | SVG image data |
Definition at line 388 of file ResourceLoaderImage.php.
References $command, $res, $wgSVGConverter, $wgSVGConverterPath, massageSvgPathdata(), SvgHandler\rasterize(), 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.
ResourceLoaderContext | $context | Image context |
Definition at line 315 of file ResourceLoaderImage.php.
References $context, getExtension(), getMimeType(), getName(), and FileBackend\makeContentDisposition().
|
protected |
Convert this image, which is assumed to be SVG, to given variant.
array | $variantConf | Array with a 'color' key, its value will be used as fill color |
ResourceLoaderContext | $context | Image context |
Definition at line 332 of file ResourceLoaderImage.php.
References getPath().
Referenced by getImageData().
|
private |
Check if the image depends on the language.
Definition at line 473 of file ResourceLoaderImage.php.
Referenced by getUrl().
|
private |
Definition at line 49 of file ResourceLoaderImage.php.
Referenced by __construct().
|
private |
Definition at line 53 of file ResourceLoaderImage.php.
Referenced by __construct(), and getImageData().
|
private |
Definition at line 47 of file ResourceLoaderImage.php.
Referenced by __construct(), and getPath().
|
private |
Definition at line 55 of file ResourceLoaderImage.php.
Referenced by getExtension().
|
staticprotected |
Map of allowed file extensions to their MIME types.
Definition at line 35 of file ResourceLoaderImage.php.
|
private |
Definition at line 45 of file ResourceLoaderImage.php.
Referenced by __construct(), and getModule().
|
private |
Definition at line 43 of file ResourceLoaderImage.php.
Referenced by __construct(), and getName().
|
private |
Definition at line 51 of file ResourceLoaderImage.php.
Referenced by __construct().