Commit graph

65 commits

Author SHA1 Message Date
Timo Tijhof
bce48e9420 resourceloader: Consistently use 'resourceloader' log group
Some were using generic wfDebug().

Removed obsolete new-line which is already added by wfDebugLog.

Bug: 44018
Change-Id: I9907b374fa868c04ff2ce40964238936b9084a4a
2013-05-20 19:35:11 +00:00
Timo Tijhof
8dbe77db6c phpcs: Pass includes/resourceloader/
- A cast statement must not be followed by a space.
- The method parameter $context is never used.
- Avoid function calls in a FOR loop test part.
- Opening brace should be on the same line as closing parenthesis.

Change-Id: I0eba7fcc9ceab372003d1134857346690c525e87
2013-04-03 02:16:02 +02:00
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
umherirrender
be90ce07b3 fix some spacing
Change-Id: I93f0a87ba7129bc336083e7289247d3150feb606
2013-02-04 19:54:07 +00:00
Catrope
e2e8461fd2 (bug 31044) Make ResourceLoader behave in read-only mode
When the database is in read-only mode or writes fail for some other
reason, ResourceLoader should make every attempt to still serve JS and
CSS correctly.

* Surround a bunch of DB write code in MessageBlobStore.php in try-catch
  blocks.
* Surround the DB write in ResourceLoaderFileModule.php in a try-catch
  block rather than checking wfReadOnly(), because the DB may fail for
  other reasons.
* In ResourceLoader::respond() and helpers, set a short cache timeout on
  responses that include commented-out error messages.

Change-Id: Idc83a0fe042806263f9337c40ade8c38c56aa3cd
2013-01-16 03:10:26 +00:00
Matthew Flaschen
a5d257e861 Fix typo in ResourceLoaderFileModule.
Change-Id: Ia4460fb8bba7e08f235016fa8b59adf97e48a4d3
2012-12-27 13:05:53 -05:00
Timo Tijhof
799db0b44b ResourceLoader: Move safeFilemtime() to ResourceLoaderModule.
This is a useful method not just for inside and sub classes of
ResourceLoaderFileModule (i.e. it could've been useful in
VisualEditor's ResourceLoaderModule class as well)

Also moved up getTargets() to be in the right section (looking at
the file as a whole).

Change-Id: If696ffbdc5aa7f0a51603bcf9d52adab38b9c686
2012-12-16 23:13:04 +01:00
jeroendedauw
11feec4c56 Remove duplicate files, no point in loading them twice
Change-Id: I52df1ee1cfeda240e8546fa303b65116183d09e7
2012-10-21 23:06:00 +02:00
Brion Vibber
4b3a426ae0 Work in progress on ResourceLoader mobilification
Goes along with MobileFrontend changes: https://gerrit.wikimedia.org/r/28434

Adds 'targets' option to module definitions, defaulting to 'desktop'.
Only a couple more modules are whitelisted into both desktop and mobile for now.

Startup module takes a 'target' parameter (defaults to 'desktop') to filter
the resource module registration list. Only modules matching the filter get
registered, and thus will be loadable from client-side RL.

Change-Id: Ifb772d4995b8e2ec4b63776fe0bb5b0214f82e04
2012-10-18 00:55:54 +00:00
Reedy
505c5cbfe3 Use wfDebugLog() not wfErrorLog()
Change-Id: I98dca32d788a4ff3ea102afe358e91b9ff4b06a5
2012-10-15 21:32:20 +01:00
Reedy
4fbbe15778 Add wfErrorLog() call before throwing an exception in readStyleFile
Due to the stupid PHP bug, this just gets rendered as a warning.

Then we have no idea what is actually wrong...

Change-Id: I38a2c6df2dc09ef67ff23537f867efa2ce2e3b54
2012-10-15 18:12:10 +01:00
Siebrand Mazeland
d4b046a893 Update docs for return and exception info
* Removed some inline tabs in the process.
* IDE fixed some incorrect leading spaces, too.

Change-Id: Ic9303eff6db4424ac3f1fa2816839692b43e6190
2012-10-09 09:41:58 +00:00
Timo Tijhof
ff594d3b0a ResourceLoader: Refactor style loading
Fixes:
* bug 31676: Work around IE stylesheet limit.
* bug 35562: @import styles broken in modules that combine
  multiple stylesheets.
* bug 40498: Don't output empty "@media print { }" blocks.
* bug 40500: Don't ignore media-type for urls in debug mode.

Approach:
* Re-use the same <style> tag so that we stay under the 31
  stylesheet limit in IE. Unless the to-be-added css text from
  the being-loaded module contains @import, in which case we do
  create a new <style> tag and then re-use that one from that
  point on (bug 31676).

* Return stylesheets as arrays, instead of a concatenated string.
  This fixes bug 35562, because @import only works when at the
  top of a stylesheet. By not unconditionally concatenating files
  within a module on the server side already, @import will work
  in e.g. module 'site' that contains 2 wiki pages.

  This is normalized in ResourceLoader::makeCombinedStyles(),
  so far only ResourceLoaderWikiModule makes use of this.

Misc. clean up and bug fixes:
* Reducing usage of jQuery() and mw.html.element() where
  native DOM would be very simple and faster. Aside from
  simplicity and speed, this is also working towards a more
  stand-alone ResourceLoader.
* Trim server output a little bit more
  - Redundant new line after minify-css (it is now an array, so
    no need to keep space afterwards)
  - Redundant semi-colon after minify-js if it ends in a colon
* Allow space in styleTest.css.php
* Clean up and extend unit tests to cover for these features
  and bug fixes.
* Don't set styleEl.rel = 'stylesheet'; that has no business
  on a <style> tag.
* Fix bug in mw.loader's addStyleTag(). It turns out IE6
  has an odd security measure that does not allow manipulation
  of elements (at least style tags) that are created by a
  different script (even if that script was served from the same
  domain/origin etc.). We didn't ran into this before because
  we only created new style tags, never appended to them. Now
  that we do, this came up. Took a while to figure out because
  it was created by mediawiki.js but it calls jQuery which did
  the actual dom insertion. Odd thing is, we load jquery.js and
  mediawiki.js in the same request even...
  Without this all css-url related mw.loader tests would fail
  in IE6.
* mediawiki.js and mediawiki.test.js now pass jshint again.

Tested (and passing qunit/?module=mediawiki; 123 of 123):
* Chrome 14, 21
* Firefox 3.0, 3.6, 4, 7, 14, 15, 16beta
* IE 6, 7, 8, 9
* Safari 4.0, 5.0, 5.1
* Opera 10.0, 11.1, 11.5, 11.6, 12.0, 12.5beta
* iPhone 3GS / iOS 3.0 / Mobile Safari 4.0
  iPhone 4 / iOS 4.0.1 / Mobile Safari 4.0.5
  iPhone 4S / iOS 6.0 Beta / Mobile Safari 6.0

Change-Id: I3e8227ddb87fd9441071ca935439fc6467751dab
2012-10-03 00:23:16 +02:00
Max Semenik
cd7923ac16 Introduced the concept of raw ResourceLoader modules
This is needed for mobile scripts that are supposed to work on dumb
devices and as such can't rely on client-side RL, but still can take
advantage of server-side minification and concatenation.

Patchset 2: Allow loading raw modules with &raw=true appended to URL.

Change-Id: I9410ffbf6633075e07bd06b10a98a4d12d9b6106
2012-05-16 01:03:12 +04:00
Alexandre Emsenhuber
7d9016943d Added missing GPLv2 headers in some places.
Also made file/class documentation more consistent.

Change-Id: I1815587ab2eeb24623ce4bf1c695088bd3f1c2ea
2012-04-30 09:16:10 +02:00
Antoine Musso
f6d01d8bd3 fix @example in ResourceLoaderFileModule
Doxygen @example is meant to include another file content. To render
an example you need to use a named paragraph and then a block of code.
2012-02-01 17:05:15 +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
Sam Reed
eacecf4ed2 Merge r97670, r98206 2011-10-03 13:41:50 +00:00
Sam Reed
f639abf12e Merge r97771, r97775 2011-10-03 13:37:47 +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
Roan Kattouw
ea24f9755f (bug 26486) ResourceLoader modules with paths to nonexistent files cause PHP warnings/notices to be thrown. Worked around all of them using file_exists() checks, and introduced a safe wrapper around filemtime() that checks for file_exists(). The only warning I couldn't squash is "Warning: array_map(): An error occurred while invoking the map callback" but that's due to a bug in PHP, which I've reported at https://bugs.php.net/bug.php?id=55416 2011-08-13 21:25:02 +00:00
Roan Kattouw
ae7d7676fb Fix r93820: PROT_ -> PROTO_ 2011-08-03 13:11:42 +00:00
Roan Kattouw
6adb2e86a5 Some random URL protocol forcing for protocol-relative URLs 2011-08-03 12:58:21 +00:00
Brion Vibber
49d3d18033 Followup to r91608: reduce impact of bug 29784 (high jsmin+ memory usage during parsing) by skipping JS validation on modules backed by files. Unless you're developing them, these will usually be stable, and large individual files like the pre-bundled jQuery can hit memory limits much sooner than we like.
Validation on JS from wiki pages is still on by default ($wgResourceLoaderValidateJS = true).
Validation on static files can be re-enabled by setting $wgResourceLoaderValidateStaticJS = true (defaults false).
2011-07-11 21:39:06 +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
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