Commit graph

226 commits

Author SHA1 Message Date
Ammarpad
1cf4eab3ab ApiParse: Support hidden skins
Since $wgSkipSkins is meant to only 'remove skin from preferences',
it should not affect parsing with them.

So these skins need to be allowed here.

To achive this, this patch adds getInstalledSkins() method to SkinFactory
to provide the complete. The method supersedes getSkinNames() which does
the same thing but with ambiguous name.

Description of getAllowedSkins() has been corrected as it was slightly incorrect.

Bug: T237856
Change-Id: I0889b823d27f1a2830cc0205f5a21ed4de744e08
2021-09-20 09:29:24 +01:00
jenkins-bot
adfa9a9503 Merge "resourceloader: Fix debug mode for RL-to-RL cross-wiki module loads" 2021-09-16 01:40:13 +00:00
Umherirrender
a2e6ff11f3 resourceloader: Avoid same named variables in inner and outer foreach
Change-Id: I308ba9c607ba56b6d8ebf7d5f56d9e19d217d946
2021-09-04 00:28:20 +02:00
jenkins-bot
ceac7b68a6 Merge "resourceloader: Call getStyleFiles from FileModule::getFileHashes" 2021-09-02 18:10:06 +00:00
Arlo Breault
f07e73dd9a resourceloader: Call getStyleFiles from FileModule::getFileHashes
ResourceLoaderFileModule::getFileHashes had its own code to collect
style files that omitted the feature files that ResourceLoaderSkinModule
adds.  This deduplication should fix the issue where
wgParserEnableLegacyMediaDOM was adding an additional feature file but
didn't seem to be invalidating the cache.

Bug: T51097
Bug: T290273
Change-Id: I50cf73a79cb1ce2b3d80510e80948e3e6fc1791b
2021-09-02 17:51:10 +00:00
Fomafix
ff7f41f928 resourceloader: Append newline to JavaScript only if missing
In debug mode of a packageFiles module there is now only one newline
between the JavaScript code and the closing }.

This change reuses ResourceLoader::ensureNewline and make this to a
interal public static function.

Change-Id: I89519896e3dc56d966c4a63102904686bff6fac9
2021-08-28 12:25:11 +00:00
Timo Tijhof
b99458ceab resourceloader: Fix debug mode for RL-to-RL cross-wiki module loads
The native "foreign module source" feature, as used by the GlobalCssJs
extension, did not work correctly in debug mode as the urls returned
by the remote wiki were formatted as "/w/load.php...", which would
be interpreted by the browser relative to the host document, instead
of relative to the parent script.

For example:

1. Page view on en.wikipedia.org.

2. Script call to
   meta.wikimedia.org/w/load.php?debug=true&modules=ext.globalCssJs.user&user

   This URL is formatted by getScriptURLsForDebug on en.wikipedia.org,
   when building the article HTML. It knows the modules is on Meta, and
   formats it as such.

   So far so good.

3. meta.wikimedia.org responds with an array of urls for sub resources.
   That array contained URLs like "/w/load.php...only=scripts".

   These were formatted by getScriptURLsForDebug running on Meta,
   no longer with a reason to make it a Meta-Wiki URL as it isn't
   perceived as cross-wiki. It is indistinguishable from debugging
   a Meta-Wiki page view from its perspective.

This patch affects scenario 3 by always expanding it relative to the
current-request's wgServer. We still only do this in debug mode. There
is not yet a need to do this in non-debug mode, and if there was we'd
likely want to find a way to avoid it in the common case to keep
embedded URLs short.

The ResourceLoader::expandUrl() method is similar to the one in
Wikimedia\Minify\CSSMin.

Test Plan:

* view-source:http://mw.localhost:8080/w/load.php?debug=1&modules=site
  For Module base class.
  Before, the array entries were relative. After, they are full.
* view-source:http://mw.localhost:8080/w/load.php?debug=1&modules=jquery
  For FileModule.
  Before, the array entries were relative. After, they are full.
* view-source:http://mw.localhost:8080/wiki/Main_Page?debug=true
  Unchanged.
* view-source:http://mw.localhost:8080/wiki/Main_Page
  Unchanged.

Bug: T255367
Change-Id: I83919744b2677c7fb52b84089ecc60b89957d32a
2021-08-25 20:05:38 +00:00
Timo Tijhof
1367e356e7 resourceloader: Remove isFileModule() overhead from web requests
About 1.5% of load.php wall-time is spent in isFileModule() calls
during the ServiceWiring/getResourceLoader/register call early on.

Reduce the overhead of this cost by moving that logic to the Module
class.

There are two costs that we save this way:

1. The inherent cost of applying the skinStyles.

   This is now limited to only the modules that are constructed in a
   given web request. Thus, apart from the startup response (which
   constructs all modules), for regular load.php requests and all
   index.php page views, the vast majority of modules will never need
   to be constructed, and thus won't pay this cost.

2. The overhead of predicting (and class-loading) for whether a module
   is (or will become) a FileModule object.

   This is what isFileModule() does and is the main reason I wrote
   this patch. It involves class loading, and checks and conditions that
   run 1000+ times at WMF. This is eliminated now because we no longer
   have to calculate this decision. Instead, the logic applies when
   it needs to (due to FileModule implementing it), and doesn't
   when it doesn't!

Change-Id: Ia2db14f930800c96e767b94ef62fb00e9d52725b
2021-08-19 01:18:32 +00:00
DannyS712
4f9970f30b Fix a bunch of random typos
* yeild -> yield
* paramter -> parameter
* seperator -> separator
* neccesary -> necessary
* inital -> initial
* intial -> initial
* repsonse -> response
* retreived -> retrieved

Bug: T201491
Change-Id: I461941b027590997448f3bdd8a137a48bb338beb
2021-06-29 11:32:04 +00:00
jdlrobson
e5f09fd1bb Installer: Do not use mediawiki.skinning.interface module
The `mediawiki.skinning.interface` module includes the `toc` feature
which is enabled by default,
which requires a working localization environment which requires
DBLoadBalancer which is disabled at this entry point.

Instead use ResourceLoaderSkinModule directly with an opt-in
policy where toc feature is not disbled.

This means the definition in Resources.php is no longer
necessary so it is marked for deprecation. The installer
now works.

A unit test is added to make sure the installer stylesheet
doesn't break again.

Bug: T270027
Change-Id: I851fcd0e50e3a70158d5bfa1fdcae3cd278694d6
2021-04-15 11:11:32 -07:00
anjali041
480c126305 Fix typo in code 'defintion'
Changed the typo 'defintion' to 'definition'

Bug: T201491
Change-Id: I6e866283b5fd8a2b2f237a770942ac03f735c138
2021-04-10 14:22:52 +05:30
jenkins-bot
d48d5292a6 Merge "resourceloader: Allow modules to mark themselves as ES6-only" 2021-03-07 02:56:03 +00:00
Roan Kattouw
b267f7aa90 resourceloader: Allow modules to mark themselves as ES6-only
Modules that set "es6": true in their module definition will error when
a non-ES6 client tries to load them.

To detect ES6 support, this looks for native Promise support,
RegExp.prototype.flags, and non-BMP characters in variable names. All
browsers that lack full ES6 support fail at least one of those checks.

To flag modules as requiring ES6, this adds a ! to the end of their
version string. This takes up much less space than adding another
register() parameter (which would have to be at the end). It's hacky,
but we expect this feature to be relatively temporary, until we require
ES6 for running any JS at all (probably in about a year).

For distinguishing different types of errors thrown from
sortDependencies(), use e.name. We can't subclass Error properly because
that requires ES6.

Bug: T272104
Change-Id: I45670c910ff12eb422ae54c9fcf372e45c7b2bf1
2021-03-04 14:53:36 -05: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
Tim Starling
e2a91921c5 resourceloader: Fix FileModule resource URLs for document root wikis
Per the comment in extractBasePaths(), remoteBasePath is typically '/'
when MediaWiki is installed in the document root. CSSMin knows what to
do with that, but getRemotePath() was getting it wrong, generating an
invalid protocol-relative URL.

So, add a simple hack for this case.

Change-Id: I16abf482e3a1a4a548c571de0e81cb3c1bdf55e1
2021-02-24 05:27:55 +00:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
jenkins-bot
1976283835 Merge "Update a lot of unspecific "array" types in PHPDocs" 2020-11-13 21:48:24 +00:00
Brad Jorsch
cd54c03e86 resourceloader: Remove wfExpandUrl() coupling from CSSMin
There are three cases in CSSMin::remap where performs path
resolution.

1. Absolute local path URLs to full URL.
   Example: url(/static/foo.png), url(/w/index.php?…), etc.

   These previously used wfExpandUrl(), which got the server
   name and protocol directly from $wgServer.

   We will now use the $remote parameter to get this information
   instead, which is generally set to something like
   https://wiki/w/resources/foo, and thus naturally contains
   the server name and protocol.

   The resolution is powered by the Net_URL2 library, allowing
   this to work outside Mediawiki as well.

   Some tests needed to change because they were calling CSSMin::remap
   with an incomplete $remote dummy values like "/" or "/w, because
   the test author (past me) was trying to be clever by not supplying
   it, knowing MW would ignore it. Now that it is consistently used,
   like normal calls from ResourceLoader would, the expected values
   will always be based on http://localhost/w, instead of sometimes
   the competing $wgServer value of `https://expand.example`.

2. Relative local path to full URL
   Example: url(foo.png), url(../foo.png), url(bar/foo.png)

   These were already using $remote. The only change is that
   they now use Net_URL2 library instead of blind string
   concatenation. One of the benefits of this is that we will
   no longer need to call wfRemoveDotSegments() to get rid
   of things like double slashes or redundant "../" sequences.
   Previously, thing like "foo//bar" or "foo/../bar" were cleaned
   up only due to wfRemoveDotSegments(). This is now naturally
   handled by Net_URL2.

3. Remote URLs
   Example: url(http://example.org/bar.png), url(//example.org/bar.png)

   This is generally not used in source code, but gadgets may use this,
   e.g. for upload.wikimedia.org or cross-wiki imports.

Other changes:

* One test case used spaces within the URL string in CSS, which the
  net_url2 library represents with percent-encoding instead.
  Same thing either way.

Bug: T88914
Change-Id: Ibef70cc934c0ee8260a244c51bca9fb88c1c0d88
2020-11-05 19:59:02 +00:00
Thiemo Kreuz
b0130ca649 Update a lot of unspecific "array" types in PHPDocs
This includes fixing some mistakes, as well as removing
redundant text that doesn't add new information, either because
it literally repeats what the code already says, or is actually
duplicated.

Change-Id: I3a8dd8ce57192deda8916cc444c87d7ab1a36515
2020-10-28 11:01:33 +01:00
Thiemo Kreuz
1fc8d79ac6 Remove documentation that literally repeats the code
For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.

Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.

Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
2020-10-27 19:20:26 +00:00
Timo Tijhof
0c01d8cc52 resourceloader: Add skin-based 'mediawiki.skin.variables.less' import
Add the SkinLessImportPaths attribute for skin-specific LESS import
paths, which skins can use to override the mediawiki.skin.variables.less
file.

As a starting point, add the following 5 variables:

* device widths (3x)
  To help phase out 'mediawiki.ui/variables'. These are
  commonly used by MobileFrontend.

* @font-family-sans
  Recommended by Volker. Used by multiple skins.

* @border-radius-base
  Recommended by Volker as example of something that we currently
  hardcode in MediaWiki core for Vector and OOUI/WikimediaUI
  in 'mediawiki.widgets.datetime' but should instead be allowed
  to vary by skin and OOUI theme.

  Remove the hardcoded value for '@border-radius-base' in
  various places in favour of importing from mediawiki.skin.
  The default is a bare default of 0 (as border-radius is off
  by default in the browser).

  The value for Vector is restored there by I47da304667811.
  The value for MonoBook is improved by I000f319ab31b.

Bug: T112747
Change-Id: Icf86c930a3b5524254bb549624737d3b9dccb032
2020-09-15 10:05:53 +00:00
Ammar Abdulhamid
ca1224dc44 Deprecate Skin methods moved to SkinFactory
* Skin::getAllowedSkins
* Skin::getSkinNames

Both are hard-deprecated and their equivalents in
SkinFactory should be used instead.

Bug: T257993
Depends-On: Ib8e4ec28f6755abec7e33476efefa78dcc2c6b78
Depends-On: Icc945ce1e3287a3b25152702818e5b2a90232677
Change-Id: I9595248ae5410361a5db50d1b95df1e513ac5a2c
2020-08-26 12:45:52 -07:00
Aaron Schulz
5e0fa6ecc8 resourceloader: store relative paths in less compilation cache
Bug: T253055
Change-Id: Iac911eaeaf26ff8b85642dbc908a8a1e08d0d234
2020-07-21 14:33:59 -07:00
jenkins-bot
b2ce2db332 Merge "resourceloader: Add some typehints and misc clean up" 2020-07-02 03:02:02 +00: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
Umherirrender
bc5cb7ae64 phan: Enable redundant_condition_detection
Remove duplicate casts
Suppress false positives

Bug: T248438
Change-Id: I2f89664a4bcd3b39b15e7cf850adda2f0c90ae6f
2020-07-01 20:13:07 +00:00
Roan Kattouw
8c6c1c9adc VueComponentParser: Use RemexHtml instead of PHP's HTML parser
This fixes an issue with HTML tags inside the <script> tag.
Remex also doesn't throw errors on attributes like @click, although it
does mangle them when producing DOM. To work around this, don't use DOM
serialization for the template HTML, but parse everything again using a
Remex parse+serialize pipeline that extracts the template and
(optionally) removes comments and strips whitespace.

One important effect of this change is that we'll have to forbid
self-closing tags in Vue templates, because Remex doesn't handle those
correctly (or rather, handles them *too* correctly). But on the up side,
we can now allow shorthands for v-bind/v-on/v-slot again.

Bug: T253334
Bug: T255587
Depends-On: I2253a2317187fe0d781ba5bfefab95e0f97d0a80
Change-Id: Id9a9728b7163601cc60bc587be07b70977d41970
2020-06-22 19:54:15 +00:00
Timo Tijhof
d7e2a20785 resourceloader: Improve packageFiles/skinScripts error message
The uppercase spelling would I think be confusing, as the actual
options are lowercase, which should be quoted when referred to
in natural language.

Bug: T251957
Change-Id: Ib97a2bc790799990f3e4b622b20636965a93fca1
2020-06-11 23:22:21 +01:00
Vas Jaremchuk
323b5968e7 resourceloader: skinScripts cannot be used alongside packageFiles
The new exception was added in ResourceLoaderFileModule.php that
packageFiles and skinScripts are incompatible.

Bug: T251957
Change-Id: Id51763b9049b9b2041c4c1c47575d1a6cb3452b0
2020-06-11 20:29:40 +00:00
Holger Knust
50b62c49bf resourceloader: Add more $wgResourceModules documentation
Added documentation markup for $wgResourceModules in DefaultSettings.php
and added a reference to it in ResourceLoaderFileModule.php.

Bug:  T232566
Change-Id: Ib4c0bd55cc2a06f48ef36ceb069906f1d3a22826
2020-03-26 21:41:09 +00:00
Roan Kattouw
ca46126e98 resourceloader: Support single-file component .vue files
Allows .vue files to be used in package modules as if they were .js
files: they can be added to the 'packageFiles' array in module
definitions, and require()d from JS files.

In the load.php output, each .vue file is transformed to a function that
contains the JS from the <script> tag, then a line that sets
module.exports.template to the contents of the <template> tag (encoded
as a string). The contents of the <style> tag are added to the module's
styles.

Internally, the type of a .vue file is inferred as 'script-vue', and the
file is parsed with VueComponentParser, which extracts the three parts.
After the transformation, the file's type is set to 'script+style', and
files of this type contribute to both getScript() and getStyles().

This change also adds caching to getPackageFiles(), because it now needs
to be called twice (in getScript() and getStyles()).

Change-Id: Ic0a5c771901450a518eb7d24456053956507e1ed
2020-03-12 14:32:41 -07:00
James D. Forrester
43939abbf7 resourceloader: Error in FileModule if provided path is a directory
Pre-PHP74, these would silently return false; now they throw an error.

Bug: T233012
Change-Id: I9bcb98fa1189c3d59a67a054c5b807d1495d82bb
2020-03-12 01:32:18 +00:00
James D. Forrester
8595db5546 resourceloader: Factor out file loading in ResourceLoaderFileModule
This file had six different almost-identical calls to the system
call file_get_contents(), which makes it hard to fix all nine of
them neatly.

Change-Id: I607f3cd3dbfa0f47f8d9766a27e581fdc127a0cf
2020-03-12 01:31:32 +00:00
Timo Tijhof
007a0620db resourceloader: Convert mediawiki.Uri to package files
This replaces the client-side compiler for 'mediawiki.template.regexp',
with a simple PHP callback.

The regexp temple compiler is not used anywhere after this and will be
removed in a follow-up commit.

Bug: T233676
Change-Id: I1baa1465d88293d03975cadf2efdd57283427722
2020-02-24 17:45:31 +00:00
Aaron Schulz
5282a02961 resourceloader: support tracking indirect module dependency paths via BagOStuff
This can be enabled via a configuration flag. Otherwise, SqlModuleDependencyStore
will be used in order to keep using the module_deps table.

Create a dependency store class, wrapping BagOStuff, that stores known module
dependencies. Inject it into ResourceLoader and inject the path lists into
ResourceLoaderModule directly and via callback.

Bug: T113916
Change-Id: I6da55e78d5554e30e5df6b4bc45d84817f5bea15
2020-02-13 17:26:36 +00:00
Roan Kattouw
ca7fa28615 resourceloader: Separate style processing from style file loading
ResourceLoaderFileModule::readStyleFile() both reads a style file from
disk and processes it through LESS, CSSJanus and CSSMin. Factor out the
processing part into ResourceLoaderFileModule::processStyle(), which
takes a string of unprocessed CSS/LESS rather than a file. This is
needed for future support for styles that don't come (directly) from a
file, but are generated through packageFiles.

Other changes:
- Use a hash of the source instead of the file name in the cache keys
  for the LESS compilation output
- Also prefix the cache key with 'resourceloader' while we're changing
  it anyway
- LESS compilation no longer adds the source file itself as a dependency
- Don't pass down $flip, just use $this>getFlip()

Change-Id: I86e880d06af724f0fbae93e042c85e0395771912
2020-02-12 20:23:24 +00:00
jenkins-bot
8db5a0d27c Merge "resourceloader: Allow packageFiles callbacks to return a file" 2020-01-20 22:07:51 +00:00
Roan Kattouw
2890bca27d resourceloader: Allow packageFiles callbacks to return a file
If a callback for a virtual file returns a ResourceLoaderFilePath
object, we will load that file from disk and use it in that file's
place. This enables us to port modules that use languageScripts or
skinScripts, by writing a virtual file callback that returns a
ResourceLoaderFilePath pointing to different files depending on the
language/skin.

This also makes the base path parameters to the ResourceLoaderFilePath
constructor optional. Callbacks would construct a ResourceLoaderFilePath
with only one parameter (the file path, but no base paths), and the
RL infrastructure ignores the object's base paths anyway, in favor of
the module's base paths.

Bug: T239371
Change-Id: I8e24f667b4e1944c20f3354a9f7382d5c486055e
2019-12-17 14:23:43 +01:00
Timo Tijhof
6bf01cfaa3 resourceloader: Use FileContentsHasher batching in FileModule::getFileHashes
Instead of hashing each file separately, hash them in a batch.
Previous research on this area of code has identified the suppressing
and restoring of warnings to have a measurable cost, which is why
this was optimised in 3621ad0f82. However, we never really made
use if it (aisde from the 2:1 change in that commit itself), because
we always call it with a single item, turn it into an array, do the
hash and then merge it again.

Instead, we now let it handle a single module's set of files all
at once. Given that this no longer exposes an array of hashes,
also update the (private) signature of getFileHashes to reflect this.

This means all file modules will have their version bumped during the
next MediaWiki release. In general this happens for most releases
and weekly branches already (due to localisation update, general
maintenance, linting changes, and other internal changes). But,
noting here for future reference as this might not be obvious from
the diff.

Change-Id: I4e141a0f5a5c1c1972e2ba33d4b7be6e64ed6ab6
2019-12-17 11:56:22 +00:00
Timo Tijhof
b18fe40fcc resourceloader: Various optimisations in FileModule::getFileHashes()
* Use LanguageFallback::getAll directly instead of the
  deprecated wrapper Language::getFallbacksFor.

* For the loop over package files, use foreach instead of the slower array_map.
  Also incorporate a simple simple isset() check in that foreach loop,
  instead of iterating the values a second time with array_filter.
  This also makes the check more explicit (we discard values that have
  'filePath' unset or set to null), previously array_filter rejected any
  value that could indirectly cast to boolean false.

* For the safeFileHash loop, also use foreach with assignments instead
  of the slower array_map. As a side-effect this now makes explicit that
  we don't preserve array keys (assignments use []= to push).
  This means we can remove the array_values() call, which previously performed
  yet another loop and transformation on our array.

Bug: T233059
Change-Id: I3fe9f0a9ddcce8870ac02986193022a12ecc1606
2019-12-17 12:53:39 +01:00
Timo Tijhof
9c0dee3965 resourceloader: Use ConvertibleTimestamp and Logger directly
Avoid use of wfTimestamp and wfDebugLog global functions.

Also simplify some of the error messages around processing of
'packageFiles' definitions and throw generic LogicException
instead of MWException.

Change-Id: I55ce1f107f53dfdfe673cbe4411b0a7c4e24b2ea
2019-12-04 16:24:40 -08:00
Bartosz Dziewoński
d50c7f5b56 extension.schema.v2: Fix schemas for 'packageFiles'
The PHP code handling 'packageFiles' looks like it only expects
numeric arrays, and not associative arrays. Therefore in JSON the
value for the 'packageFiles' key should be arrays and not objects.
(And a special case of a string, handled the same as single-element
array, is also accepted.)

Individual items in the array can be not only strings, but also
objects, describing data which is pulled from other sources than a
file.

* ResourceLoaderFileModule: Remove unused variable and tweak docs.

Change-Id: I6c3d186de1877f73d4a4e3fec7d6d632a5d5fa83
2019-10-24 22:30:10 +02:00
jenkins-bot
23dfdf865f Merge "Fix new phan errors, part 7" 2019-10-21 23:00:40 +00:00
Daimona Eaytoy
b1a5367ec8 Fix new phan errors, part 7
Bug: T231636
Change-Id: Ia5e0abee7163c5a1abd0bb53b89603cc2e7a9b5c
2019-10-21 22:10:20 +00:00
Andrew Otto
e35f53316c resourceloader: Support passing extra arguments to packageFiles callback
Currently packageFiles callbacks take 2 parameters, $context and $config.
This patch allows for specifying an extra parameter in the packageFiles
definition that will be passed to the callback.  Example:

  'callback' => function ( $context, $config, $extra ) { ... },
  'callbackParam => [ 'this is val 1', 'this is val 2' ],

The callback will be called with the usual $context and $config
parameters, and the extra array is passed as third parameter.

Bug: T233634
Change-Id: Ie11874665f4f9a557d4e394dcab3a972887e8126
2019-10-21 15:07:53 -04:00
Fomafix
a9823d16f6 resourceloader: Add array type hints
Change-Id: I4844eae68e85adc46e52646ea066b459bbabdcce
2019-10-05 15:26:56 +00:00
jenkins-bot
5155abe0e6 Merge "resourceloader: Add $context to static functions in ResourceLoader" 2019-09-27 20:48:15 +00:00
Fomafix
2fc229116d resourceloader: Add $context to static functions in ResourceLoader
This change allows to use the context in the functions.

The following internal static functions from ResourceLoader get now a
reference to the ResourceLoaderContext object:
* makeLoaderImplementScript
* makeLoaderStateScript
* makeLoaderRegisterScript
* makeLoaderSourcesScript

ResouceLoader::encodeJsonForScript is duplicated to
ResourceLoaderContext::encodeJson loading the debug mode from context.

ResourceLoader::encodeJsonForScript is kept for other usages without
context.

The debug mode is loaded from $context->getDebug() instead of from
ResourceLoader::inDebugMode(). This does not support to enable the debug
mode by setting the cookie 'resourceLoaderDebug' or the configuration
variable wgResourceLoaderDebug. Only the URL parameter debug=true
enables the debug mode. This should be sufficient for the subsequent
ResourceLoader requests. The tests don't need the global variable
wgResourceLoaderDebug anymore. The initial ResourceLoader context in
OutputPage still uses ResourceLoader::inDebugMode() with cookie and
global configuration variable.

This change adds the parameter $context with a ResourceLoaderContext
object to ResourceLoaderModule::getDeprecationInformation and deprecates
omitting the parameter. Ifa1a3bb56b731b83864022a358916c6aca5d7c10
updates this in extension ExtJSBase.

Bug: T229311
Change-Id: I5341f18625209446a6d006f60244990f65530319
2019-09-27 18:35:55 +02:00
Fomafix
69981b6476 resourceloader: Add type hints for type ResourceLoaderContext
Change-Id: I10fc4b9277f94fc495149fe0d0077b054090387b
2019-09-27 06:43:44 +02: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