MediaWiki REL1_28
CSSMin Class Reference

Transforms CSS data. More...

Inheritance diagram for CSSMin:

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, $ie8Compat=true)
 Encode an image file as a data URI.
 
static encodeStringAsDataURI ( $contents, $type, $ie8Compat=true)
 Encode file contents as a data URI with chosen MIME type.
 
static getLocalFileReferences ( $source, $path)
 Get a list of local files referenced in a stylesheet (includes non-existent files).
 
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 / * @embed * / comment.
 
static remapOne ( $file, $query, $local, $remote, $embed)
 Remap or embed a CSS URL path.
 
static serializeStringValue ( $value)
 Serialize a string (escape and quote) for use as a CSS string value.
 

Public Attributes

const COMMENT_REGEX = '\/\*.*?\*\/'
 
const DATA_URI_SIZE_LIMIT = 32768
 Internet Explorer data URI length limit.
 
const EMBED_REGEX = '\/\*\s*\@embed\s*\*\/'
 
const URL_REGEX = 'url\(\s*[\'"]?(?P<file>[^\?\‍)\'"]*?)(?P<query>\?[^\‍)\'"]*?|)[\'"]?\s*\‍)'
 

Static Protected Member Functions

static isLocalUrl ( $maybeUrl)
 Is this CSS rule referencing a local URL?
 
static isRemoteUrl ( $maybeUrl)
 Is this CSS rule referencing a remote URL?
 

Static Protected Attributes

static array $mimeTypes
 List of common image files extensions and MIME-types.
 

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

◆ buildUrlValue()

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 207 of file CSSMin.php.

Referenced by ResourceLoaderSkinModule\getStyles(), CssContentHandler\makeRedirectContent(), remap(), and CSSMinTest\testBuildUrlValue().

◆ encodeImageAsDataURI()

static CSSMin::encodeImageAsDataURI (   $file,
  $type = null,
  $ie8Compat = true 
)
static

Encode an image file as a data URI.

If the image file has a suitable MIME type and size, encode it as a data URI, base64-encoded for binary files or just percent-encoded otherwise. Return false if the image type is unfamiliar or file 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.
bool$ie8CompatBy default, a data URI will only be produced if it can be made short enough to fit in Internet Explorer 8 (and earlier) URI length limit (32,768 bytes). Pass false to remove this limitation.
Returns
string|bool Image contents encoded as a data URI or false.

Definition at line 105 of file CSSMin.php.

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

Referenced by remapOne().

◆ encodeStringAsDataURI()

static CSSMin::encodeStringAsDataURI (   $contents,
  $type,
  $ie8Compat = true 
)
static

Encode file contents as a data URI with chosen MIME type.

The URI will be base64-encoded for binary files or just percent-encoded otherwise.

Since
1.25
Parameters
string$contentsFile contents to encode.
string$typeFile's MIME type.
bool$ie8CompatSee encodeImageAsDataURI().
Returns
string|bool Image contents encoded as a data URI or false.

Definition at line 133 of file CSSMin.php.

References $type.

Referenced by encodeImageAsDataURI(), and ResourceLoaderImage\getDataUri().

◆ getLocalFileReferences()

static CSSMin::getLocalFileReferences (   $source,
  $path 
)
static

Get a list of local files referenced in a stylesheet (includes non-existent files).

Parameters
string$sourceCSS stylesheet source to process
string$pathFile path where the source was read from
Returns
array List of local file references

Definition at line 69 of file CSSMin.php.

References $files, $matches, $path, $source, and as.

Referenced by ResourceLoaderFileModule\readStyleFile(), and ResourcesTest\testCommentedLocalFileReferences().

◆ getMimeType()

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

Definition at line 178 of file CSSMin.php.

References $ext.

Referenced by encodeImageAsDataURI(), and remap().

◆ isLocalUrl()

static CSSMin::isLocalUrl (   $maybeUrl)
staticprotected

Is this CSS rule referencing a local URL?

Parameters
string$maybeUrl
Returns
bool

Reimplemented in CSSMinTestable.

Definition at line 382 of file CSSMin.php.

◆ isRemoteUrl()

static CSSMin::isRemoteUrl (   $maybeUrl)
staticprotected

Is this CSS rule referencing a remote URL?

Parameters
string$maybeUrl
Returns
bool

Reimplemented in CSSMinTestable.

Definition at line 369 of file CSSMin.php.

◆ minify()

static CSSMin::minify (   $css)
static

Removes whitespace from CSS data.

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

Definition at line 453 of file CSSMin.php.

References $css.

Referenced by ResourceLoader\applyFilter(), MinifyScript\minify(), CSSMinTest\testMinify(), and ResourcesTest\testStyleMedia().

◆ remap()

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 / * @embed * / 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 / * @embed * / is found.
Returns
string Remapped CSS data

Definition at line 229 of file CSSMin.php.

References $mimeTypes, $source, buildUrlValue(), COMMENT_REGEX, EMBED_REGEX, getMimeType(), remapOne(), true, URL_REGEX, and use.

Referenced by ResourceLoaderFileModule\readStyleFile(), and CSSMinTest\testRemapRemapping().

◆ remapOne()

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 399 of file CSSMin.php.

References $query, encodeImageAsDataURI(), PROTO_RELATIVE, OutputPage\transformFilePath(), wfExpandUrl(), and wfRemoveDotSegments().

Referenced by remap().

◆ serializeStringValue()

static CSSMin::serializeStringValue (   $value)
static

Serialize a string (escape and quote) for use as a CSS string value.

http://www.w3.org/TR/2013/WD-cssom-20131205/#serialize-a-string

Parameters
string$value
Returns
string
Exceptions
Exception

Definition at line 163 of file CSSMin.php.

References $value.

Referenced by ResourceLoaderEditToolbarModule\getLessVars().

Member Data Documentation

◆ $mimeTypes

array CSSMin::$mimeTypes
staticprotected
Initial value:
= [
'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',
]

List of common image files extensions and MIME-types.

Definition at line 48 of file CSSMin.php.

Referenced by remap().

◆ COMMENT_REGEX

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

Definition at line 43 of file CSSMin.php.

Referenced by remap().

◆ DATA_URI_SIZE_LIMIT

const CSSMin::DATA_URI_SIZE_LIMIT = 32768

Internet Explorer data URI length limit.

See encodeImageAsDataURI().

Definition at line 40 of file CSSMin.php.

◆ EMBED_REGEX

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

Definition at line 42 of file CSSMin.php.

Referenced by remap().

◆ URL_REGEX

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: