Commit graph

166 commits

Author SHA1 Message Date
jdlrobson
d146934f94 Add RL template module with HTML markup language
Preparation work for templating in core.
RL should allow us to ship HTML / template markup from server to client.
Use in Special:Upload and mediawiki.feedback as a proof of concept.
Separation of concerns etc...

See Also:
Ia63d6b6868f23a773e4a41daa0036d4bf2cd6724

Change-Id: I6ff38c12897e3164969a1090449e626001926c3b
2014-10-17 09:23:04 -07:00
Timo Tijhof
8c34c8ed5e doxygen: Document problem with slashes and fix a few
Change-Id: I39f8f394e7421fca71e7d26818f7118e85de7e4f
2014-09-23 19:32:13 +00:00
jenkins-bot
09aa7275fa Merge "resourceloader: Condition-wrap the HTML tag instead of JS response" 2014-09-13 13:29:06 +00:00
umherirrender
cc25a96976 Typo: compatability -> compatibility
Change-Id: I533dfc9daff5e11c1732d5d81a54faa9d7b0c43a
2014-09-13 06:32:11 +00:00
Timo Tijhof
9d390a09cd resourceloader: Condition-wrap the HTML tag instead of JS response
Follows-up 9272bc6c47, 03c503da22, 1e063f6078.

One can't wrap arbitrary JavaScript in an if-statement and have
its inner-body mean exactly the same.

Certain statements are only allowed in the top of a scope (such
as hoisted function declarations). These are not allowed inside
a block. They're fine in both global scope and local function
scope, but not inside an if-block of any scope.

The ECMAScript spec only describes what is an allowed token.
Any unexpected token should result in a SyntaxError.

Chrome's implementation (V8) allows function declarations in
blocks and hoists them to *outside* the condition. Firefox's
SpiderMonkey silently ignores the statement. Neither throw a
SyntaxError.

Rgular ResourceLoader responses only contain mw.loader.implement()
and mw.loader.state() call which could be wrapped without issues.
However such responses don't need wrapping as they're only made
by mediawiki.js (in which case mw is obviously loaded). The
wrapping is for legacy scripts that execute in the global scope.

For those, let's wrap the script tag itself (instead of the
response). That seems like the most water-tight and semantically
correct solution.

Had to bring in $isRaw from ResourceLoader.php, else the startup
module would have been wrapped as well (added regression test).

Bug: 69924
Change-Id: Iedda0464f734ba5f7a884726487f6c7e07d444f1
2014-09-09 15:54:16 +00:00
jenkins-bot
d1b6cd35d4 Merge "resourceloader: Only store sources' load.php urls" 2014-09-07 23:10:33 +00:00
Kunal Mehta
e103ba265b resourceloader: Only store sources' load.php urls
Previously ResourceLoader would store any arbitrary data about a
source, provided it had a 'loadScript' key. It would register
the 'local' source with an additional 'apiScript' key, which was
also documented in DefaultSettings.php. However, it was
completely unused outside of the ForeignAPIGadgetRepo class in
Gadgets 2.0, which should be changed to take an API url as a
parameter. This was not useful as it was not ever formally
exposed, and it could not be depended upon that a source had
registered an 'apiScript' key.

For backwards compatability, both ResourceLoader::addSource()
and mw.loader.addSource() will both take an array/object, but
discard all parameters except for 'loadScript'.

Also added tests for ResourceLoader::addSource().

Bug: 69878
Change-Id: I4205cf788cddeec13b619be0c3576197dec1b8bf
2014-09-05 04:38:22 +02:00
Timo Tijhof
37e3d9befa phpcs: Pass ResourceLoader.php
There was only one warning left.

> 1184 | WARNING | Line exceeds 100 characters; contains 107 characters
>      |         | (Generic.Files.LineLength.TooLong)

Change-Id: I99c729e02dac6aaf13a05568fd04e7bb5ad7bcb5
2014-08-26 15:32:21 +02:00
Kunal Mehta
bb03d1a8e0 Turn MessageBlobStore into a singleton instead of static functions
For easier testability and other things. There are no uses
of this class in any extensions in gerrit.

Change-Id: I606de4259239e128ed7e0477fc98b84c647430c4
2014-08-25 03:53:39 -07:00
Timo Tijhof
03c503da22 resourceloader: Only conditional-wrap script responses with only=scripts
Follows-up 9272bc6c47. The shouldIncludeScripts method returns
true for only=scripts, but also for other responses (except for
only=styles, naturally).

Regular load.php responses that load both scripts and styles don't
need the conditional wrap because those requests should only be
made from the mw.loader client which inherently means the
environment has been provided already.

It's merely unnecessary and shouldn't have caused any issues since
it simply evaluates to true always. It was already correctly being
excluded from raw modules that run before the environment is
provided (such as startup, jquery and mediawiki).

Change-Id: I375a7a8039f9b3ad4909e76005725f7d975d8a5e
2014-08-22 01:15:49 +00:00
Bartosz Dziewoński
cd22ba020e Consistently use 'Less' rather than 'LESS' in function names
PHP function names are case-insensitive, so this is a fully
backwards-compatible change.

Change-Id: Ide04ad542ac5c3a26b6064093ae272cf9aeef2d1
2014-08-20 18:48:10 +02:00
umherirrender
c2de24efcd Add missing @param to function docs
Change-Id: Ib7ac94d05a04490f25dfd40b46b27973cbab582c
2014-08-14 19:38:57 +00:00
jenkins-bot
c54bcbc5b9 Merge "resourceloader: Wrap only=script responses in "if(window.mw)"" 2014-08-13 00:50:10 +00:00
Timo Tijhof
9272bc6c47 resourceloader: Wrap only=script responses in "if(window.mw)"
We currently have a few legacy requests to the load.php end point
that bypass the ResourceLoader client by coding a request to
load.php via a "<script src>" directly. Most prominently the
request for the 'site' wiki module (aka MediaWiki:Common.js).

Remove the manual wrapping of embedded private modules as this
is now taken are of by ResourceLoader::makeModuleResponse itself.

Misc:
* Mark "jquery" and "mediawiki" as Raw modules. While the startup
  module had this already, these didn't. Without this, they'd
  get the conditional wrap – which would be a problem since mediawiki.js
  can't be conditional on 'window.mw' for that file defines that
  namespace itself.
* Strip the cache-key comment in the unit tests because the hash
  no longer matches and using the generic 'wiki' dbname was breaking
  DB queries.
* Relates to bug 63587.
* See also 05d0f6fefd which expands the reach of the non-JS
  environment to IE6 and helped expose this bug.

Change-Id: Icf6ede09b51ce212aa70ff6be4b341762ec75b4d
2014-08-12 23:20:42 +00:00
Kunal Mehta
4b1a87c96e includes/resourceloader/: Use Config instead of globals
Change-Id: Iaa1f4ae9c397575c9bb86dacbc342456e6f5f532
2014-08-07 18:47:34 +01:00
jenkins-bot
6f02280988 Merge "Fixed spacing" 2014-08-04 11:13:21 +00:00
umherirrender
473b7d925e Fixed docs
- Use short form of boolean
- Use capital at begin of doc text

Change-Id: Ic5afacfa7298b1938d3b45ffd0cac5ce01f2f9db
2014-08-04 12:00:15 +02:00
umherirrender
861617ca24 Fixed spacing
- Removed spaces around array index
- Changed else if to elseif
- Added space after foreach/if/function
- include_once is not a function

Change-Id: I7745ae791d1b7e60cfebec6d268513a9cc071bdd
2014-08-04 11:51:22 +02:00
Bartosz Dziewoński
3971d0646c resourceloader: Allow skins to provide additional styles for any module
The newly introduced $wgResourceModuleSkinStyles global enables skins to
provide additional stylesheets to existing ResourceLoader module.

This both makes it easier (or at all possible) to override default
styles and lowers the style footprint by making it possible not to
load styles unused on most pages.

----

Example:

Use the file 'foo-styles.css' for the 'mediawiki.foo' module when using
the MySkin skin:

  $wgResourceModuleSkinStyles['myskin'] = array(
    'mediawiki.foo' => 'foo-styles.css',
    'remoteSkinPath' => 'MySkin',
    'localBasePath' => __DIR__,
  );

For detailed documentation, see the doc comment in DefaultSettings.php.
For a practical usage example, see Vector.php.

----

Implementation notes:

* The values defined in $wgResourceModuleSkinStyles are embedded into
  the modules as late as possible (in ResourceLoader::register()).
* Only plain file modules are supported, setting module skin styles
  for other module types has no effect.
* ResourceLoader and ResourceLoaderFileModule now support loading
  files from arbitrary paths to make this possible, defined using
  ResourceLoaderFilePath objects.
  * This required some adjustments in seemingly unrelated places for
    code which didn't handle the paths fully correctly before.
* ResourceLoader and ResourceLoaderFileModule are now a bit more
  tightly coupled than before :(
* Included a tiny example change for the Vector skin, a lot more of
  similar cleanup is possible and planned for the future.
* Many of the non-essential mediawiki.* modules defined in
  Resources.php should be using `'skinStyles' => array( 'default' => … )`
  instead of `'styles' => …` to allow more customizations, this is
  also planned for the future after auditing which ones would actually
  benefit from this.

Change-Id: Ica4ff9696b490e35f60288d7ce1295766c427e87
2014-07-29 00:53:41 +02:00
umherirrender
dd8921c9d9 Cleanup some docs (includes/[m-r])
- Swap "$variable type" to "type $variable"
- Added missing types
- Fixed spacing inside docs
- Makes beginning of @param/@return/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: I8ebfbcea0e2ae2670553822acedde49c1aa7e98d
2014-07-24 19:43:25 +02:00
Kunal Mehta
126fb8d157 OutputPage: Support foreign module sources in makeResourceLoaderLink
To do so, created ResourceLoader::createLoaderURL(), which takes a
ResourceLoaderContext object. ResourceLoader::makeLoaderURL() was
deprecated.

While reviewing usage of the old function, many of the callers only
differed by one or two parameters from their respective
ResourceLoaderContext object. To simplify that use case, I created
DerivativeResourceLoaderContext, based of off DerivativeContext for
IContextSource.

Change-Id: I961c641ab953153057be3e3b8cf6c07435e9a0b0
2014-07-19 23:44:00 +00:00
Timo Tijhof
75c08916b0 resourceloader: Implement "skip function" feature
A module can be registered with a skip function. Such function,
if provided, will be invoked by the client when a module is
queued for loading. If the function returns true, the client will
bypass any further loading action and mark the module as 'ready'.

This can be used to implement a feature test for a module
providing a shim or polyfill.

* Change visibility of method ResourceLoader::filter to public.

So that it can be invoked by ResourceLoaderStartupModule.

* Add option to suppress the cache key report in ResourceLoader::filter.

We usually only call the minifier once on an entire request
reponse (because it's all concatenated javascript or embedded
javascript in various different closures, still valid as one
large script) and only add a little bottom line for the cache
key. When embedding the skip function we have to run the minifier
on them separately as they're output as strings (not actual
functions). These strings are typically quite small and blowing
up the response with loads of cache keys is not desirable in
production.

* Add method to clear the static cache of ResourceLoader::inDebugMode.

Global static state is evil but, as long as we have it, we at
least need to clear it after switching contexts in the test suite.

Also:
* Remove obsolete setting of 'debug=true' in the FauxRequest in
  ResourceLoaderTestCase. It already sets global wgResourceLoaderDebug
  in the setUp() method.

Bug: 66390
Change-Id: I87a0ea888d791ad39f114380c42e2daeca470961
2014-06-12 03:48:26 +02:00
Timo Tijhof
0888ccbcad Installer: Re-use ResourceLoader methods instead of duplicating
Also:
* Fix incorrect documentation comment of ResourceLoaderModule::getStyles(),
  it doesn't return a string, it never has.
* Remove spurious space in count() call.
* Fix spelling of in "proper".

Change-Id: I000393636f7b9015ad1bacfbb3eb8a6ad8695d72
2014-06-07 10:02:55 +02:00
Siebrand Mazeland
0b2fcf3785 Pass phpcs-strict on includes/resourceloader/
Change-Id: I5c63e0612c2aae240abcdbf21da9cdadd80dee31
2014-05-10 10:39:37 +02:00
Timo Tijhof
aae8314279 resourceloader: Report problematic modules in only=styles as well
Similar to how we do with other exceptions that we don't log on
the server but want a client to be able to debug, report modules
that were not included in the response.

Especially when debugging a load.php?only=styles request that
contains lots of different modules., there was no way of knowing
certain modules were excluded (e.g. because they aren't
registered), other than to try and remove them from the request
one by one until you're left with non-zero modules in the request
and an empty string as response body.

This change prepends a comment like the following to the response.

/*
Problematic modules: {
	"foo": "missing"
}
*/

Bug: 64826
Change-Id: If5136c60ff7168dac5d6cdebd487824767c0ec16
2014-05-05 22:37:44 +00:00
umherirrender
dcf6955e5c Fixed some @params documentation (includes/*)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.

Change-Id: Ifbb1da2a6278b0bde2a6f6ce2e7bd383ee3fb28a
2014-04-20 23:33:05 +02:00
Ori Livneh
a2bf2346cd Don't cache $wgResourceLoaderLESSVars in a static
Caching the value of $wgResourceLoaderLESSVars in a static variable that is
enclosed in a closure makes it harder to reset global state for test runs, and
it does so in the name of a performance benefit that is miniscule.

Change-Id: I0958b03818f56ab73c8c9124daa9e54cc59f2428
2014-04-18 12:11:42 -07:00
Ori Livneh
5742c1f385 ResourceLoader::makeLoaderImplementScript: Bind args as '$' and 'jQuery'
Make the function that wraps ResourceLoader modules bind the first and
second arguments it receives to '$' and 'jQuery'. This patch is a
follow-up to change I0c9edac35, which updated the invocation of
mw.loader#implement so that it passes jQuery as the first and second
argument.

Change-Id: I0f0c3a04c3b0e6a28115a10bf11a2a78aca66c21
2014-04-11 18:15:11 +00:00
Timo Tijhof
f039edc7d5 resourceloader: Don't add superfluous line breaks and semicolons
The logic was there but didn't work in practice because, just
like this code does itself, code doesn't usually end in ';'.
Instead it ends in ";\n" (trailing line break at end of file),
or even two line breaks (in case of concatenated scripts where
ResourceLoaderFileModule adds another line break).

This saves off a few bytes that were uselessly added in the
load.php output, like:

	...
	}( jQuery ) );

	;
	/**
	...

After this:

	}( jQuery ) );

	/**

The logic to add ;\n is still there, but the logic to not add it
when there already wasn't working (added in I3e8227ddb).

Change-Id: Ie055b37b3419ac6dca6349daf745bc48850fff3e
2014-04-04 20:13:08 +00:00
Ori Livneh
51581fee86 Callers of ResourceLoader::getModule should check for null return
ResourceLoader::getModule returns null if cannot find a ResourceLoaderModule
instance or a module configuration array matching the requested name. Existing
callers of that method chain ResourceLoaderModule method calls to the return
value of ResourceLoader::getModule without bothering to check for a null
result. This patch makes the documentation for the method more explicit, and it
adds checks for the return value to existing calls of the method. In some
cases, it is possible to reason to that the call will succeed, on the
assumption that missing modules would have been filtered out by earlier
iterations through the modules array. But in the interest of robustness, it is
always good to check.

Bug: 63310
Change-Id: Ic32f1e61ffee0383f7a8761423099041e3b6b8cc
2014-04-03 17:29:53 -07:00
addshore
23ce808b30 Fix phpdoc of class vars in ResourceLoader
Change-Id: Iced0b17d0c964f3d137b6714946577c7d1a24e30
2014-03-07 21:18:06 +00:00
jenkins-bot
38c8edae1b Merge "resourceloader: Consistently pass inDebugMode to encodeJsCall() in load.php" 2014-03-07 19:50:41 +00:00
Timo Tijhof
99a4c31425 resourceloader: Consistently pass inDebugMode to encodeJsCall() in load.php
Still quite a few were being minified unconditinally. This is in
preparation for adding unit tests for the startup module where
it'll make reading the unit tests (and looking at the diff in case
of a failure) a lot easier if the strings aren't minified.

Change-Id: Ia06787e0ce608fcafac4596c980606d06107f517
2014-03-07 19:11:19 +00:00
Timo Tijhof
94ba63be03 doc: Clean up documentation in ResourceLoader.php
Change-Id: I33e47e1bfb7dbff1304e56033c62fb80dfefdcf0
2014-03-07 20:04:26 +01:00
Timo Tijhof
c59ff09be9 qunit: Move modules exclusively for $wgEnableJavaScriptTest to test registry
These modules should only be loaded when $wgEnableJavaScriptTest
is true. Move these modules to the registry that is only activated
in that context and rename the modules to be namespaced under 'test.'
so that there is no mistake when referencing these that they are
not regularly available.

Change-Id: I21e69f50b006904b12fe9f79c196c903ebff4661
2014-02-05 12:32:37 -08:00
MZMcBride
b2576a5404 Expand load.php's "no modules requested" output to be friendlier
Change-Id: I9300ec4d86a364034a70ce4204a0d9c1ac44b60f
2014-01-18 00:11:48 +00:00
umherirrender
073abe3e12 No variable assignment on return statement
Split the variable assignment and the return statement in two lines for
better readability.

When there was two return statements in one method the logic was swapped
to have only one return statement.

Change-Id: Id7a01b4a2df96036435f9e1a9be5678dd124b0af
2014-01-02 09:43:35 +00:00
umherirrender
0bc583af2c Move closing parenthesis from multi line if and function to own line
The Line continuation Coding conventions prefers the closing parenthesis
on the same line than the beginning curly braces. This is done for ifs
and functions.
Also move some boolean operator from the end of a line to the beginning
and changed some indentation to make the condition hopefully better
readable.

Change-Id: Id0437b06bde86eb5a75bc59eefa19e7edb624426
2013-12-01 21:39:00 +01:00
umherirrender
5dbfd5bf80 Fixed spacing
- Removed trailing spaces in comments
- Removed multiple empty lines
- Removed space after object operator

Change-Id: I9fd3256ab490c7cd2034de3fd94e6be6e6d6d8f2
2013-11-21 18:52:25 +00:00
Timo Tijhof
f46f21915a resourceloader: Use state "error" instead of "missing" in case of exceptions
Changes:
* If we catch an exception while making the response for a module, set its
  client state to "error" instead of "missing".
  State "missing" should only be used if the module could not be
  found in the registry.
  This matches the behaviour of the client.

Clean up:
* Merge the two mw.loader.state calls into one.
* Add @throws documentation for compileLESSFile (follows-up cdc8b9e).
* Don't use 3 different ways to assert an array being empty,
  using 1 and sticking to it.
  - !$arr
  - $arr === array()
  - count( $arr )

Change-Id: I54c3de6d836702ffbe3044bc58a38e83e758bc33
2013-11-15 02:32:48 +01:00
MarkAHershberger
22280a1e3b Merge "installer: Run the LESS compiler for *.less files" 2013-10-28 21:39:31 +00:00
Kevin Israel
8cc7208753 installer: Run the LESS compiler for *.less files
Includes the following improvements:

* Use the ResourceLoader module definitions (with a hardcoded list of
  module names) instead of a hardcoded list of filenames.
* Make the errors more discoverable like we do in load.php, prepending
  them instead of burying them in the middle somewhere.

Bug: 55589
Change-Id: Iab78a60209ab46a10d4c492c75527e717f36f803
2013-10-24 01:02:47 -04:00
Tim Starling
d1bc243f65 Remove all instances of the word "iff"
It's elitist mathematical jargon. In all cases dealt with here, it adds
no additional meaning compared to "if", beyond what was already obvious
from context. Thus, its only purpose is to smugly demonstrate that the
author attended their second-year mathematics classes, at the expense of
causing confusion for everyone who doesn't have such a background.

If you really think you need to convey extra information beyond what
"if" gives you, the English language contains plenty of devices for doing
so, without resorting to neologisms.

Change-Id: Iae21095d02ec2935c10e94f532235c2671c115b1
2013-10-23 10:56:54 -07:00
Timo Tijhof
f0386d3183 exception: Move logging logic to static method of MWExceptionHandler
Follows-up c28251a9fd, which unconditionally called logException
on objects that aren't always instances of MWException.

This makes it possible to, for example, log PHP errors or errors
from Less in ResourceLoader to be logged as well (which naturally
don't have a logException method).

As a result of the handling now being generic, non-MWException
errors will now be loggable, and also have their ID fixed between
HTML output and the debug log entry.

* Not yet removing MWException::getLogMessage (introduced in bcb9f9e1c)
  as it has been around since 2006 (released in 1.8.0).

* Not yet removing MWException::getLogId (introduced in 70841c5867)
  as it was part of the 1.20.0 release.

* Removed MWException::logException (introduced in c28251a9fd)
  as it was only added a few weeks ago within this release cycle.

Change-Id: Iab98e3a7a9b78d8602e69e0571b35cf107a96b72
2013-10-14 05:00:40 +00:00
Max Semenik
5c51cb96ea Maintenance script to check LESS files for validity
A reworked version of script from I068686854ad79e2f63a08d81b1af02f373110613

Move leccs instantiation code to ResourceLoader because it doesn't depend on any
particular module's state.

Change-Id: I733b53171dca77f50a30e5bd0bd5f1b456e4c85d
2013-09-30 21:37:13 +04:00
Max Semenik
fd4d0ec254 Collect stats about RL cache hit rate
Change-Id: I7cf2f2248f60b0e686e90faf9cb9989b723c88d1
2013-09-19 16:02:59 -07:00
jenkins-bot
136b3c3f5d Merge "Use wfResetOutputBuffers in ResourceLoader" 2013-09-18 17:01:20 +00:00
Aaron Schulz
c28251a9fd Fully log exceptions within ResourceLoader (including traces)
Change-Id: Icb479c76cd855244429fe65b29667783dcca8f53
2013-09-18 16:30:18 +00:00
Marius Hoch
d2ba63a1df Use wfResetOutputBuffers in ResourceLoader
No need to replicate its logic there.

Bug: 46836
Change-Id: I0c6ad90c327e39b9bc35fc3a9ecab39487a1d8b5
2013-09-18 16:16:32 +00:00
csteipp
4624b8a0d0 SECURITY: Prevent FPD on exceptions in load.php
Sanitize error messages in ResourceLoader if $wgShowExceptionDetails is
false.

Bug: 46332

Change-Id: Ia14ae21972192d291cb86dce65568e9e8b4674f7
2013-09-03 21:38:58 +00:00