Commit graph

60 commits

Author SHA1 Message Date
Timo Tijhof
a3725a66af CSSMin: Optimise isLocalUrl by moving fast comparison forward
Change-Id: I668e248bd51fb75dfeeef3b74973f517a188c7ba
2015-01-29 19:47:55 +00:00
Bartosz Dziewoński
6e82fe6417 CSSMin: Rewrite encodeImageAsDataURI()
* Make it actually check against the URI length, not file size.
  Previous code could produce URIs that edged just over the limit.
* Replace $sizeLimit parameter with $ie8Compat, because that's the
  only use case and the file size limit approach was flawed per above,
  anyway.
* Remove CSSMin::EMBED_SIZE_LIMIT constant, which is not used anymore.
  CSSMin::DATA_URI_SIZE_LIMIT still exists.
* Change code flow to avoid repetition.
* Split off new method, encodeStringAsDataURI(), that does actual
  encoding rather than file handling.

Change-Id: I3704404ce831d7e0f6e3a65f23c76f313ad13238
2014-11-16 18:06:35 +00:00
Bartosz Dziewoński
bf3b97791b CSSMin: Don't generate double rules for IE < 8 when embedding SVG files
Bug: 71003
Change-Id: Ic232e8d62b164940003afdfe7cce9f964d7e9cbc
2014-09-30 21:19:58 +00:00
Bartosz Dziewoński
fa223d65d6 CSSMin: Do not base64-encode non-binary files when embedding
Do not base64-encode non-binary files (containing only whitespace and
printable ASCII characters, which matches sane SVG files).

For SVG files the percent-encoded URIs are actually slightly longer
than the base64-encoded ones (~10%), but compress a lot better
resulting on 15-20% less data to transfer after gzip compression.

(The effect is best seen on the 'oojs-ui' module, which consists
mostly of SVG icons – especially after commenting out everything other
than 'oojs-ui.svg.css'.)

I tried this for binary files too, just in case; but as expected, they
suffer from a noticeable size increase even with compression (~15%).

Bug: 67341
Change-Id: Iddaf863b6be98570a2bb8e606f13946a96345f65
2014-09-30 23:13:42 +02:00
Bartosz Dziewoński
4c01f8b2bc Make "/*@noflip*/ /*@embed*/" annotation work without CSSJanus hacks
This reverts most of commit 2d842f1425,
leaving only the test added in it, and reimplements the same
functionality better.

Instead of stripping /*@noflip*/ annotations in CSSJanus, which is
incompatible with other implementations that preserve it, extend
CSSMin to allow other CSS comments to be present before the
rule-global @embed annotation. (This required making the regex logic
in it even worse than it was, but it's actually slightly less terrible
than I expected it would be. Good thing we have tests!)

Bug: 69698
Change-Id: I58603ef64f7d7cdc6461b34721a4d6b15f15ad79
2014-09-23 22:47:54 +00:00
Kevin Israel
eac059c722 Remove dead mime_content_type() code paths
Since PHP 5.3, mime_content_type() is implemented as part of PHP's
fileinfo extension and thus is deprecated in favor of the newer
alternatives provided by that extension (already in use).

Also updated a comment in DefaultSettings.php that mentioned the
function. Did not modify lessc.inc.php, a third-party library
maintained separately from MediaWiki.

Change-Id: Ic4a0873989ddb634ec9a05c3340941a9ba3f5ec5
2014-09-03 16:35:35 +00:00
rillke
c31fbf073e Unify the spelling of MIME in documentation
Writing MIME as written in Wikipedia and some documentation clean up.

Change-Id: I9dfc36d2bf55d72d9374c4075bd6d45eef0415a4
2014-08-07 23:38:45 +02:00
Timo Tijhof
3b229c06be CSSMin: Add link to css-syntax spec for url tokens on w3.org
Change-Id: I9bfd7016ba4ec106e1b92602fd6d8188b8b183f3
2014-07-12 02:00:55 +02:00
Stephan Gambke
3b1b2b0c33 Fix CSSMin url() remapping when comments in CSS contain curly braces
Remapping of url()s was thrown off if the CSS contained comments
with curly braces. To fix, replace all block comments (except @embed
directives) with placeholders before url() processing and swap them
back in afterwards. Patch also includes tests.

Bug: 60077
Change-Id: If18a93c17ea9bcd529f6a664aa2dcc51d4a37f38
2014-06-30 09:14:10 +00:00
Trevor Parscal
3e2fd810d2 Revert "Fix "CSSMin url() value remapping not working in certain obscure cases""
This reverts commit fa1053a16a.

Breaks CSS output, making the skin and extensions look unstyled.

Change-Id: I297150f775dd5559f91f2c9c25c64b134459c6b6
2014-06-10 22:04:40 +00:00
Stephan Gambke
fa1053a16a Fix "CSSMin url() value remapping not working in certain obscure cases"
This patch extends the regex used to find URLs by css block quote subpatterns.

Bug: 60077
Change-Id: Ife00d01b78c6369f20ffc49d20aa58e354a61ee7
2014-06-09 23:50:28 +02:00
Siebrand Mazeland
40e04816f0 Pass phpcs-strict on includes/libs/
No changes to "real" libs. They are excluded from CodeSniffer tests.

Change-Id: Ifd14c0be24014fd9629a31e9bd155b27e2c0e93d
2014-04-24 21:48:10 +02:00
Bartosz Dziewoński
603174ff41 CSSMin: Don't do file_exists on random data in getLocalFileReferences()
If it's a URL, it obviously can't be a local file; check that first to
avoid PHP warnings about malformed paths.

Bug: 60960
Change-Id: Id784c089c3de8af79af7524ef5ab5cc2f7b8af9e
2014-03-10 20:55:02 +01:00
Bartosz Dziewoński
ae839a0fac CSSMin: Clean up the logic in getLocalFileReferences()
The function used to check if the $path parameter is null on every
inner loop iteration, only to effectively return an empty array if it
was. Rephrased the code to say exactly that.

(Not sure what the behavior is good for, though…)

Change-Id: I716bfde581d3ed4c02f0d9f544beb9d0a1906261
2014-02-28 21:26:56 +01:00
Reedy
05b70dc29e Remove unreachable statement
Change-Id: I79175695698a6ef393eff841580263c867719e25
2014-01-30 04:06:03 +00:00
jenkins-bot
2fd7a38349 Merge "Add SVG versions of enhanced recent changes collapse/show arrows" 2013-12-27 22:38:54 +00:00
m4tx
3b3042891e Add SVG versions of enhanced recent changes collapse/show arrows
Bug: 35344
Change-Id: I1fcc255691048cb8929a68096e1e0e56e934f020
2013-12-27 23:32:17 +01:00
Bartosz Dziewoński
2c866d8e73 CSSMin: Correctly format 'url()' values with parentheses etc.
Introduce new static function, CSSMin::buildUrlValue.

Actually using such values in CSS does not work well because the
URL_REGEX is nowhere near good enough. :(

Change-Id: I04a7078dd0087bcb461fa5e5168c870d37c255f4
2013-12-11 22:22:59 +01:00
Bartosz Dziewoński
e36dcfa4c6 CSSMin: Change behavior for missing files
We would previously return the path to the local file on the
filesystem, which is useless in all cases and possibly a security
issue in some. Now we return the URL at which the file would be
accessible had it existed.

Also reordered the code around that part to make the control flow
clearer and added a test.

Change-Id: I1d5befb2ea385ae4d316c5d8c5d1fc092b64c4ff
2013-12-11 21:21:36 +01:00
Bartosz Dziewoński
3987b10b51 CSSMin: Fix remapOne() for URLs that are proto-relative or have query part
Bug: 58338
Change-Id: I836a2c054ae3edc07895b2388f4ec8663223347a
2013-12-11 20:58:28 +01:00
Bartosz Dziewoński
f3779e067f Rewrite CSSMin::remap to support multiple url() values in one rule
Each can be selectively embedded by placing the /* @embed */ comment
just before the url() value. /* @embed */ at the beginning of the rule
affects all url() values appearing in it.

Three changes in existing behavior for previously supported syntax:
* /* @embed */ comments are no longer preserved in output
* rules not terminated by semicolons are correctly supported
* spaces within url() values are correctly supported

Bug: 46757
Bug: 56514
Change-Id: If9082f553fa920c606f12093f39f4a163ebacc32
2013-11-29 18:23:33 +00:00
Ori Livneh
755f0a9fc6 CSSMin: factor out image encoding into encodeImageAsDataURI method
The code for encoding suitable images as base64 data URIs was previously part
of the remap method of CSSMin, which greps CSS files for /* @embed */
annotations. This patch moves it into its own method, encodeImageAsDataURI.

Change-Id: I6f57116c6a6c18ff9d4e28760dd484ea2c8fc493
2013-09-18 15:09:20 -07:00
Ori Livneh
adee3374bf Make CSSMin::getMimeType public rather than protected
There's no reason why it should be protected. People sometimes use
'protected' to mean 'ancillary to the main purpose of the class', but
'protected' comes with the added cost of making the class API less
flexible. I intend to call this method in a future revision of Id052a04dd2,
but I think it should be public regardless.

Change-Id: I56365df3152df1180ce73de98202e3a91def1485
2013-09-18 04:09:21 +00:00
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
Timo Tijhof
90fd3bdea5 CSSMin: Clean up $remote trailing slash fix
* No need to strip them from everywhere all over. This bug is only
  caused by the presence of a trailing slash on $remote.

* To make sure everything still works before and after I added
  unit tests for CSSMin in Ic9195614acfd, making this dependent
  on that change.

Change-Id: Ia82048a328a056117afe0d653fe22f5429b21f5a
2012-06-20 14:30:10 +02:00
Alexandre Emsenhuber
63176b99b7 Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent.

Change-Id: I1deb70318d01a257b51948ba806d80cd1a239f4f
2012-05-04 08:47:07 +02:00
Roan Kattouw
23ab0f7162 (bug 34114) CSSMin::remap() doesn't respect its $embed parameter. Patch by Gilles van den Hoven 2012-02-02 10:30:57 +00:00
Sam Reed
4622da783c More documentation! 2011-10-26 04:15:09 +00:00
Sam Reed
27665d27ae Update some deprecated code
Documentation

Fix "/*" comments to "/**"

Flesh out some missing returns, change some return types
2011-10-14 21:18:38 +00:00
Roan Kattouw
b3599d8f8c Followup to r92580 and r93820: r92580 duplicated the call to wfExpandUrl(), and r93820 caused them to get out of sync. 2011-08-14 13:35:06 +00:00
Roan Kattouw
3e0a770524 Fix syntax error in r93820 2011-08-03 13:12:55 +00:00
Roan Kattouw
ae7d7676fb Fix r93820: PROT_ -> PROTO_ 2011-08-03 13:11:42 +00:00
Roan Kattouw
6adb2e86a5 Some random URL protocol forcing for protocol-relative URLs 2011-08-03 12:58:21 +00:00
Roan Kattouw
cb8418647f Fixes for URL expanding in CSSMin: adjust the offset correctly (this could've theoretically resulted in very strange bugs) and only call wfExpandUrl() if available (the file is in includes/libs so it should work outside of MediaWiki) 2011-07-19 21:19:50 +00:00
Sam Reed
bdf84cb20e Swap else if for elseif
Trimming trailing whitespace also

Doing in 3 commits, so hopefully reviewable in CR...
2011-06-17 16:03:52 +00:00
Brion Vibber
5feb09f086 * (bug 25262) Fix for minification of hardcoded data: URIs in CSS
CSSMin::minify()'s processing of url references for path adjustment or embedding had excluded explicit fully-qualified http: and https: URLs, but was damaging others such as data: URIs that were actually hardcoded into the original CSS.
This was affecting styles used on no.wikipedia.org which embedded a few icons directly into the style sheet.
Now checking for any URL scheme rather than hardcoding a check for http & https.
2011-05-10 20:14:30 +00:00
Ryan Kaldari
55fc4f6a86 oops, don't delete char before the slash, followup to r83902 2011-03-15 02:03:01 +00:00
Ryan Kaldari
754e09b59b keep double slash filter from breaking absolute URLs, fix to r83902 2011-03-15 01:57:37 +00:00
Roan Kattouw
797544d3a3 (bug 27052) CSSMin generated URLs like foo//../bar in some cases, which apparently resolves to foo/bar rather than foo/../bar or bar . Fixed by eliminating duplicate slashes from the file URL when remapping 2011-03-14 15:01:50 +00:00
Roan Kattouw
97a945864a (bug 27328) Redo r82218 properly, expanding URLs with absolute paths 2011-02-19 14:58:16 +00:00
Roan Kattouw
a99d1f47e5 Revert r82218 , doesn't fix absolute path URLs but breaks them. Will fix properly in next commit 2011-02-19 14:46:49 +00:00
Roan Kattouw
94ab016fb2 Followup r82156: skip relative URLs with absolute paths too 2011-02-16 06:27:22 +00:00
Trevor Parscal
64e5faa430 Resolves remaining issues in r82000 with remapping relative CSS URLs that contained queries. 2011-02-15 00:49:34 +00:00
Trevor Parscal
7a1903ec6b Resolves bug #27328 by supporting URL rewriting for CSS that comes from the Wiki, such as user and site scripts. 2011-02-11 22:57:32 +00:00
Trevor Parscal
083125258c Resolves bug #26655 - adds support for space before and after the URL inside the parenthesis of a url() statement in CSS. 2011-01-10 21:31:12 +00:00
Roan Kattouw
b548c98abb (bug 26228) On certain PHP 5.2 installs, finfo functions can be available while FILEINFO_MIME_TYPE is not. Check for the latter explicitly 2010-12-05 13:38:25 +00:00
Roan Kattouw
f21e31ccaa Fix typo in comment 2010-12-03 23:34:12 +00:00
Aaron Schulz
fe9076c3c8 Broke and split up many long lines 2010-12-02 19:49:54 +00:00
Roan Kattouw
1bf567fa6b (bug 25735) Fix regex error in PHP < 5.2.2 by using old (?P<name>) syntax for named subpatterns. Patch by Paul Oranje. 2010-11-01 14:31:32 +00:00
Roan Kattouw
bd02732734 Per r74946 CR, check whether realpath( $file ) returns false before using it 2010-10-18 15:11:48 +00:00