Commit graph

71 commits

Author SHA1 Message Date
Bartosz Dziewoński
1decdbce53 CSSMin: Make isRemoteUrl and isLocalUrl really private, now that we can in PHP 5.5
Well, protected, because we want to have unit tests for them, apparently.

Change-Id: I734b88599e5860aa59a07a89cc5389eb73b48813
2016-02-17 15:50:08 +01:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Timo Tijhof
419db58c8b Centralise url handling for urls to static resources
Keep in CSSMin as-is for back-compat and to ensure library remains
independent of MediaWiki.

Moved down a few lines as there is no need to compute the md5 hash when we're
returning a data URI. Previously md5_file was called twice during module builds
(once for the fallback url, and another time when producing the embedded data uri).

Applied to logo in SkinModule as example. To be applied elsewhere as needed.
Without it, fallback is current behaviour (no cache invalidation).

Bug: T99096
Change-Id: I7f38bfc1bea5c241bc4f8ec4f4b640fd65f2c04f
2016-02-02 23:26:16 +00:00
Amir E. Aharoni
ad275af1b3 Make lines shorter to pass phpcs under includes/libs
Bug: T102614
Change-Id: I40ca85dbc5849d6ff7ee584c82a8b56d07e095b6
2015-09-26 18:20:34 +00:00
Ori Livneh
889883b731 ResourceLoaderEditToolbarModule::cssSerializeString() → CSSMin::serializeStringValue()
ResourceLoaderEditToolbarModule is clearly the wrong place for something so
generic, so this method needs a new home. We can either introduce a new class
or find a suitable existing home. I think CSSMin is suitable. It has public
methods that do things that are closely related, like `encodeStringAsDataURI`
and `buildUrlValue`.

Change-Id: Icc6dfb8f47199e6188dd71948f4645baee085e51
2015-09-25 09:48:51 -07:00
Elliott Eggleston
c737e48d7f Strip comments before gathering url(...) refs in CSS
Change I5a3cdeb7d53485f161ccf8133e76850cdf5b4579 introduced tests
for existence of all local files referenced in CSS.  It's currently
failing changes even when the referenced files have been commented
out.  This change ensures that commented-out files are not included
in the testing list.

Change-Id: I2ad74c13a9cf36e96a7d7451bf229856bcd18422
2015-09-19 16:10:53 -04:00
Bartosz Dziewoński
8f5cd11d82 ResourcesTest: Detect missing files in url(...) expressions
The way this is implemented is really dirty... but it found us
a few pre-existing bugs already (T111518, T111519, T111771).
I think it might be worth it.

* CSSMin: Add new method getAllLocalFileReferences() which skips the
  file_exists() check.
* ResourceLoaderModule: Make use of it to track missing files too.
* ResourcesTest: Verify that the missing files are missing.

Change-Id: I5a3cdeb7d53485f161ccf8133e76850cdf5b4579
2015-09-16 00:27:23 +00:00
jenkins-bot
4590c637f5 Merge "CSSMin: remove dot segments in relative local URLs" 2015-08-20 14:11:36 +00:00
Ori Livneh
3063e85248 CSSMin: version URLs based on content, not mtime
The content of these files is more stable than their mtimes, which change
every time we roll out a new branch. Because MD5 avalanches well[0], using
the first five hexadecimal digits is sufficient to ensure that the chance
of two successive versions colliding is improbably small (roughly one in a
million).

[0]: https://en.wikipedia.org/wiki/Avalanche_effect

Change-Id: I1bdf94c58786d2545311b238476b48217a5a60af
2015-08-17 15:22:07 -07:00
Ori Livneh
5844ebcd93 CSSMin: remove dot segments in relative local URLs
Call wfRemoveDotSegments() (if available) on relative local URLs, so that
relative dot segments are collapsed.

Change-Id: Icc1c23a2a7d96c869412965bd8c3730d3c3b3a53
2015-08-16 10:41:45 -07:00
Ori Livneh
08633bd182 Use a fixed comment placeholder string in CSSMin
Both the problem and solution are nearly identical to the ones presented in
I31d4556bb. Use a constant string as a comment placeholder, and differentiate
it from possible user input using \x7f, which is not valid CSS anyway[1].

  [1]: http://www.w3.org/TR/CSS21/grammar.html

Change-Id: I3d3c2578d5e9c1fe52c02e87901cb08d03847ea7
2015-06-02 09:45:08 -07:00
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