Commit graph

24 commits

Author SHA1 Message Date
Robin Pepermans
013410082a Removed Title::isValidCssJsSubpage(), deprecated since 1.17 (77309), and updated all remaining usage in extensions 2011-12-13 11:54:02 +00:00
Roan Kattouw
79916a2c87 Allow overrides of ResourceLoaderWikiModule::getDB() (introduced in r93760) to return null, needed for ForeignAPIGadgetRepo support (introduced in r101627) 2011-11-02 15:04:34 +00:00
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
fe0d158186 (bug 30074) Moving user JS subpages resulted in JS errors because #REDIRECT [[Foo]] is invalid JS. Fix this by refusing to load redirect pages in ResourceLoaderWikiModule. Patch by John Du Hart 2011-08-10 14:23:25 +00:00
Roan Kattouw
883d40949a In ResourceLoaderWikiModule, use isCssOrJsPage() as well as isCssJsSubpage() to check whether a wiki page is a CSS or JS page. This is required to make ResourceLoaderWikiModule work for pages that are CSS/JS pages, but don't live in the MediaWiki namespace and aren't user subpages. This wasn't possible before r93759, which introduced a hook that allows extensions to override which pages are considered to be CSS/JS pages. 2011-08-02 16:00:42 +00:00
Roan Kattouw
641081d341 Factor out obtaining the database object in ResourceLoaderWikiModule into a getDB() method that can be overridden by subclasses. This is needed for the Gadgets extension in the RL2 branch, which subclasses ResourceLoaderWikiModule to create modules for foreign wiki pages. 2011-08-02 15:47:30 +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
Alexandre Emsenhuber
0a7f26f395 Use wfMessage() so that we can check message existence in content language instead of user language 2011-05-22 08:24:07 +00:00
Sam Reed
16c194d0ae Fixup/add documentation
Remove trailing whitespace
2011-05-21 17:45:20 +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
Trevor Parscal
7a1903ec6b Resolves bug #27328 by supporting URL rewriting for CSS that comes from the Wiki, such as user and site scripts. 2011-02-11 22:57:32 +00:00
Sam Reed
e42253eb45 Minor documentation tweaks/improvements 2011-02-08 23:09:22 +00:00
Tim Starling
fc6f65a85b Fixes for ResourceLoaderWikiModule r72776. No serious bugs found, do not merge before deployment.
* Specify page titles as strings instead of split NS/DBK, as suggested by Roan on CR. It seemed sensible to me.
* Pass a Title object to getContent() instead of a string, to avoid unnecessary object construction overhead
* "*" and "/" are valid title characters. Check module input for JS comment end tokens.
* Fixed inappropriate conversion to boolean, when checking result of getContent(). Presumably the idea was to omit empty sections and errors, so that's what I did. Maybe an informative error message would be better in the error case.
* Use LinkBatch for selecting multiple page rows instead of Database::makeWhereFrom2d(). 
* Fixed assignment expression.
2011-02-08 06:34:38 +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
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
Victor Vasiliev
47401b998e Fix r77309 per CR: use appropriate function in ResourceLoaderWikiModule to check the validity of CSS user subpage. 2010-11-27 14:55:54 +00:00
Max Semenik
b200ac0c17 Grammar: it's --> its 2010-11-05 07:39:48 +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
Sam Reed
39c005ca79 bug 25517 Assignment in conditions should be avoided/ http://www.mediawiki.org/wiki/Manual:Coding_conventions#Assignment_expressions 2010-11-01 00:07:17 +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