35 const PLACEHOLDER =
"\x7fPLACEHOLDER\x7f";
41 const URL_REGEX =
'url\(\s*[\'"]?(?P<file>[^\?\)\'"]*?)(?P<query>\?[^\)\'"]*?|)[\'"]?\s*\)';
50 'jpe' =>
'image/jpeg',
51 'jpeg' =>
'image/jpeg',
52 'jpg' =>
'image/jpeg',
54 'tif' =>
'image/tiff',
55 'tiff' =>
'image/tiff',
56 'xbm' =>
'image/x-xbitmap',
57 'svg' =>
'image/svg+xml',
70 $stripped = preg_replace(
'/' . self::COMMENT_REGEX .
'/s',
'',
$source );
74 $rFlags = PREG_OFFSET_CAPTURE | PREG_SET_ORDER;
75 if ( preg_match_all(
'/' . self::URL_REGEX .
'/', $stripped,
$matches, $rFlags ) ) {
77 $url = $match[
'file'][0];
80 if ( substr( $url, 0, 2 ) ===
'//' || parse_url( $url, PHP_URL_SCHEME ) ) {
107 if ( $ie8Compat && filesize( $file ) >= self::DATA_URI_SIZE_LIMIT ) {
111 if (
$type === null ) {
112 $type = self::getMimeType( $file );
118 return self::encodeStringAsDataURI( file_get_contents( $file ),
$type, $ie8Compat );
136 if ( preg_match(
'/^[\r\n\t\x20-\x7e]+$/', $contents ) ) {
139 $uri =
'data:' .
$type .
',' . rawurlencode( $contents );
140 if ( !$ie8Compat || strlen( $uri ) < self::DATA_URI_SIZE_LIMIT ) {
146 $uri =
'data:' .
$type .
';base64,' . base64_encode( $contents );
147 if ( !$ie8Compat || strlen( $uri ) < self::DATA_URI_SIZE_LIMIT ) {
164 if ( strstr(
$value,
"\0" ) ) {
165 throw new Exception(
"Invalid character in CSS string" );
167 $value = strtr(
$value, [
'\\' =>
'\\\\',
'"' =>
'\\"' ] );
168 $value = preg_replace_callback(
'/[\x01-\x1f\x7f-\x9f]/',
function ( $match ) {
169 return '\\' . base_convert( ord( $match[0] ), 10, 16 ) .
' ';
171 return '"' .
$value .
'"';
179 $realpath = realpath( $file );
182 && function_exists(
'finfo_file' )
183 && function_exists(
'finfo_open' )
184 && defined(
'FILEINFO_MIME_TYPE' )
186 return finfo_file( finfo_open( FILEINFO_MIME_TYPE ), $realpath );
190 $ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
191 if ( isset( self::$mimeTypes[
$ext] ) ) {
192 return self::$mimeTypes[
$ext];
211 if ( preg_match(
'!^[\w\d:@/~.%+;,?&=-]+$!', $url ) ) {
214 return 'url("' . strtr( $url, [
'\\' =>
'\\\\',
'"' =>
'\\"' ] ) .
'")';
229 public static function remap(
$source, $local, $remote, $embedData =
true ) {
241 if ( substr( $remote, -1 ) ==
'/' ) {
242 $remote = substr( $remote, 0, -1 );
256 $source = preg_replace_callback(
258 function ( $match )
use ( &$comments ) {
259 $comments[] = $match[ 0 ];
260 return CSSMin::PLACEHOLDER . ( count( $comments ) - 1 ) .
'x';
271 $source = preg_replace_callback(
273 function ( $matchOuter )
use ( $local, $remote, $embedData ) {
274 $rule = $matchOuter[0];
279 $rule = preg_replace(
281 CSSMin::PLACEHOLDER .
293 $pattern =
'/(?P<embed>' . CSSMin::EMBED_REGEX .
'\s*|)' .
CSSMin::URL_REGEX .
'/';
295 $ruleWithRemapped = preg_replace_callback(
297 function ( $match )
use ( $local, $remote ) {
298 $remapped =
CSSMin::remapOne( $match[
'file'], $match[
'query'], $local, $remote,
false );
309 $ruleWithEmbedded = preg_replace_callback(
311 function ( $match )
use ( $embedAll, $local, $remote, &
$mimeTypes ) {
312 $embed = $embedAll || $match[
'embed'];
321 $url = $match[
'file'] . $match[
'query'];
322 $file = $local . $match[
'file'];
324 !self::isRemoteUrl( $url ) && !self::isLocalUrl( $url )
325 && file_exists( $file )
339 if ( !$embedData || $ruleWithEmbedded === $ruleWithRemapped ) {
341 return $ruleWithRemapped;
342 } elseif ( $embedData && $needsEmbedFallback ) {
346 return "$ruleWithEmbedded;$ruleWithRemapped!ie";
349 return $ruleWithEmbedded;
354 $pattern =
'/' . CSSMin::PLACEHOLDER .
'(\d+)x/';
355 $source = preg_replace_callback( $pattern,
function( $match )
use ( &$comments ) {
356 return $comments[ $match[1] ];
370 if ( substr( $maybeUrl, 0, 2 ) ===
'//' || parse_url( $maybeUrl, PHP_URL_SCHEME ) ) {
383 if ( $maybeUrl !==
'' && $maybeUrl[0] ===
'/' && !self::isRemoteUrl( $maybeUrl ) ) {
405 if ( self::isLocalUrl( $url ) && function_exists(
'wfExpandUrl' ) ) {
411 if ( self::isRemoteUrl( $url ) || self::isLocalUrl( $url ) ) {
415 if ( $local ===
false ) {
417 $url = $remote .
'/' . $url;
420 $url =
"{$remote}/{$file}";
422 $localFile =
"{$local}/{$file}";
423 if ( file_exists( $localFile ) ) {
425 $data = self::encodeImageAsDataURI( $localFile );
426 if ( $data !==
false ) {
430 if ( method_exists(
'OutputPage',
'transformFilePath' ) ) {
435 $url .=
'?' . substr( md5_file( $localFile ), 0, 5 );
441 if ( function_exists(
'wfRemoveDotSegments' ) ) {
456 [
'; ',
': ',
' {',
'{ ',
', ',
'} ',
';}' ],
457 [
';',
':',
'{',
'{',
',',
'}',
'}' ],
458 preg_replace( [
'/\s+/',
'/\/\*.*?\*\//s' ], [
' ',
'' ],
$css )
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
static remapOne($file, $query, $local, $remote, $embed)
Remap or embed a CSS URL path.
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
wfExpandUrl($url, $defaultProto=PROTO_CURRENT)
Expand a potentially local URL to a fully-qualified URL.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
static array $mimeTypes
List of common image files extensions and MIME-types.
static transformFilePath($remotePathPrefix, $localPath, $file)
Utility method for transformResourceFilePath().
static encodeImageAsDataURI($file, $type=null, $ie8Compat=true)
Encode an image file as a data URI.
static array static getLocalFileReferences($source, $path)
Get a list of local files referenced in a stylesheet (includes non-existent files).
static isLocalUrl($maybeUrl)
Is this CSS rule referencing a local URL?
static serializeStringValue($value)
Serialize a string (escape and quote) for use as a CSS string value.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
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 ...
static buildUrlValue($url)
Build a CSS 'url()' value for the given URL, quoting parentheses (and other funny characters) and esc...
wfRemoveDotSegments($urlPath)
Remove all dot-segments in the provided URL path.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
static getMimeType($file)
static minify($css)
Removes whitespace from CSS data.
static isRemoteUrl($maybeUrl)
Is this CSS rule referencing a remote URL?
static encodeStringAsDataURI($contents, $type, $ie8Compat=true)
Encode file contents as a data URI with chosen MIME type.
const DATA_URI_SIZE_LIMIT
Internet Explorer data URI length limit.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type