MediaWiki  REL1_24
CSSMin Class Reference

Transforms CSS data. More...

List of all members.

Static Public Member Functions

static buildUrlValue ($url)
 Build a CSS 'url()' value for the given URL, quoting parentheses (and other funny characters) and escaping quotes as necessary.
static encodeImageAsDataURI ($file, $type=null, $sizeLimit=self::EMBED_SIZE_LIMIT)
 Encode an image file as a base64 data URI.
static getLocalFileReferences ($source, $path=null)
 Gets a list of local file paths which are referenced in a CSS style sheet.
static getMimeType ($file)
static minify ($css)
 Removes whitespace from CSS data.
static remap ($source, $local, $remote, $embedData=true)
 Remaps CSS URL paths and automatically embeds data URIs for CSS rules or url() values preceded by an / * * / comment.
static remapOne ($file, $query, $local, $remote, $embed)
 Remap or embed a CSS URL path.

Public Attributes

const COMMENT_REGEX = '\/\*.*?\*\/'
const EMBED_REGEX = '\/\*\s*\@embed\s*\*\/'
const EMBED_SIZE_LIMIT = 24576
 Maximum file size to still qualify for in-line embedding as a data-URI.
const URL_REGEX = 'url\(\s*[\'"]?(?P<file>[^\?\)\'"]*?)(?P<query>\?[^\)\'"]*?|)[\'"]?\s*\)'

Static Protected Attributes

static $mimeTypes

Detailed Description

Transforms CSS data.

This class provides minification, URL remapping, URL extracting, and data-URL embedding.

Definition at line 30 of file CSSMin.php.


Member Function Documentation

static CSSMin::buildUrlValue ( url) [static]

Build a CSS 'url()' value for the given URL, quoting parentheses (and other funny characters) and escaping quotes as necessary.

See http://www.w3.org/TR/css-syntax-3/#consume-a-url-token

Parameters:
string$urlURL to process
Returns:
string 'url()' value, usually just `"url($url)"`, quoted/escaped if necessary

Definition at line 165 of file CSSMin.php.

References array().

Referenced by remap(), and CSSMinTest\testBuildUrlValue().

static CSSMin::encodeImageAsDataURI ( file,
type = null,
sizeLimit = self::EMBED_SIZE_LIMIT 
) [static]

Encode an image file as a base64 data URI.

If the image file has a suitable MIME type and size, encode it as a base64 data URI. Return false if the image type is unfamiliar or exceeds the size limit.

Parameters:
string$fileImage file to encode.
string | null$typeFile's MIME type or null. If null, CSSMin will try to autodetect the type.
int | bool$sizeLimitIf the size of the target file is greater than this value, decline to encode the image file and return false instead. If $sizeLimit is false, no limit is enforced.
Returns:
string|bool: Image contents encoded as a data URI or false.

Definition at line 116 of file CSSMin.php.

References $file, $type, and getMimeType().

Referenced by remapOne().

static CSSMin::getLocalFileReferences ( source,
path = null 
) [static]

Gets a list of local file paths which are referenced in a CSS style sheet.

This function will always return an empty array if the second parameter is not given or null for backwards-compatibility.

Parameters:
string$sourceCSS data to remap
string$pathFile path where the source was read from (optional)
Returns:
array List of local file references

Definition at line 72 of file CSSMin.php.

References $file, $files, $matches, $path, $source, array(), and as.

static CSSMin::getMimeType ( file) [static]
Parameters:
$filestring
Returns:
bool|string

Definition at line 136 of file CSSMin.php.

References $ext, and $file.

Referenced by encodeImageAsDataURI().

static CSSMin::minify ( css) [static]

Removes whitespace from CSS data.

Parameters:
string$cssCSS data to minify
Returns:
string Minified CSS data

Definition at line 354 of file CSSMin.php.

References $css, and array().

Referenced by CSSMinTest\testMinify(), and ResourcesTest\testStyleMedia().

static CSSMin::remap ( source,
local,
remote,
embedData = true 
) [static]

Remaps CSS URL paths and automatically embeds data URIs for CSS rules or url() values preceded by an / * * / comment.

Parameters:
string$sourceCSS data to remap
string$localFile path where the source was read from
string$remoteURL path to the file
bool$embedDataIf false, never do any data URI embedding, even if / * * / is found.
Returns:
string Remapped CSS data

Definition at line 187 of file CSSMin.php.

References $source, array(), buildUrlValue(), COMMENT_REGEX, EMBED_REGEX, remapOne(), and URL_REGEX.

Referenced by ResourceLoaderWikiModule\getStyles(), and CSSMinTest\testRemapRemapping().

static CSSMin::remapOne ( file,
query,
local,
remote,
embed 
) [static]

Remap or embed a CSS URL path.

Parameters:
string$fileURL to remap/embed
string$query
string$localFile path where the source was read from
string$remoteURL path to the file
bool$embedWhether to do any data URI embedding
Returns:
string Remapped/embedded URL data

Definition at line 301 of file CSSMin.php.

References $file, $query, encodeImageAsDataURI(), and wfExpandUrl().

Referenced by remap().


Member Data Documentation

CSSMin::$mimeTypes [static, protected]
Initial value:
 array(
        'gif' => 'image/gif',
        'jpe' => 'image/jpeg',
        'jpeg' => 'image/jpeg',
        'jpg' => 'image/jpeg',
        'png' => 'image/png',
        'tif' => 'image/tiff',
        'tiff' => 'image/tiff',
        'xbm' => 'image/x-xbitmap',
        'svg' => 'image/svg+xml',
    )

Definition at line 48 of file CSSMin.php.

const CSSMin::COMMENT_REGEX = '\/\*.*?\*\/'

Definition at line 43 of file CSSMin.php.

Referenced by remap().

const CSSMin::EMBED_REGEX = '\/\*\s*\@embed\s*\*\/'

Definition at line 42 of file CSSMin.php.

Referenced by remap().

const CSSMin::EMBED_SIZE_LIMIT = 24576

Maximum file size to still qualify for in-line embedding as a data-URI.

24,576 is used because Internet Explorer has a 32,768 byte limit for data URIs, which when base64 encoded will result in a 1/3 increase in size.

Definition at line 40 of file CSSMin.php.

const CSSMin::URL_REGEX = 'url\(\s*[\'"]?(?P<file>[^\?\)\'"]*?)(?P<query>\?[^\)\'"]*?|)[\'"]?\s*\)'

Definition at line 41 of file CSSMin.php.

Referenced by remap().


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