Commit graph

65 commits

Author SHA1 Message Date
Timo Tijhof
d6dd6e4d72 resourceloader: Remove use of object registering in test suites
This was done as a "clever" shortcut to make sure tests a little
but shorter, but also made them less consistent with normal code.

Remove this in favour of 'class' or 'factory' options as needed.
Also remove a bunch of unneeded register() calls.

The tests cover everything affected by this change.

Side fix - isFileModule should reject modules with 'factory'
the same way it rejected raw objects and non-FileModule 'class'
cases already. This is now covered by tests as well.

Bug: T222637
Change-Id: I3996317dbcd780cc6e0f82c84e769c08a3fc42bb
2019-07-12 01:17:44 +00:00
Timo Tijhof
c554ee8e64 resourceloader: Remove support for raw modules
Being a raw module means that when it is requested from load.php with
"only=scripts" set, then the output is *not* wrapped in an
'mw.loader.implement' closure *and* there no 'mw.loader.state()' appendix.
Instead, it is served "raw".

Before 2018, the modules 'mediawiki' and 'jquery' were raw modules.
They were needed before the client could define 'mw.loader.implement', and
could never be valid dependencies. Module 'mediawiki' merged to 'startup',
and 'jquery' became a regular module (T192623). Based on the architecture
of modules being deliverable bundles, it doesn't make sense for there to
ever be raw modules again. Anything that 'startup' needs should be bundled
with it. Anything else is a regular module.

On top of that, we never actually needed this feature because specifying
the 'only=scripts' and 'raw=1' parameters does the same thing.

The only special bit about marking modules (not requests) as "raw" was that
it allowed the client to forget to specify "raw=1" and the server would
automatically omit the 'mw.loader.state()' appendix based on whether the
module is marked as raw. As of Ie4564ec8e26ad53f2, the two remaining use
cases for raw responses now specify the 'raw=1' request parameter, and we
can get rid of the "raw module" feature and all the complexity around it.

== Startup module

In the startup module there was an interesting use of isRaw() that has
little to do with the above. The "ATTENTION" warning there applies to the
startup module only, not raw modules in general. This is now fixed by
explicitly checking for StartupModule.

Above that warning, it talked about saving bytes, which was an optimisation
given that "raw" modules don't communicate with mw.loader, they also don't
need to be registered there because even if mw.loader would try to load
them, the server would never inform mw.loader about the module having
arrived. There are now no longer any such modules.

Bug: T201483
Change-Id: I8839036e7b2b76919b6cd3aa42ccfde4d1247899
2019-06-27 00:08:14 +00:00
jenkins-bot
d1401ab5f1 Merge "resourceloader: Add explicit tests for isValidModuleName()" 2019-06-10 23:44:07 +00:00
Timo Tijhof
c9318edc2d resourceloader: Warn on ResourceLoader::construct without Config
The only remaining use of 'new ResourceLoader' is in tests, which have
been migrated in this commit to either passing the real config explicitly
(for integration tests), or by passing a HashConfig from a new
'getMinimalConfig' method which has only the keys required for the tests
to pass (e.g. avoid any ConfigExeption for unknown keys).

Also clean up some related code quality issues:

* Migrate wfScript() to $conf->get() so that the local Config is used,
  instead of implicitly using global variables. This isn't deprecated for
  MediaWiki generally, but done here to prepare ResourceLoader for becoming
  a standalone library.

* Remove mocking of 'CacheEpoch' config, this is no longer used anywhere
  in ResourceLoader.

* Change EmptyResourceLoader to use the minimal config by default and
  remove code duplication by calling the parent.

  Update the small number of uses that are integration tests, to explicitly
  pass in the live config as needed. And for the one case that tests the
  'startup' module, it no longer needs to register it manually given this
  is part of ResourceLoader::__construct() by default.

Bug: T32956
Change-Id: I127346fd530fa66f205156e545758b1c29d0fac0
2019-06-10 15:24:45 +00:00
Timo Tijhof
ff03ae3043 resourceloader: Add explicit tests for isValidModuleName()
Mark the two basic integration tests as `@medium`.
These confirm that:
* The registration method throws on invalid names.
* The higher levels are able to support an empty string as name.

Change-Id: Ib8215408a28040986ae07f4b2421681bc885abad
2019-06-01 22:46:40 +00:00
Timo Tijhof
a259a2ed0d resourceloader: Move remaining module registrations to ServiceWiring
Also restore the order of registrations as it was before
last week with 47422fabe2. (That is, core modules are registered
before extension modules, in case of conflicts with a warning, the
core one wins).

Bug: T32956
Change-Id: I3a50508178159dfc8e5db1e218a5e6d10e2d4b2a
2019-04-17 19:01:29 +00:00
Timo Tijhof
f2bf73a4c4 resourceloader: Move expandModuleNames() to ResourceLoader.php
This has always been an odd case, as indicicated by the cross-class
comment references, and the fact that its test cases are already
in ResourceLoaderTest.php, for convenience, as that's also where
the creation of 'module name strings' is done and tested.

Actually move it there instead of pretending it is there.

Change-Id: Ied9569436cc78704a5c1b75eeebb73f8631350f6
2019-04-11 21:06:53 +00:00
Timo Tijhof
5c90f8d137 resourceloader: Move registering of custom sources to ServiceWiring
Remove the now-redundant mocking of this configuration from various
test classes.

Bug: T32956
Change-Id: If90a10a76b8289c4ba707382ac915441c17d831f
2019-03-29 01:46:34 +00:00
Timo Tijhof
9a4a754231 resourceloader: Replace ResourceLoaderDebug config use with context
Reduce our reliance on static state and configuration, and
propagate more state in explicit ways, through context, and
request parameters.

OutputPage creates ResourceLoaderContext and ResourceLoaderClientHtml
based on the configuration (via ResourceLoader::inDebugMode).

Everything within those classes should not need to check it
again.

* ResourceLoaderClientHtml:
  Already doesn't check MW config, but it's test was still
  mocking it. Removed now, and confirmed that it passes both
  with true and false. The individual test cases set
  debug=true/false as needed already.

  It's sets were previously relying on the accidental behaviour
  that within a unit test, we don't serialise over HTTP, which
  meant that a pure PHP boolean would survive. With the new
  raw `=== 'true'` check, this no longer works. Set it as a
  string explicitly instead, which is the only thing we support
  outside unit tests as well.

* ResourceLoaderContext:
  Remove fallback to MW config when 'debug' is unset.
  This is never unset in practice given that all load.php
  urls have it set by OutputPage based on ResourceLoader::inDebugMode.

  This change means that manually constructed ad-hoc load.php
  urls that are missing 'debug=' parameter, will now always be
  read as debug=false. This was the default already, but could
  previously be changed through wgResourceLoaderDebug.

When changing wgResourceLoaderDebug, everything will still have
debug=true as before. The only change is when constructing load.php
urls manually and explicitly not set it.

Bug: T32956
Change-Id: Ie3424be46e2b8311968f3068ca08ba6a1139224a
2019-03-08 20:33:16 +00:00
Roan Kattouw
1c7c9bdf1f Use packageFiles feature to replace special-purpose RL modules
For config vars, add a virtual package file called 'config.js', and use
require( './config.js' ) in the module. For most data modules, add a
virtual package file called 'data.js', use require( './data.js' ) in the
module. Where needed, add wrapper files that put the data in the
relevant global object and in module.exports.

LanguageDataModule is the only special-purpose module not being removed
in this commit, because it uses languageScripts, and those are not
compatible with packageFiles (yet).

Also merge mediawiki.ForeignStructuredUpload.config into
mediawiki.ForeignStructuredUpload, since that was the only thing that
used it.

Change-Id: I203d4e3ecdeeeb16729eba2dcf40d11a41d2e582
2019-02-09 00:10:48 +00:00
Roan Kattouw
fbbd65d2df ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.

Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.

The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.

The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.

Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
  XmlJsCode objects into one larger XmlJsCode object. This is needed for
  encoding the packageFiles parameter in mw.loader.implement() calls.

Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2019-02-05 22:05:02 +00:00
Thiemo Kreuz
c3dfa88966 Add missing empty lines between methods
This might hint at an edge-case in the PHP CodeSniffer sniff that should
detect if methods are separated by a single empty line. Feel free to
investigate. I, personally, can't invest more time in this than
suggesting this quick fix.

Change-Id: Ib3c60eac76f255b4fe929f7933de256222716576
2019-01-15 19:14:35 +00:00
Timo Tijhof
0a5757cda8 resourceloader: Make ResourceLoader::makeLoaderRegisterScript() internal
* There is only a single non-test caller to this method in the entire
  codebase, and no callers elsewhere (Wikimedia Git, Codesearch).

  It's only used with an array, so remove the other unused code paths,
  and mark it internal (to my knowledge, nothing ever used it outside
  RL in the past, either).

* Add test coverage for the module indexing logic.

Change-Id: I9e0f95416d5b2fdd87323288231ee6d8c85d88e7
2018-09-18 00:53:42 +01:00
Timo Tijhof
4b069cdc1e resourceloader: Remove closure around $CODE.defineLoader()
Follows-up b7b84d55d4, which embedded the whole of the three 'mediawiki'
JS files inside of startup.js, but did so inside of the pre-existing
closure that was there.

This adds some overhead we don't get value of, so best to remove
it and embed it as a sibling of startup.js in the same top-level
scope.

In local testing (Chrome stable, CPU 1/6th) this reduced startup
run-time from 73-78ms to 63-65ms.

Also:
* Declare isCompatible() as a normal function.
  Disable the implicit-globals warning given this isn't a regular module,
  this file is  intentionally in the global scope.
* Unfold the private startUp() function to its call site.

Change-Id: Ida51ab20898c9e4ae6cbf7ad2968d88d824a1483
2018-09-08 22:45:03 +01:00
Timo Tijhof
f3641c0a9c resourceloader: Remove support for addSource(id, url)
The PHP interface still supports it without deprecation, but there
is no need for the client to support it given it is only ever called
from the startup module, which always passes it an object.

Follows-up 6815e35575, which did the same for `state(key, val)`.

Also simplify the implementation to avoid extra calls and optimise
for the only signature.

Mark the method as @private, and change the existing use of
@protected to @private (doesn't really make sense in JavaScript).

Change-Id: I24786f90bcfb256b2e7c37f7760bba1a5e399443
2018-09-08 22:45:03 +01:00
Timo Tijhof
ca510f742f resourceloader: Remove $wgResourceLoaderLESSVars support
The use of global variables was deprecated in favour of
ResourceLoaderModule::getLessVars() on a per-module basis.

Also moved testLessFileCompilation case to the appropiate file as it
covers ResourceLoaderFileModule.php, not ResourceLoader.php.

Bug: T140804
Depends-On: Ib1b2808df2384473bfac47f53a5d25d7c9bbca2b
Depends-On: I96047f69d01c4736306df2719267e6347daf556f
Change-Id: If708087c85c80355c7e78f1768529b5f2e16ed07
2018-08-14 18:57:45 +00:00
Timo Tijhof
5f8a94a0b3 resourceloader: Improve coverage of ResourceLoader::respond()
- Cover case of simple module load.
  The bulk of this use case is already covered by a lower-level
  test for makeModuleResponse(). The added case here exists
  to cover the wrapper method, ResourceLoader::respond().

- Cover logic for catching and logging internal errors.

Change-Id: I4315bb00137ff80ee2b790c6b4d4b5fbd93f6bc1
2018-05-30 18:30:42 +01:00
Timo Tijhof
eaf40e6dd5 Remove deprecated wgResourceLoaderLESSImportPaths
The last remaining users of this feature were MobileFrontend and Minerva,
which have been migrated to direct imports.

Bug: T140807
Change-Id: I1a66a2ad314bde332297798520e5ec3e0e3d4c9b
2018-05-29 15:49:28 +01:00
Timo Tijhof
af340d58b7 resourceloader: Add coverage for empty case in makeModuleResponse
Adds coverage for line 1049-1056.

Also, follow-up 6292d54dff by simpliying the regex by using /s modifier to
enable PCRE_DOTALL which includes matching of new lines.

Change-Id: Icec34dfe107d418951b3d155234295c79410ffaa
2018-05-29 03:05:41 +01:00
jenkins-bot
474daae531 Merge "resourceloader: Include global LESS variables in LESS cache key" 2018-05-28 11:36:32 +00:00
Timo Tijhof
6292d54dff resourceloader: Add coverage for non-js error case in makeModuleResponse
Adds coverage for line 1170-1175.

Change-Id: I2208264d3fca306b2740b243d7cdc209b224ebca
2018-05-28 00:48:40 +00:00
Alexia E. Smith
8a1da0a43b resourceloader: Include global LESS variables in LESS cache key
This prevents cache churn when the wiki-global LESS variables vary
between wikis because the cache key is used as a "global" instead of
db-local. This is good for the common case, but should still explicitly
vary if the vars differ between wikis.

Bug: T191937
Change-Id: If12fd07a7062792205384150d6f5fd9a83f996cc
2018-05-25 18:13:10 +00:00
Timo Tijhof
f4d1039a20 resourceloader: Add test case for ResourceLoader::getLessCompiler
This was previously covered implicitly by an unrelated test.
Change that test (dependency.less) to use ../ to access the file
directly so that that test case is only about tracking dependencies
and testing the parser.

Then, add a second case that tests the use of import dirs.

Bug: T140807
Change-Id: Ie85abffe313922c03b3e146422f36b1d6a79743d
2018-05-19 23:06:54 +00:00
Timo Tijhof
94f71346e8 resourceloader: Improve test coverage of ResourceLoader::register()
Verify that calling register() twice does not throw, but warns,
and that the last registration wins.

This behaviour was actually surprising to me because it used to
throw, and I'd assume that when we added the warning, the behaviour
would go from fatal to non-fatal, but keep that the last one is
at fault/unsupported.

Perhaps b1ea0612 / d3e3bcfd6 (T116628) should've added a return
statement. Oh well, we can consider changing that later, but at
least test for it.

Change-Id: I955132868146ea5bf88c9b9e648c84d8196cb1f9
2018-05-04 02:15:24 +01:00
Timo Tijhof
870d3a6532 resourceloader: Simplify load.mock.php by removing includes dependency
It previously depended on Xml.php for Xml::encodeJsCall, which
in turn depends on FormatJson. Other Xml.php methods also depend
on Sanitizer, but that was carefully not triggered.

Avoid both of these by simply constructing the string inline,
and using json_encode() directly for the one variable parameter.

Also, fix the names of one of the ResourceLoaderTest cases for
dotless module names. It claims to have been added to cover a
regression fixed in r88706, but that commit seems rather unrelated.
A bit of searching revealed as the relevant commit instead.

Bug: T188076
Change-Id: I04851d0355227f3a6b79b8d41a51d4beadce0e80
2018-03-06 15:59:13 -08:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Timo Tijhof
b0910b7176 resourceloader: Introduce metric for backend response timing
We currently have several counts and timings of individual pieces
of ResourceLoader backend logic (minification, module building, ..)
but no measure of the response overall.

This responseTime metric will effectively provide both a timing
measure as well as a backend request count.

Bug: T178350
Change-Id: I625a5eb90f5a4ea90aebf9292dfda0f1c5ae4f2e
2017-10-17 04:02:59 +01:00
Timo Tijhof
3d342d4deb resourceloader: Add support for modules sending preload headers
ResourceLoaderModule objects gain a new method getPreloadLinks() which
returns an array with the meta data required to build a Link rel=preload
header according to the current draft for W3C Preload.
<https://w3c.github.io/preload/>

Another implementation of this is already in use in OutputPage for
preloading the logo image.

This array is formatted by the ResourceLoaderModule::getHeaders method,
which is implemented as "final" at this time, thus restricting use to
the Link rel=preload header.

Headers are exposed and process-cached, like all other content
(scripts, styles, etc.), through ResourceLoaderModule::getModuleContent,
and aggregated by ResoureLoader::makeModuleResponse.

I had hoped for the getPreloadLinks to be stateless (not vary on $context).
Whether something should be preloaded and what, should not vary on the
skin or language. However, while that conceptually holds true, the exact
url for any given resource may still vary. Even the main use case for this
feature (T164299, preloading base modules request) require $context to pass
down skin and lang to the load.php url.

Add full test coverage and example documentation.

Bug: T164299
Change-Id: I2bfe0796ceaa0c82579c501f5b10e931f2175681
2017-08-03 03:57:00 +00:00
Timo Tijhof
e4a52de025 resourceloader: Avoid mw-exception log spam from PHPUnit tests
Bug: T50002
Change-Id: Ida18f271883535eca2a1d26ee34120190914d87a
2017-07-15 00:37:53 +00:00
Timo Tijhof
483f13b226 resourceloader: Use "\n" instead of ";" as separator for scripts
This fixes two bugs:

* 1) When two modules are requested, and the first one ends with ";"
     inside a comment, the second module might become part of
     that comment.
* 2) A request with script=only where the requested module content
     ends in a statement without ";", but has a comment after it
     that does ends with a semicolon, then in debug=false, mw.loader.state()
     would be appended directly after the semicolon-less statement because
     the check is performed before minification.
     Previously:
     script> foo()
     script> // bar();
     states> mw.loader.state( {} );
     Became (minified separately):
     script> foo()
     states> mw.loader.state({});
     Became (concatenated)
     > foo()mw.loader.state();
     Which is invalid code.

Both of these are now fixed.

Bug: T162719
Change-Id: Ic8114c46ce232f5869400eaa40d3027003550533
2017-06-28 03:59:05 +00:00
Timo Tijhof
39eda6770e resourceloader: Add more concat test cases for makeModuleResponse
Bug: T162719
Change-Id: Ic8d4a022dbe8c7998924fb20d727936e68cb11d2
2017-06-27 19:10:03 -07:00
jenkins-bot
cb3ae02172 Merge "resourceloader: Add @covers for stripBom and makeModuleResponse tests" 2017-06-27 13:18:10 +00:00
Timo Tijhof
580dbeba7a resourceloader: Add @covers for stripBom and makeModuleResponse tests
Change-Id: Ie32178cdd03a79a0ab871122acf081c65e5a9f4d
2017-06-26 22:15:06 -07:00
Umherirrender
be42e09aa8 build: Prepare for mediawiki/mediawiki-codesniffer to 0.9.0
The used phpcs has a bug, so the version 0.9.0 could not be enforced at the moment.
Will be fixed in next version, see T167168

Changed:
- Remove duplicate newline at end of file
- Add space between function and ( for closures
- and -> &&, or -> ||

Change-Id: I4172fb08861729bccd55aecbd07e029e2638d311
2017-06-26 17:14:31 +00:00
Timo Tijhof
84074e856d resourceloader: Add unit tests for ResourceLoader::isFileModule
Change-Id: Ic21ae9e9cc418868ad7b93fe65bd09495f38d1b2
2017-06-21 19:48:34 +00:00
daniel
2b3762ecb4 resourceloader: Allow modules to be registered via a factory callback
This should work the same way as registering API modules via a factory callback.
Point in case: Ifb8611473a971 could avoid global state using this mechanism.

Change-Id: Ifbf29006141ce2a2dff42efa352f406502a06bc6
2017-05-21 17:12:37 +00:00
Gergő Tisza
525bfbc8df Switch to librarized version of TestingAccessWrapper
Replaces \TestingAccessWrapper (defined in core) with
\Wikimedia\TestingAccessWrapper (defined in the composer package
wikimedia/testing-access-wrapper).

See https://gerrit.wikimedia.org/r/#/q/topic:librarize-testing-access-wrapper
for downstream patches.

The core version of the class is kept around for a while to avoid
circular dependency problems.

Bug: T163434
Change-Id: I52cc257e593da3d6c3b01a909e554a950225aec8
2017-04-20 14:15:57 +00:00
Timo Tijhof
16adb3fe31 resourceloader: Improve code coverage
* Missing cases for StartupModule::getModuleRegistrations
  (now 100% covered)
  - Raw modules are omitted from the manifest.
    E.g. The base modules ('jquery', 'mediawiki') are raw modules
    that we don't register client side (they can't load themselves).
  - Exceptions from getVersionHash() are caught.
  - Oversized versions are re-hashed.

* Missing cases for ResourceLoader::makeLoaderRegisterScript.
  (now 100% covered)

* Missing cases for ResourceLoader::getModule.
  (now 100% covered)

Change-Id: If9717a48195fc6ae776da5d0e86f323d7f60426d
2017-04-05 18:19:48 -07:00
Timo Tijhof
22b112aeda resourceloader: Fix testMakeModuleResponseError() failure on Travis
> 1) ResourceLoaderTest::testMakeModuleResponseError
> Failed asserting that '[e08c982d974548127cb5d7ce] Fatal exception of type Exception'
> matches PCRE pattern "/Ferry not found/".
> .../ResourceLoaderTest.php:519

This happened on Travis CI, because ResourceLoader::formatException() behaves
differently based on $wgShowExceptionDetails. Which is enabled in Vagrant
and Jenkins, but disabled by default (and thus in Travis CI builds).

Bug: T75176
Change-Id: If15dd03213703b7b6ff899cad5e5569e2515b378
2017-02-22 02:56:30 +00:00
Timo Tijhof
466939c631 resourceloader: Don't let module exception break startup
When getScript (or some other method used in a module response)
throws an error, only that module fails (by outputting mw.loader.state
instead of mw.loader.implement). Other modules will work.

This has always been the case and is working fine. For example,
"load.php?modules=foo|bar", where 'foo' throws, will return:

```js
/* exception message: .. */
mw.loader.implement('bar', ..)
mw.loader.state('foo', 'error')
```

The problem, however, is that during the generation of the startup
module, we iterate over all other modules. In 2011, the
getVersionHash method (then: getModifiedTime) was fairly simple
and unlikely to throw errors.

Nowadays, some modules use enableModuleContentVersion which will
involve the same code path as for regular module responses.

The try/catch in ResourceLoader::makeModuleResponse() suffices
for the case of loading modules other than startup. But when
loading the startup module, and an exception happens in getVersionHash,
then the entire startup response is replaced with an exception comment.

Example case:
* A file not existing for a FileModule subclass that uses
  enableModuleContentVersion.
* A database error from a data module, like CiteDataModule or
  CNChoiceData.

Changes:
* Ensure E-Tag is still useful while an error happens in production
  because we respond with 200 OK and one error isn't the same as
  another.
  Fixed by try/catch in getCombinedVersion.
* Ensure start manifest isn't disrupted by one broken module.
  Fixed by try/catch in StartupModule::getModuleRegistrations().

Tests:
* testMakeModuleResponseError: The case that already worked fined.
* testMakeModuleResponseStartupError: The case fixed in this commit.
* testGetCombinedVersion: The case fixed in this commit for E-Tag.

Bug: T152266
Change-Id: Ice4ede5ea594bf3fa591134bc9382bd9c24e2f39
2016-12-15 23:25:57 +00:00
Timo Tijhof
6f5cb7d42b resourceloader: Add tests to verify empty string works
It's not explicitly supported anywhere, but I don't see a point in explicitly
disallowing it. Add unit tests to verify that this works.

Bug: T28804
Change-Id: I876ac43885bb27da54ef6e59b6416868ff636b84
2016-11-16 17:15:04 -08:00
Timo Tijhof
09e1b91756 resourceloader: Move 'site' and 'user' logic to makeModuleResponse
* Keep this out of makeLoaderImplementScript() to keep it more generic
  and to simplify future refactoring.

* Remove now-broken test case that asserted that the output varies
  by global debug mode.

* Make the test responsible for wrapping in XmlJsCode. Previously
  this magically happened because the module name was "user" in the
  last test case.

* Make makeLoaderImplementScript protected. It's not used anywhere
  outside ResourceLoader and we should keep it that way.

Test plan:
* Verify output unchanged:
  - load.php?modules=user&only=scripts&user=Admin (raw code)
  - load.php?modules=user&user=Admin (implement with unwrapped string)
  - load.php?modules=jquery.client (implement with closure)

Change-Id: I527d01926fb6e4ce68c931695d830cdb9ceb608c
2016-09-15 18:32:07 -07:00
Timo Tijhof
c4e5cc2957 resourceloader: Create unit tests for ResourceLoaderContext
* Fix up one last use of global config vars in this class.
  Other places in this class already used $rl->getConfig().
  This way we don't inherit all of MediaWikiTestCase.

* Add unit tests covering all of ResourceLoaderContext
  except expandModuleNames and getImageObj (tested in better
  places already with the right @covers).

* Increase coverage for expandModuleNames(), add missing case
  of when modules are not in alphabetical order.

Change-Id: Id19b084d37a6c3a77b36e03509adffb6b156fee1
2016-08-29 16:47:15 -07:00
Timo Tijhof
7dbad8562c resourceloader: Improve coverage in ResourceLoaderTest.php
* Fix signature of makeLoaderSourcesScript() to match
  the change in behaviour since e103ba265.

* Consistently order providers before the test.

* Simplify testRegisterValid() and remove needless @depends.

* Remove unused private method stripNoflip().

Coverage:

* Expand test coverage for register().

* Add tests for getModuleNames().

* Add tests for getModule().

* Expand test coverage for addSource().
  (case of invalid array)

* Expand test coverage for makeLoaderImplementScript().
  (case of unwrapped user script, and case of invalid scripts)

* Add tests for makeLoaderSourcesScript().

Change-Id: Ibca3e486fcd3664f171f135327a0f340ee6da9ee
2016-08-24 18:56:20 -07:00
jdlrobson
bc4e07b6f6 resourceloader: Implement modern module loading (2/2)
* Send 'module' and 'require' parameters to module closures.
  This depends on Ia925844cc22f143 being deployed one cycle earlier.
* Patch Moment and OOjs to ensure these libraries continue to expose
  their module as globals as well. AMD/UMD-compatible libraries
  only expose a global *OR* an export, not both. We need both
  for back-compat.
* Update pluralRuleParser to make use of module export to allow
  usage via require().

To test, check out the patch and run:
> mw.loader.load('moment');
> mw.loader.require('moment')()
> mw.loader.require('moment')('2011-04-01').fromNow()

Bug: T108655
Change-Id: Idbd054880ee70d659ec760aef8fcb38d0704a394
2016-04-13 15:43:41 +00: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
Reedy
0f19a8e771 Remove duplicate array keys from tests
Change-Id: I437b87151be6589a8d5c984b90cd249c2d0ecd3c
2016-02-07 21:22:53 +00:00
Ori Livneh
e176c76da2 resourceloader: Fully remove ResourceLoaderLESSFunctions
Deprecated in 1.24, for reasons explained in a0c41ae39d. I don't see any
usage in core or extensions.

Change-Id: I46f9e04ae633e7ff1ee112b652e1865731172f1f
2015-09-04 01:41:40 +00:00
Vivek Ghaisas
9f5b6f5aeb Fix whitespace issues around parentheses
Fix issues found by MediaWiki.WhiteSpace.SpaceyParenthesis sniff.

Bug: T102617
Change-Id: Iec7f71e64081659fba373ec20d9d2006306a98f4
2015-06-16 22:14:02 +03:00
Timo Tijhof
3cf2f18bb8 resourceloader: Omit empty parameters from mw.loader.implement calls
Follows-up ebeb29723, 1f393b6da, 0e719ce23.

Also:
* Add tests for ResourceLoader::makeLoaderImplementScript().
* Apply ResourceLoader::trimArray to makeLoaderImplementScript (new in c0c221bf).

This commit changes the load.php response to omit empty parameters.

These parameters were required until recently. The client has been
updated (1f393b6da and 0e719ce23) to make these optional, thus supporting
both the old server format and the change this commit makes

Clients with a tab open from before 0e719ce23 are naturally not
compatible with load.php responses from after this commit. Ensure
this is deployed several days after 0e719ce23 to reduce race
conditions of this nature.

(This is a re-submitted version of 4ce0c0da4)

Bug: T88879
Change-Id: I9e998261ee9b0b745e3339bc3493755c0cb04b6a
2015-04-03 07:20:51 +01:00