Commit graph

85 commits

Author SHA1 Message Date
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
Catrope
4910a61046 Factor out module name validation into a static function
Also add the requirement that module names be at most 255 bytes, so
they'll fit in the DB fields that we put module names in (md_module,
mr_resource, mrl_resource)

Change-Id: I7193c9beb7aff4eabfe20db461e6f9032ae994b1
2012-05-09 14:41:27 -07:00
Alexandre Emsenhuber
160a1df2f0 Fix comment ResourceLoader::tryRespondFromFileCache().
Mention ResourceFileCache instead of ObjectFileCache for the $fileCache parameter since the signature is
function tryRespondFromFileCache( ResourceFileCache $fileCache, ResourceLoaderContext $context )

Change-Id: I8e738c847ea358117a2a9b54f41fdb10308e2656
2012-05-08 17:53:59 +02: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
Aaron
3b7e79486f Put the filecache save step before the error buffer closes so those errors don't break the output.
Change-Id: Icee6e97002ca9ac9dc76dcb6cd9a3badf7d2b8db
2012-04-16 12:17:02 -07:00
Reedy
13169c88c1 * (bug 34212) ApiBlock/ApiUnblock allow action to take place without a token parameter present
* (bug 35317) CSRF in Special:Upload
Revert r56793, which removed the CSRF check for Special:Upload for normal file
uploads. Cross-site posting of file uploads without user interaction has been
possible since at least as early as Chrome 8 (late 2010) and Firefox 6 (mid
2011).

Commonist has used api.php since version 0.4.0 (April 2010), and the API
already requires an edit token, so Commonist 0.4.0+ is not affected by this
change.

* (bug 34907) Fix for CSRF vulnerability due to mw.user.tokens. Patch by Roan
Kattouw and Tim Starling.
* Filter out private modules early in ResourceLoader::makeResponse() and just
pretend they weren't specified. This means these modules cannot be loaded
through load.php . This filtering must not happen in makeModuleResponse(),
because that would break inlining.
* Force inlining of private modules in OutputPage::makeResourceLoaderLink(),
disregarding $wgResourceLoaderInlinePrivateModules
* Remove $wgResourceLoaderInlinePrivateModules
* Remove special treatment of private modules ($private) in
ResourceLoader::makeResponse() and sendResponseHeaders(), because we're not
allowing private modules to be loaded through here any more
* Remove identity checks in ResourceLoaderUserOptionsModule and
ResourceLoaderUserCSSPrefsModule, they didn't make a lot of sense before but
they're certainly useless now.
* Factored out error comment construction in ResourceLoader.php and stripped
comment terminations from exception messages. I didn't find an XSS
vulnerability but it looked scary.

Patchset2:
 Removes whitespace error that prevented automatic merge by Gerrit:
 includes/resourceloader/ResourceLoaderUserOptionsModule.php

Change-Id: I2dec8b8caf9db3c64919763865cc10cccdd6a1a3
2012-03-26 11:46:46 +02:00
Krinkle
1e2c889d03 [ResourceLoader] Minor clean up
* Re-order special modules and add a few comments
* Single quote in QUnitTestResources.php
* Space in ResourceLoader.php

(Separated from another commit while skimming code)
2012-03-04 22:56:43 +00:00
Krinkle
5bf04171dc [RL] Comment mod and other minor changes
_ Add comment about why it casts to (object)
- Modify function comment
- Whitespace (start the function body on a new line in debug mode. In production mode this is trimmed away afterwards)
- Remove the jQuery->$ passage from loader. There is already a global alias for $ by jQuery, and aside from that every module has it's own (function(){}) wrapper that aliases it from jQuery (not from $), so there is no performance gain either by having it locally here since it doesn't use that.
2012-02-13 15:17:15 +00:00
Sam Reed
0a626db6e1 Fixing some of the "@return true" or "@return false", need to be "@return bool" and then the metadata can say true if foo, false if bar
Other documentation improvements
2012-02-09 19:29:36 +00:00
Alexandre Emsenhuber
5d28d74a73 Fix profiling, that function is not profiled 2012-01-18 14:48:35 +00:00
Aaron Schulz
5a6559d8b1 Reverted r108743 per CR comment. This should at least be discussed first. 2012-01-12 19:41:18 +00:00
Sam Reed
a5c200a25b Kill "* @return void" 2012-01-12 19:12:24 +00:00
Antoine Musso
c447423593 merge JSTesting branch into trunk
Changed written by Timo and reviewed by Hashar. This should be harmless.

To enable the feature:
  $wgEnableJavaScriptTest = true;

Then head to:
  [[Special:JavaScriptTest/qunit]]
2012-01-03 18:33:26 +00:00
Krinkle
10138296b4 Move embedded ResourceLoader modules to the <head>
* Embed "private" ResourceLoader modules in the <head> before the first loader link, instead of in the <body> after the last loader link
* Wow, was in the opposite place where it should've been :D
* Fixes bug 30914
2011-12-28 22:20:29 +00:00
Aaron Schulz
5dc9336cf4 FU r98698: Show any PHP warnings in tryRespondFromFileCache() in debug mode 2011-12-17 05:02:15 +00:00
Brion Vibber
e97346ec18 Revert r103978, r103979 -- screwed something up, breaks jQuery minification.
Incremented ResourceLoader::filterCacheVersion rather than decrementing to avoid potential confusion, especially since we already needed the incr.
2011-11-23 00:22:46 +00:00
Brion Vibber
956de0db3f Functional part of r103978 (d'oh!) plus an update to the ResourceLoader filter cache key, so broken entries stuck in cache will be reloaded. 2011-11-22 23:20:50 +00:00
Roan Kattouw
f12177ce20 Make ResourceLoader::register() non-recursive, was calling itself recursively on every page load. 2011-11-19 16:02:26 +00:00
Platonides
d71e657d59 The early return added in r98698 was skipping the closing wfProfileOut(). 2011-10-27 20:50:07 +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
Aaron Schulz
93d358cd0c FileCache:
* Added FileCacheBase::*MissesRecent() functions for counting cache misses from different visitors.
* Made ObjectFileCache more generic.
* Cleaned up FileCacheBase::checkCacheDirs().
* Added FileCacheBase::typeSubdirectory() function and overwrote in HTMLFileCache. Fixes r98405 invalidating all existing cache due to directory change.
* Simplified FileCacheBase::checkCacheDirs() a bit

ResourceLoader:
* Use ResourceFileCache to handle load() requests, if $wgUseFileCache. Only caches requests for default language and skins. Single modules requests are always cached, whereas others require a certain threshold of traffic.
* Added ResourceFileCache class (functionality was initially to be in ObjectFileCache).
2011-10-02 17:53:33 +00:00
Aaron Schulz
a7bd3bed3c Reverted stuff from r98602 committed by mistake 2011-10-01 05:03:10 +00:00
Aaron Schulz
9ac53dcc3b Made provideIPCIDRs() not add a '/' if there is no prefix length. Fixes bug 31234. 2011-10-01 04:54:44 +00:00
Aaron Schulz
9b2cff1c2d Refactored out new sendResponseHeaders() and tryRespondLastModified() functions out of respond() code. These changes were made for $wgUseFileCache support (haven't committed the other stuff here). 2011-10-01 04:15:07 +00:00
Roan Kattouw
2b05b95a6d Address fixme on r96978: expand URLs fed to the client-side loader 2011-09-30 10:14:39 +00:00
Krinkle
32327650c5 clean up Html::inlineScript usage
* ResourceLoader::makeLoaderConditionalScript:
-- window.mediaWiki -> window.mw; Not just because it's shorter but because that's the variable that is actually being used inside the script.
* ProtectionForm::buildCleanupScript
-- Use a single quote string and no new line
-- Use ResourceLoader::makeLoaderConditionalScript instead of duplicating this logic everywhere
* ProtectionForm::buildCleanupScript:
-- Use Xml::encodeJsCall to render javascript code
-- Use ResourceLoader::makeLoaderConditionalScript
-- Fix bug 31230 by using the new OutputPage->addJsConfigVars( r98374 )
(had to use $wgOut for now since there wasn't an obvious route to a context that I could find here (Article has context, but ProtectionForm::__construct takes any WikiPage, not just Article)
* EditPage::getEditToolbar:
-- Use Xml::encodeJsCall
-- Use ResourceLoader::makeLoaderConditionalScript

Fixes:
* (bug 31230) ProtectionForm should set wgCascadeableLevels in mw.confg instead of globally
2011-09-28 22:47:05 +00:00
Niklas Laxström
c94639fe2d rv r97851 for further inspection, causes PHP notices 2011-09-22 21:27:04 +00:00
Ilmari Karonen
b0f51413b0 followup r79862: the for loop only cleans up half the output handlers (since $i counts up while ob_get_level() counts down); check the return value of ob_end_clean() instead.
(I just noticed this while eyeballing the code -- apparently most people don't have multiple output handlers active, given that nobody had caught this in over eight months.)
2011-09-22 20:44:05 +00:00
Roan Kattouw
b9af8a8118 Followup r93247: add apiScript as a property of a ResourceLoader source. 2011-09-15 15:40:40 +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
Chad Horohoe
94245538ff Merge live hack - bumping version of minified stuff 2011-08-01 23:20:58 +00:00
Roan Kattouw
a2afc812ca Make mw.user.options and mw.user.tokens work in debug mode in IE. Now that mw.user is a separate module, we have to make these depend on that and make sure dependencies are actually processed.
* Make ResourceLoaderUserOptionsModule and ResourceLoaderUserTokensModule depend on mw.user
* Load mw.user.{tokens,options,groups} load as TYPE_COMBINED instead of TYPE_SCRIPT. The latter wouldn't wrap the code in mw.loader.implement()
** ...but make sure 'user' (user scripts) is excluded, that one needs to not be wrapped in a closure
* Make TYPE_COMBINED actually work in makeResourceLoaderLink()
* Add a comment in makeModuleResponse() to explain what the weird is_array( $scripts ) stuff is all about
* Add FIXME about how mw.user.options should split off the CSS part into a separate module
2011-07-28 05:48:57 +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
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
Roan Kattouw
8dab43f703 (bug 28840) URLs with dots break because of IE6 security check
* Replace the overly paranoid regex with a function that simulates IE6's behavior
* Remove the UA check in isPathInfoBad(), was causing more problems than it was worth
* Revert r87711, going back to using dots for dots in ResourceLoader URLs, instead of exclamation marks
* Append &* to ResourceLoader URLs. * is an illegal character in extensions, and putting it at the end of the URL ensures that both IE6 and our detection function will deem the URL to have no extension (unless something like .html? appears in the query string, but in that case we're screwed no matter what)
2011-05-26 09:49:45 +00:00
Sam Reed
16c194d0ae Fixup/add documentation
Remove trailing whitespace
2011-05-21 17:45:20 +00:00
Platonides
28e6771032 Follow up r88053. This was trying to throw the return value of a function called MWException. 2011-05-15 12:36:21 +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
104c5ddfe9 Followup r87711: add ! to the forbidden characters list for module names, per CR 2011-05-14 09:24:24 +00:00
Krinkle
49ce5de7d9 Creating a way to toggle mw.config LEGACY_GLOBALS from LocalSettings (bug 28916).
* I thought a while for a way to somehow get that global variable from php to the start of the main mediaWiki object creation. Considered using a (temporary) global variable and deleting afterwards, but that looked like a hack and wasn't sure about the cross-browser functioning of it. Instead ended up by moving it to the startUp module where other global variables are accessed as well. This seems to work pretty good.

* Can be toggled from LocalSettings by setting $wgLegacyJavaScriptGlobals.
* Changed some usages of mediaWiki to use the global mw alias instead.
2011-05-10 23:17:13 +00:00
Roan Kattouw
950cf2cb86 (bug 28840) Commit patch by bawolff that encodes dots in ResourceLoader module names as exclamation marks in the generated URLs, so as to avoid triggering the recently added IE security measure and causing a blank 403 response. This broke RL in various ways for IE users.
This is by no means intended to be permanent, but it's the best way to unbreak RL for IE users while we work out how to fix this properly.
2011-05-09 13:10:06 +00:00
Roan Kattouw
7fee86c38e Per bug 28738 comment 4, pack ResourceLoader URLs by encoding foo.bar|foo.baz|bar.baz|bar.quux as foo.bar,baz|bar.baz,quux
* Expand these URLs in ResourceLoaderContext
* Build and emit these URLs in OutputPage::makeResourceLoaderLink() and in mw.loader
* Throw an exception in ResourceLoader::register() for module names that contain pipe characters or commas. Commas need to be forbidden for this packing feature to work. Pipes were already forbidden but weren't checked for
2011-05-05 13:46:47 +00:00
Krinkle
373859bafe mw.loader fixes
* Renaming locally declared function "request" to "getScriptTag" to avoid confusion or conflict with the other local "request" function inside the mw.loader closure
* (bug 26804) Code clean up ($skin was generated locally already)
2011-05-04 20:58:14 +00:00
Trevor Parscal
2cff94d097 Added charset property to HTTP Content-Type fields when serving CSS and JavaScript via ResourceLoader - resolves bug #28208. 2011-04-01 20:48:50 +00:00
Roan Kattouw
b066397f10 Bump RL filter version to 4 to keep it in sync with the cluster. WMF-centrism, I know, sue me ;) 2011-03-23 17:45:00 +00:00
Roan Kattouw
15bcd02d4c (bug 27054) Implicit end of statement can break stuff when files are combined. Applied patch by Paul Copperman: add a semicolon to the end of every module when combining; this'll terminate any unterminated final statement, and otherwise create a harmless empty statement. 2011-03-14 14:25:23 +00:00
Roan Kattouw
47d5ad564b Followup r83885: implement maximum line length and statement termination (each statement on its own line) in JavaScriptMinifier. Also add globals for these things and update minify.php for these new config vars. 2011-03-14 13:24:30 +00:00
Roan Kattouw
867fc1cba8 (bug 27528) Incorporate Paul Copperman's minifier 2011-03-14 11:44:33 +00:00
Krinkle
e89aab93a3 mw.loader.implement now calls script without setting mw to mediaWiki since this is already globally avaiable
* Also shortens a few wrapper functions the same way
* Partial revert of r82496. Apparantly mw-alias is not available in startUp module. TODO: Find out why ?

(See also r82496 commit message)
2011-02-19 23:52:11 +00:00