Commit graph

15 commits

Author SHA1 Message Date
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
Tim Starling
9c3c0b704b Use array_fill_keys() instead of array_flip() if that reflects the developer's intention
array_fill_keys() was introduced in PHP 5.2.0 and works like
array_flip() except that it does only one thing (copying keys) instead
of two things (copying keys and values). That makes it faster and more
obvious.

When array_flip() calls were paired, I left them as is, because that
pattern is too cute. I couldn't kill something so cute.

Sometimes it was hard to figure out whether the values in array_flip()
result were used. That's the point of this change. If you use
array_fill_keys(), the intention is obvious.

Change-Id: If8d340a8bc816a15afec37e64f00106ae45e10ed
2021-06-15 00:11:10 +00:00
jdlrobson
de63b08fe1 resourceloader: Correctly handle a null getMessageBlob() in SkinModule
Fixes the issue:
> Warning: array_intersect_key(): Expected parameter 1 to be an array,
> null given
> in includes/resourceloader/ResourceLoaderLessVarFileModule.php

... for SkinModule instances without any LESS messages, which will
occur after I3905bc2c324 gets merged.

Change-Id: I0e3ba3c2cfa64bba49e3944d93e0c802b553bac8
2021-04-15 01:55:05 +01:00
Reedy
bbe130b242 Rename some variables to use more neutral language
Bug: T254646
Change-Id: I997625b8201dce2c257d20f96d00089e995c2b0d
2021-03-19 16:18:49 +00:00
Timo Tijhof
245bdafd9e resourceloader: Add wikimedia/minify package and remove local copies
- JavaScriptMinifier: The public interface for this internal class is
  ResourceLoader::filter which, except for one caller (minify.php)
  is indeed consistently used already, no other callers need replacing.

- CSSMin: Idem for minification, however, this class has some other
  method as well, which have a number of internal users, but none
  outside core. These have all been replaced in this commit.

- Remove pear/net_url2 as own dependency as this was only used by CSSMin
  and recently added there. This is now a dependency of wikimedia/minify
  instead. This was not part of the public API and no longer mentioned
  here in composer.json or RELEASE-NOTES. (It remains pinned in
  mediawiki-vendor, however.)

Bug: T273247
Depends-On: Iadff8c2112d5e53bd994ab4882006e8c644a2379
Depends-On: Id3c6dcc0b952a9efe34b3a9ed88b716101a51f87
Depends-On: I589be910f57289fd908b22db87241b0e52da60d4
Change-Id: I8d71fc64aeecdb31db218b02e361ae9bb0d19b48
2021-02-24 21:03:02 +00:00
Timo Tijhof
8ad97d7c32 resourceloader: Fail gracefully if a LESS message is not found
The message cache is originally meant for mw.messages in JS,
which expects non-existent messages to be cleanly omitted.
There is minimal server-side and client-side handling in place for this.

For LESS, however, we were assuming that the blob is complete,
thus not feeding anything to the LESS compiler, thus leading to
a run-time failure where the LESS file can't be parsed at all
due to an undeclared variable.

This could happen sometimes during development or after upgrading
a wiki with a stale LocalisationCache that is still being updated
at that time.

Bug: T267785
Change-Id: I60ff4eb7dce1fee56470acc177afd29ee14b764f
2021-01-07 15:41:02 -08:00
Timo Tijhof
91c73f6bac resourceloader: Add some typehints and misc clean up
* Add a void return hint to methods that are not meant to return
  anything. This helps catch accidental return statements in the
  future, lets Phan better understand how methods are meant to be
  used, and might also allow PHP to better optimise the compiled
  code form (speculation).

  I did not, however, add it to publicly extended methods as that
  might mess with strict mode.

* Remove the internal getResourceLoader() method from MessageBlobStore.
  This has been redundant since 3edaa0b37c.
  The method was protected, and not considered stable to subclass
  for extensions. Hence not a breaking change.

* Add Throwable typehint to formatException() and friends.
  This is the narrowest one I could add given that the methods
  called from here already enforce the same typehint.
  Update the doc to match for now. There isn't a reason right now
  to limit this only to Exception, and given this is the method
  and not the catch statement itself, does not change behaviour.

* Remove unused ResourceLoader->getHookContainer().
  Added within 1.35 cycle, safe to remove.

* Remove unexpected `@since` for `@internal` getHookRunner().

* Remove redundant `@internal` from ResourceLoaderMwUrlModule
  methods, which itself is already `@internal`.

Change-Id: I68d33ff6feca7ef95282a7ff03eb9332adfde31c
2020-07-02 03:05:59 +01:00
James D. Forrester
41f8acfd52 Coding style: Auto-fix MediaWiki.Commenting.DocComment.*
Change-Id: Iea5a07e10712723970a15008eb367e0af226fcc3
2020-01-10 12:28:12 -08:00
Timo Tijhof
fe11acb2a7 resourceloader: Document variable escape logic in LessVarFileModule
Also:
* Fix ref of CSSJanus that was meant to refer to CSSMin,
  and clarify that this is about LESS specifically (not related
  to CSS, and hence this is not something CSSMin can/should do),
  and that it isn't specific to less.php.

* Rename and invert excludeMessagesFromBlob as pluckFromMessageBlob
  so that we can express "get X" as "X" instead of "everything without Y".

* Remove the (object) cast from excludeMessagesFromBlob, which was specific
  to the use case of one of its callers (getMessageBlob) where it is now
  inlined.

Change-Id: Ia1667199aef6d383faeb213fb163cb0627d91f1e
2019-12-18 23:06:01 +00:00
Fomafix
705146d102 resourceloader: Add array type hints (2)
This change is a follow-up to a9823d16f6.

Change-Id: I80f570a98c02aa5521504262a6839e9241936db1
2019-10-10 04:58:16 +00:00
Fomafix
a9823d16f6 resourceloader: Add array type hints
Change-Id: I4844eae68e85adc46e52646ea066b459bbabdcce
2019-10-05 15:26:56 +00:00
Timo Tijhof
a5ce1d7792 resourceloader: Add Doxygen group and improve overall docs
* Add license header where missing.
* Add missing `@since` (1.17 for most classes), except
  ResourceLoaderLessVarFileModule since 1.32 (1bc62c548c).

* Remove duplicate file-level description for class-only files,
  merge with the class description instead.

* Remove my own `@author` annotation from one file.

* Mark core's own FileModule subclasses as `@internal`, except
  for the following which we support use of in extensions:
  ResourceLoaderLessVarFileModule,
  ResourceLoaderOOUIIconPackModule, and
  ResourceLoaderWikiModule.

Change-Id: I336af2e4ccdbe2512594e8861b72628d24194e41
2019-09-14 18:37:36 +00:00
Umherirrender
9fa4b4ebdb resourceloader: Fix return type in ResourceLoader-related classes
Change-Id: I543e321129cf8fadc1159017b622528f462ea116
2019-06-18 20:20:34 +00:00
Fomafix
ce6ae6ada0 ResourceLoaderLessVarFileModule: Add parameter 'lessMessages'
This change allows to add internationalized messages into CSS. The new
parameter 'lessMessages' contains the array of message keys that get
set as Less variables.

In Less the variables must enclosed in double quotes (") or single
quotes (') to prevent CSS injection.

Example usage:
Resources:
	"class": "ResourceLoaderLessVarFileModule",
	"lessMessages": [ "editsection" ],
Message 'editsection':
	edit
Less file:
	content: '[@{msg-editsection}]';
Generated CSS file:
	content: '[edit]';

Also add a type case (object) to ensure that an empty object is
serialized as '{}' and not as '[]'.

Also include Less variables from parent.

Change-Id: I280b52c6745fe8e5755dc5d58c5621a64757d99d
2018-05-12 17:46:15 +02:00
jdlrobson
1bc62c548c Introduce ResourceLoaderLessVarFileModule
This ResourceLoader module provides a way to ship
messages to CSS variables.

We will need this going forward to deal with flash of
unstyled content in various JavaScript based UIs that
are subject to i18n such as table sorting and
collapsible elements.

To avoid overhead of hitting the database to fetch and
transform localisation messages we make use of the MessageBlobStore
making use of `messages` definition already inside
ResourceLoaderFileModule. Given this resource is only intended
for render blocking styles without JavaScript this should be okay
(although if requested in JavaScript will also ship associated
messages)

Bug: T42812
Change-Id: I2bf12cdc848478889acbe9a7a970e46f8aefa287
2018-04-25 11:27:11 -07:00