Commit graph

41 commits

Author SHA1 Message Date
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
16842c0b73 Swap else if for elseif
Trimming trailing whitespace also

Doing in 3 commits (2/3), so hopefully reviewable in CR...
2011-06-17 16:05:05 +00:00
Sam Reed
16c194d0ae Fixup/add documentation
Remove trailing whitespace
2011-05-21 17:45:20 +00:00
Trevor Parscal
e6bee6f043 Added direct file loading functionality to debug mode for both scripts and styles, with callbacks for module state changes (changing to ready) and executing of jobs and modules awaiting dependency resolutions. These changes also provide a way to used mw.loader.implement with arrays of URLs for the scripts and styles arguments, which will make it possible to implement modules using user scripts. This probably solves bug #27023 - tests to verify that will be coming soon. 2011-05-14 12:15:58 +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
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
Antoine Musso
3730ef7358 doxygen can use @code ! 2011-03-02 20:28:32 +00:00
Krinkle
b2378a694c Using the mw alias for mediaWiki in core. Saves bandwidth and makes sense (there's no point in a wrapper function for ($,mw) if we use jQuery and mediaWiki inside of it).
TODO: Since the alias is globally available from the start, the 'mw' argument in the wrapper is redundant, so that should be removed at some point as well.
2011-02-19 22:59:44 +00:00
Krinkle
4c0ddd464f Follow-up r82038. Calling wfExpandUrl() on remote base path *AFTER* is has been set in the foreach loop.
(Also ping r81731)
2011-02-12 23:20:32 +00:00
Krinkle
2b6aa1370c Follow-up r81731 CR comments. Calling wfExpandUrl() on remote base path. 2011-02-12 22:46:41 +00:00
Platonides
49074e8a56 Yet more additions of wfProfileOut() 2011-02-10 16:39:53 +00:00
Roan Kattouw
6b6fe23e74 Remove $wgServer prepending from remote JS/CSS paths. It's not needed and breaks other-domain $wgStylePath / $wgExtensionAssetsPath settings 2011-02-08 12:34:08 +00:00
Roan Kattouw
57c3b082a4 Fix bug in ResourceLoader causing LTR->RTL flipping to only be applied to the first CSS file of every module. Thanks to thedj for reporting and investigating this bug and to Nikerabbit for finding the culprit (bad use of array_map) 2011-01-09 16:24:09 +00:00
Roan Kattouw
8075262119 Avoid dot bloat in paths 2011-01-09 12:48:30 +00:00
Trevor Parscal
63ea295de5 Moved CSS flipping to occur inside a module - this resolves a bug which occurs when flipping happens AFTER CSSMin::remap embeds a data URI of an un-flipped image. 2010-12-16 19:31:48 +00:00
Roan Kattouw
5a94d605c5 Spaces to tabs in r77011 2010-12-03 13:04:01 +00:00
Tim Starling
dac5084f6d * Made Resources.php return a pure-data array instead of an ugly mix of data and code. This allows the class code to be lazy-loaded with the autoloader, for a performance advantage especially on non-APC installs. And using the convention where if the class is omitted, ResourceLoaderFileModule is assumed, the registration code becomes shorter and simpler.
* Modified ResourceLoader to lazy-initialise module objects, for a further performance advantage.
* Deleted ResourceLoader::getModules(), provided getModuleNames() instead. Although the startup module needs this functionality, it's slow to generate, so to avoid misuse, it's better to provide a foolproof fast interface and let the startup module do the slow thing itself.
* Modified ResourceLoader::register() to optionally accept an info array instead of an object.
* Added $wgResourceModules, allowing extensions to efficiently define their own resource loader modules. The trouble with hooks is that they contain code, and code is slow. We've been through all this before with i18n. Hooks are useful as a performance tool only if you call them very rarely.
* Moved ResourceLoader settings to their own section in DefaultSettings.php
* Added options to ResourceLoaderFileModule equivalent to the $localBasePath and $remoteBasePath parameters, to allow it to be instantiated via the new array style. Also added remoteExtPath, which allows modules to be registered before $wgExtensionAssetsPath is known.
* Added OutputPage::getResourceLoader(), mostly for debugging.
* The time saving at the moment is about 5ms per request with no extensions, which is significant already with 6 load.php requests for a cold cache page view. This is a much more scalable interface; the relative saving will grow as more extensions are added which use this interface, especially for non-APC installs.

Although the interface is backwards compatible, extension updates will follow in a subsequent commit.
2010-11-19 10:41:06 +00:00
Alexandre Emsenhuber
9dbae9019d Fixed some doxygen warnings 2010-11-08 10:19:28 +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
e2cf4b81db * Break long lines
* For readability, rewrote ResourceLoaderFileModule::readScriptFiles() to use a loop instead of an excessively cute nested array_map() construction.
* In ResourceLoaderFileModule, check file_get_contents() result for errors. Golden rule of error checking: always check fopen(). Every call to fopen will fail some day for some user.
* In mediaWiki.loader.filter(): broke up a complex multi-line conditional into multiple commented if statements, for readability.
* Possessive "its" has no apostrophe.
2010-11-05 06:53:14 +00:00
Tim Starling
82f274088a * Introduced Xml::encodeJsCall(), to replace the awkward repetitive code that was doing the same thing throughout the resource loader with varying degrees of security and correctness.
* Modified Xml::encodeJsVar() to allow it to pass through JS expressions without encoding, using a special object.
* In ResourceLoader::makeModuleResponse(), renamed $messages to $messagesBlob to make it clear that it's JSON-encoded, not an array.
* Fixed MessageBlobStore to store {} for an empty message array instead of [].
* In ResourceLoader::makeMessageSetScript(), fixed call to non-existent function mediaWiki.msg.set.
* For security, changed the calling convention of makeMessageSetScript() and makeLoaderImplementScript() to require explicit object construction of XmlJsCode() before interpreting their input as JS code.
* Documented several ResourceLoader static functions.
* In ResourceLoaderWikiModule, for readability, reduced the indenting level by flipping some if blocks and adding continue statements.
* In makeCustomLoaderScript(), allow non-numeric $version. The only caller I can find is already sending a non-numeric $version, presumably it was broken. Luckily there aren't any loader scripts in existence, I had to make one to test it.
* wfGetDb -> wfGetDB
* Added an extra line break in the startup module output, for readability.
* In ResourceLoaderStartUpModule::getModuleRegistrations(), fixed another assignment expression
2010-11-04 07:53:37 +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
Platonides
eda718909c Remove unused globals. 2010-10-31 15:35:01 +00:00
Roan Kattouw
6d4d8641f6 (bug 25339) Allow specifying separate base paths for local and remote paths in ResourceLoaderFileModule::__construct(). Extensions can use this to properly point the resource loader to their resources in a way that doesn't depend on the extensions/ directory being a subdirectory of phase3/ on the filesystem and that respects $wgExtensionAssetsPath. Also converted all extensions using ResourceLoader to use this approach, except MWEmbed which uses way more indirection building its module registrations than I can deal with after midnight.
What actually happens here
* Add $localBasePath, $remoteBasePath params to the FileModule constructor, defaulting to $IP and $wgScriptPath respectively
* Add getLocalPath() and getRemotePath(), which use this information to build a proper FS or URL path for a file
* Make readScriptFiles() non-static so it can use these functions
* Run every single file path we use through either getLocalPath() or getRemotePath() as appropriate
** Except file dependencies, these are already prefixed. Our inability to give them special treatment caused bugs earlier
* Kill prefixFilePathList() and resolveFilePath(), no longer needed
2010-10-27 22:22:10 +00:00
Roan Kattouw
1fb4cc1f13 Fix regression introduced by doing data URL embedding early causing file dependencies for CSS not to be registered: the data URL embedding had modified the URL to the point where getLocalFileReferences() doesn't recognize it anymore. This is a quick&dirty fix registering dependencies in $this->fileDeps just before each remap() call 2010-10-27 19:59:10 +00:00
Trevor Parscal
46409b75fa Fixes comment mistakes in r75107 2010-10-26 20:17:32 +00:00
Trevor Parscal
0f94d0e00d Fixed missing break; in ResourceLoaderFileModule::__construct, and added extra error checking to it's input arrays. 2010-10-21 22:34:26 +00:00
Trevor Parscal
d7de31b5c3 ResourceLoaderFileModule now uses mediaWiki.loader.load to load scripts in debug mode. 2010-10-21 21:25:27 +00:00
Trevor Parscal
1f0e578130 Changed the way that ResourceLoaderFileModule and mediaWiki.loader work in debug mode. As of this commit, in debug mode, ResourceLoaderFileModule will emit code which appends a a script tag for each raw JavaScript file in the module, instead of the concatenated code of the module's scripts. This eliminates the need to disable batch loading on the client in debug mode, since it effectively supersedes the effect of turning batch loading off. 2010-10-21 01:03:46 +00:00
Trevor Parscal
f5565355b9 Improves on r75055, improving comment accuracy, and removing useless casting. 2010-10-20 20:56:33 +00:00
Trevor Parscal
cdd0fb65c2 * Improves on r75054 and r75036 by adding comments and renaming variables
* Fixes issue cased by creating a file module that only contains a list of dependencies.
2010-10-20 20:43:30 +00:00
Roan Kattouw
e9ff9c0f58 Include $IP in path passed to remap() so filesystem access will work properly 2010-10-20 19:13:43 +00:00
Trevor Parscal
0caccb3d28 Whitespace, comments and general cleanup. 2010-10-20 00:22:25 +00:00
Trevor Parscal
0c2d86685c Some cleanup work 2010-10-19 23:47:56 +00:00
Trevor Parscal
39b695ab1f Whitespace adjustments 2010-10-19 23:02:15 +00:00
Trevor Parscal
4b9b2ca889 Fixed remaning use of $this->loaders to use the new naming of $this->loaderScripts 2010-10-19 23:00:52 +00:00
Trevor Parscal
4f09b0fa47 Fixed case where tryForKey can sometimes not return an array 2010-10-19 22:53:53 +00:00
Trevor Parscal
f3388ec614 Refactored ResourceLoaderFileModule, most notably removing the set* methods, which are not in use at the moment, and should only be added when we have a use case for them (API bloat = bad) 2010-10-19 22:48:52 +00:00
Trevor Parscal
fb64a62306 Fixed ResourceLoaderFileModule constructor - collated lists were not being prefixed properly. Also did some renaming to improve consistency. 2010-10-19 20:59:23 +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
032ef610dd Part 1 of 2, moving ResourceLoader*Module classes to their own files - this commit copies the ResourceLoaderModules.php file to each of the new files, as to maintain revision history. The next revision will remove non file specific code. 2010-10-19 18:25:42 +00:00