33 const PLACEHOLDER =
"\x7fPLACEHOLDER\x7f";
46 'jpe' =>
'image/jpeg',
47 'jpeg' =>
'image/jpeg',
48 'jpg' =>
'image/jpeg',
50 'tif' =>
'image/tiff',
51 'tiff' =>
'image/tiff',
52 'xbm' =>
'image/x-xbitmap',
53 'svg' =>
'image/svg+xml',
64 $stripped = preg_replace(
'/' . self::COMMENT_REGEX .
'/s',
'',
$source );
68 $rFlags = PREG_OFFSET_CAPTURE | PREG_SET_ORDER;
69 if ( preg_match_all(
'/' . self::getUrlRegex() .
'/', $stripped,
$matches, $rFlags ) ) {
72 $url = $match[
'file'][0];
76 substr( $url, 0, 2 ) ===
'//' ||
77 parse_url( $url, PHP_URL_SCHEME )
83 $anchor = strpos( $url,
'#' );
84 if ( $anchor !==
false ) {
85 $url = substr( $url, 0, $anchor );
93 $files[] =
$path . $url;
116 if ( $ie8Compat && filesize( $file ) >= self::DATA_URI_SIZE_LIMIT ) {
120 if (
$type ===
null ) {
146 $contents = preg_replace(
"/<\\?xml.*?\\?>/",
'', $contents );
148 if ( preg_match(
'/^[\r\n\t\x20-\x7e]+$/', $contents ) ) {
151 $encoded = rawurlencode( $contents );
153 $encoded = strtr( $encoded, [
163 $encoded = preg_replace(
'/ {2,}/',
' ', $encoded );
165 $encoded = preg_replace(
'/^ | $/',
'', $encoded );
167 $uri =
'data:' .
$type .
',' . $encoded;
168 if ( !$ie8Compat || strlen( $uri ) < self::DATA_URI_SIZE_LIMIT ) {
174 $uri =
'data:' .
$type .
';base64,' . base64_encode( $contents );
175 if ( !$ie8Compat || strlen( $uri ) < self::DATA_URI_SIZE_LIMIT ) {
191 $value = strtr(
$value, [
"\0" =>
"\u{FFFD}",
'\\' =>
'\\\\',
'"' =>
'\\"' ] );
192 $value = preg_replace_callback(
'/[\x01-\x1f\x7f]/',
function ( $match ) {
193 return '\\' . base_convert( ord( $match[0] ), 10, 16 ) .
' ';
195 return '"' .
$value .
'"';
204 $ext = strtolower( pathinfo( $file, PATHINFO_EXTENSION ) );
205 if ( isset( self::$mimeTypes[
$ext] ) ) {
206 return self::$mimeTypes[
$ext];
209 return mime_content_type( realpath( $file ) );
225 if ( preg_match(
'!^[\w\d:@/~.%+;,?&=-]+$!', $url ) ) {
228 return 'url("' . strtr( $url, [
'\\' =>
'\\\\',
'"' =>
'\\"' ] ) .
'")';
243 public static function remap(
$source, $local, $remote, $embedData =
true ) {
255 if ( substr( $remote, -1 ) ==
'/' ) {
256 $remote = substr( $remote, 0, -1 );
268 $pattern =
'/(?!' . self::EMBED_REGEX .
')(' . self::COMMENT_REGEX .
')/s';
270 $source = preg_replace_callback(
272 function ( $match )
use ( &$comments ) {
273 $comments[] = $match[ 0 ];
274 return CSSMin::PLACEHOLDER . ( count( $comments ) - 1 ) .
'x';
285 $source = preg_replace_callback(
287 function ( $matchOuter )
use ( $local, $remote, $embedData ) {
288 $rule = $matchOuter[0];
293 $rule = preg_replace(
295 CSSMin::PLACEHOLDER .
309 $ruleWithRemapped = preg_replace_callback(
311 function ( $match )
use ( $local, $remote ) {
314 $remapped =
CSSMin::remapOne( $match[
'file'], $match[
'query'], $local, $remote,
false );
324 $ruleWithEmbedded = preg_replace_callback(
326 function ( $match )
use ( $embedAll, $local, $remote, &
$mimeTypes ) {
329 $embed = $embedAll || $match[
'embed'];
338 $url = $match[
'file'] . $match[
'query'];
339 $file =
"{$local}/{$match['file']}";
341 !self::isRemoteUrl( $url ) && !self::isLocalUrl( $url )
342 && file_exists( $file )
356 if ( !$embedData || $ruleWithEmbedded === $ruleWithRemapped ) {
358 return $ruleWithRemapped;
359 } elseif ( $embedData && $needsEmbedFallback ) {
363 return "$ruleWithEmbedded;$ruleWithRemapped!ie";
366 return $ruleWithEmbedded;
371 $pattern =
'/' . self::PLACEHOLDER .
'(\d+)x/';
372 $source = preg_replace_callback( $pattern,
function ( $match )
use ( &$comments ) {
373 return $comments[ $match[1] ];
386 if ( substr( $maybeUrl, 0, 2 ) ===
'//' || parse_url( $maybeUrl, PHP_URL_SCHEME ) ) {
399 return isset( $maybeUrl[1] ) && $maybeUrl[0] ===
'/' && $maybeUrl[1] !==
'/';
407 if ( $urlRegex ===
null ) {
430 'url\(\s*(?P<file0>[^\s\'"][^\?\)]+?)(?P<query0>\?[^\)]*?|)\s*\)' .
432 '|url\(\s*\'(?P<file1>[^\?\']+?)(?P<query1>\?[^\']*?|)\'\s*\)' .
434 '|url\(\s*"(?P<file2>[^\?"]+?)(?P<query2>\?[^"]*?|)"\s*\)' .
441 if ( $flags & PREG_SET_ORDER ) {
445 if ( isset( $match[
'file0'] ) && $match[
'file0'][1] !== -1 ) {
446 $match[
'file'] = $match[
'file0'];
447 $match[
'query'] = $match[
'query0'];
448 } elseif ( isset( $match[
'file1'] ) && $match[
'file1'][1] !== -1 ) {
449 $match[
'file'] = $match[
'file1'];
450 $match[
'query'] = $match[
'query1'];
452 if ( !isset( $match[
'file2'] ) || $match[
'file2'][1] === -1 ) {
453 throw new Exception(
'URL must be non-empty' );
455 $match[
'file'] = $match[
'file2'];
456 $match[
'query'] = $match[
'query2'];
459 if ( isset( $match[
'file0'] ) && $match[
'file0'] !==
'' ) {
460 $match[
'file'] = $match[
'file0'];
461 $match[
'query'] = $match[
'query0'];
462 } elseif ( isset( $match[
'file1'] ) && $match[
'file1'] !==
'' ) {
463 $match[
'file'] = $match[
'file1'];
464 $match[
'query'] = $match[
'query1'];
466 if ( !isset( $match[
'file2'] ) || $match[
'file2'] ===
'' ) {
467 throw new Exception(
'URL must be non-empty' );
469 $match[
'file'] = $match[
'file2'];
470 $match[
'query'] = $match[
'query2'];
491 if ( self::isLocalUrl( $url ) && function_exists(
'wfExpandUrl' ) ) {
499 self::isRemoteUrl( $url ) ||
500 self::isLocalUrl( $url ) ||
501 substr( $url, 0, 1 ) ===
'#'
506 if ( $local ===
false ) {
508 $url = $remote .
'/' . $url;
511 $url =
"{$remote}/{$file}";
513 $localFile =
"{$local}/{$file}";
514 if ( file_exists( $localFile ) ) {
517 if ( $data !==
false ) {
521 if ( class_exists( OutputPage::class ) ) {
522 $url = OutputPage::transformFilePath( $remote, $local, $file );
526 $url .=
'?' . substr( md5_file( $localFile ), 0, 5 );
532 if ( function_exists(
'wfRemoveDotSegments' ) ) {
547 [
'; ',
': ',
' {',
'{ ',
', ',
'} ',
';}',
'( ',
' )',
'[ ',
' ]' ],
548 [
';',
':',
'{',
'{',
',',
'}',
'}',
'(',
')',
'[',
']' ],
549 preg_replace( [
'/\s+/',
'/\/\*.*?\*\//s' ], [
' ',
'' ],
$css )
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.
wfRemoveDotSegments( $urlPath)
Remove all dot-segments in the provided URL path.
static serializeStringValue( $value)
Serialize a string (escape and quote) for use as a CSS string value.
static buildUrlValue( $url)
Build a CSS 'url()' value for the given URL, quoting parentheses (and other funny characters) and esc...
static encodeImageAsDataURI( $file, $type=null, $ie8Compat=true)
Encode an image file as a data URI.
static getMimeType( $file)
static string[] $mimeTypes
List of common image files extensions and MIME-types.
static isRemoteUrl( $maybeUrl)
Is this CSS rule referencing a remote URL?
static getLocalFileReferences( $source, $path)
Get a list of local files referenced in a stylesheet (includes non-existent files).
static encodeStringAsDataURI( $contents, $type, $ie8Compat=true)
Encode file contents as a data URI with chosen MIME type.
static minify( $css)
Removes whitespace from CSS data.
static isLocalUrl( $maybeUrl)
Is this CSS rule referencing a local URL?
static processUrlMatch(array &$match, $flags=0)
static remapOne( $file, $query, $local, $remote, $embed)
Remap or embed a CSS URL path.
const DATA_URI_SIZE_LIMIT
Internet Explorer data URI length limit.
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 ...
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
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
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
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
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
if(!is_readable( $file)) $ext