Commit graph

21 commits

Author SHA1 Message Date
Sam Reed
f8a0e34ca1 Documentation
Trim trailing whitespace

Make returns return values where appropriate (ie other paths in the same method do)
2011-10-14 08:06:54 +00:00
Roan Kattouw
488d368b86 Followup r96978, clean up code duplication by factoring out the code building load.php requests into ResourceLoader::makeLoaderURL() and makeLoaderQuery() 2011-09-13 20:36:24 +00:00
Roan Kattouw
f4f3107209 Fix the fixme on r88053: dependency handling was broken in debug mode in certain cases. More specifically, if A is a file module that depends on B, B is a wiki module that depends on C and C is a file module, the loading order is CBA (correct) in production mode but was BCA (wrong) in debug mode. Fixed this by URL-ifying scripts and styles for those modules in debug mode, as I said to on CR. What this means is that the initial debug=true request for a module will now always return arrays of URLs, never the JS or CSS itself. This was already the case for file modules (which returned arrays of URLs to the raw files), but not for other modules (which returned the JS and CSS itself). So for non-file modules, load.php?modules=foo&debug=true now returns some JS that instructs the loader to fetch the module's JS from load.php?modules=foo&debug=true&only=scripts and the CSS from ...&only=styles .
* Removed the magic behavior where ResourceLoaderModule::getScripts() and getStyles() could return an array of URLs where the documentation said they should return a JS/CSS string. Because I didn't restructure the calling code too much, the old magical behavior should still work.
* Instead, move this behavior to getScriptURLsForDebug() and getStyleURLsForDebug(). The default implementation constructs a single URL for a load.php request for the module with debug=true&only=scripts (or styles). The URL building code duplicates some things from OutputPage::makeResourceLoaderLink(), I'll clean that up later. ResourceLoaderFileModule overrides this method to return URLs to the raw files, using code that I removed from getScripts()/getStyles()
* Add ResourceLoaderModule::supportsURLLoading(), which returns true by default but may return false to indicate that a module does not support loading via a URL. This is needed to respect $this->debugRaw in ResourceLoaderFileModule (set to true for jquery and mediawiki), and obviously for the startup module as well, because we get bootstrapping problems otherwise (can't call mw.loader.implement() when the code for mw.loader isn't loaded yet)
2011-09-13 17:13:53 +00:00
Krinkle
cc21627b4d [ResourceLoader 2]: Add support for multiple loadScript sources
Front-end:
* New mw.loader method: addSource(). Call with two arguments or an object as first argument for multiple registrations
* New property in module registry: "source". Optional for local modules (falls back to 'local'). When loading/using one or more modules, the worker will group the request by source and make separate requests to the sources as needed.
* Re-arranging object properties in mw.loader.register to match the same order all other code parts use.
* Adding documentation for 'source' and where missing updating it to include 'group' as well.
* Refactor of mw.loader.work() by Roan Kattouw and Timo Tijhof:'
-- Additional splitting layer by source (in addition to splitting by group), renamed 'groups' to 'splits'
-- Clean up of the loop, and removing a no longer needed loop after the for-in-loop 
-- Much more function documentation in mw.loader.work()
-- Moved caching of wgResourceLoaderMaxQueryLength out of the loop and renamed 'limit' to 'maxQueryLength

Back-end changed provided through patch by Roan Kattouw (to avoid broken code between commits):
* New method in ResourceLoader: addSource(). During construction of ResourceLoader this will be called by default for 'local' with loadScript property set to $wgLoadScript. Additional sources can be registered through $wgResourceLoaderSources (empty array by default)
* Calling mw.loader.addSource from the startup module
* Passing source to mw.loader.register from startup module
* Some new static helper methods

Use:
* By default nothing should change in core, all modules simply default to 'local'. This info originates from the getSource()-method of the ResourceLoaderModule class, which is inherited to all core ResourceLoaderModule-implementations (none override it)
* Third-party users and/or extensions can create new classes extending ResourceLoaderModule, re-implementing the getSource-method to return something else.

Basic example:
$wgResourceLoaderSources['mywiki'] = array( 'loadScript' => 'http://example.org/w/load.php' );
class MyCentralWikiModule extends ResourceLoaderModule {
	function getSource(){
		return 'mywiki';
	}
}
$wgResourceModules['cool.stuff'] => array( 'class' => 'MyCentralWikiModule' );

More complicated example
// imagine some stuff with a ForeignGadgetRepo class, putting stuff in $wgResourceLoaderSources in the __construct() method
class ForeignGadgetRepoGadget extends ResourceLoaderModule {
	function getSource(){
		return $this->source;
	}
}

Loading:
Loading is completely transparent, stuff like $wgOut->addModules() or mw.loader.loader/using both take it as any other module and load from the right source accordingly.


--
This commit is part of the ResourceLoader 2 project.
2011-07-26 21:10:34 +00:00
Brion Vibber
0f201b19f4 * (bug 28626) Validate JavaScript files and pages loaded via ResourceLoader before minification, protecting separate modules from interference
This is possibly not perfect but seems to serve for a start; follows up on r91591 that adds JSMin+ to use it in some unit tests. May want to adjust some related bits.

- $wgResourceLoaderValidateJs on by default (can be disabled)
- when loading a JS file through ResourceLoaderFileModule or ResourceLoaderWikiModule, parse it using JSMinPlus's JSParser class. If the parser throws an exception, the JS code of the offending file will be replaced by a JS exception throw listing the file or page name, line number (in original form), and description of the error from the parser.
- parsing results are cached based on md5 of content to avoid re-parsing identical text
- for JS pages loaded via direct load.php request, the parse error is thrown and visible in the JS console/error log

Issues:
- the primary use case for this is when a single load.php request implements multiple modules via mw.loader.implement() -- the loader catches the exception and skips on to the next module (good) but doesn't re-throw the exception for the JS console. It does log to console if present, but it'll only show up as a regular debug message, not an error. This can suppress visibility of errors in a module that's loaded together with other modules (such as a gadget).
- have not done performance testing on the JSParser
- have not done thorough unit testing with the JSParser
2011-07-06 21:48:09 +00:00
Sam Reed
16c194d0ae Fixup/add documentation
Remove trailing whitespace
2011-05-21 17:45:20 +00:00
Roan Kattouw
82bf4764ea For bug 27488: move the startup script, jquery+mediawiki and the mw.config.set() call for configuration variables back to the <head> . Let modules control whether they're loaded in the <head> ('top') or at the bottom of the <body> ('bottom') through the position parameter/property
Also rearranges the loading order a little bit such that only=messages comes before only=scripts, and config comes before everything except startup and jquery+mediawiki
2011-04-07 12:07:25 +00:00
Roan Kattouw
246362f8c2 Fix default implementation of ResourceLoaderModule::getStyles() to return an array, not a string. Was causing problems with another function that was being fed the return value of getStyles() and used an array type hint 2011-03-27 14:13:57 +00:00
Sam Reed
757750dcac Remove getFlip code duplication
Move usual one into ResourceLoaderModule, and then move what was in ResourceLoaderModule into ResouceLoaderFileModule
2011-03-25 11:15:40 +00:00
Roan Kattouw
880f09b10c (bug 27302) Avoid unnecessary requests for user and site modules if the relevant wiki pages don't exist.
Done by adding isKnownEmpty() to ResourceLoaderModule and overriding it to check for page existence in ResourceLoaderWikiModule. Needed to rearrange some code in OutputPage::makeResourceLoaderLink() to have the emptiness check and dropping of modules work properly. Also factored the page_touched check in ResourceLoaderWikiModule::getModifiedTime() out to a separate method (getTitleMtimes()) and moved in-object caching there as well, so getModifiedTime() and isKnownEmpty() share code and caching for their timestamp/existence checks.

This does not account for the case where e.g. a user has user CSS but no user JS: I had implemented this by checking for $context->getOnly() in getTitleMtimes(), but then realized it's not safe to do this in a function called by getModifiedTime(): it causes the timestamp list in the startup module to only take scripts in account for wiki modules, because the startup module has &only=scripts set
2011-02-19 17:07:05 +00:00
Sam Reed
c0830dd868 2 subclasses of ResourceLoaderWikiModule implement a duplicate version of getFlip. Move it up into ResourceLoaderWikiModule
(Almost looks like it could all go into ResourceLoaderModule... But that uses a different version, seemingly, the only one. 3 other subclasses of ResourceLoaderModule implement the same version of getFlip as is moved into a parent class here... Seems daft to have a different version in the base abstract class... Minor oversight?)

Some documentation
2011-02-18 00:33:45 +00:00
Roan Kattouw
c38e2e499c Fixes for r81936 per Tim's review 2011-02-11 08:29:55 +00:00
Roan Kattouw
370d700dd6 Fix getMsgBlobMtime() to also cause a cache invalidation if a module has messages but no stored message blob 2011-02-11 08:07:47 +00:00
Krinkle
dfb5beb89d user scripts & styles are lowercase skin; + using 'vector' as example instead. 2011-02-04 16:44:07 +00:00
Happy-melon
da36f65433 Follow-up r64670 (bug22929): cleaner implementation of security for script (and potentially CSS) files. ResourceLoader *already* knows where each module has come from, so all we need to do is filter them in OutputPage according to the desired level of 'trustworthiness'.
TODO:
* Are there instances where we might want to restrict CSS as well as JS?
* Would a $wg config option and/or user preference and/or index.php GET parameter to limit inclusion be useful?
* Can we deprecate any of the existing $wg config options?
* What's going on with the duplicated code between OutputPage and SkinTemplate?
2011-02-04 16:39:17 +00:00
Sam Reed
b2bfcc788a Documentation addition/tweaks 2011-01-10 04:44:33 +00:00
Tim Starling
ec2acb239b * In ResourceLoaderContext, lazy-load $this->direction and $this->language, to avoid loading the whole English localisation for load.php requests which never call getHash().
* Interpreted some Trevor-speak in the doc comment of ResourceLoader::preloadModuleInfo().
* Made setMsgBlobMtime() (called from preloadModuleInfo()) actually work, by making getMsgBlobMtime() use the cached blob times if they are available.
2010-11-19 06:52:38 +00:00
Trevor Parscal
c519873cdc Fixed Doxygen incompatible JSDoc style comments (bad Trevor!) as per some comments on r75036. 2010-11-05 18:33:50 +00:00
Tim Starling
06b2b1bd66 Resource loader minor changes. Fix for r73668 etc.
* Break long lines.
* Convert long or unnecessary ternary operator usages to if/else.
* Fixed excessively clever assignment expressions.
* Rename $cache to $cacheEntry.
* Removed unnecessary web invocation guards. Their perlish form was making me uncomfortable. BTW, unlike in Perl, die() is not a function, it's a special case in the PHP grammar which very roughly simulates the Perl syntax:

die "x"; // works
0 || die("x"); // works
0 || (die); // works
0 || (die "x"); // fail!
2010-11-03 07:58:03 +00:00
Trevor Parscal
70bae52c12 Part 2 of 2, moved ResourceLoader*Module classes to their own files - this commit removes the non file specific code. 2010-10-19 18:31:09 +00:00
Trevor Parscal
ef6baa91de Moved ResourceLoader classes to their own folder, preparing to also split ResourceLoaderModule.php into multiple files (it's getting a bit long now) 2010-10-19 18:21:38 +00:00
Renamed from includes/ResourceLoaderModule.php (Browse further)