Commit graph

53 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
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
umherirrender
a88a09d98f fix the call of count( $module->getDependencies() ) in startup (bracket
was wrong placed)

And by the way:
* store some result of getters in local variable and use it
* Title::newMainPage always returns an object
* rename a variable
* fix intendation for mw.loader.register call in debug mode

Change-Id: I083b4b61006493602b9345a822a96d538ef89f60
2012-04-14 12:41:49 +02:00
Krinkle
558e963735 Bug 34604 - [mw.config] wgActionPaths should be an object instead of a numeral array JavaScript 2012-02-23 02:45:45 +00:00
Krinkle
f6ddf76ce8 Removing wgLegacyJavaScriptGlobals from JavaScript output
* PHP config variable itself is still needed for sure, but not needed in JavaScript output. Did get into 1.18 (accidentally added to js output as part of r87856) but undocumented and unannounced.
2011-12-28 22:29:07 +00:00
Robin Pepermans
80a090ea72 * (bug 27721) Make JavaScript variables wgSeparatorTransformTable and wgDigitTransformTable depend on page content language so the sort script sorts correctly more often. It will e.g. sort according to the user language on special pages, where localised numbers are usually used.
* New JavaScript variable wgPageContentLanguage (independent from the bug, but I assume this var can be useful)
2011-11-28 20:53:26 +00:00
Sam Reed
5bd492d51c "else if" to "elseif" 2011-11-25 00:15:27 +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
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
ef927d3904 Remove wgProto from mw.config
* Introduced in r82575 spontaneously, but was never used.
* It was removed from PHP by Tim in r90193, who gracefully kept a work-around in place to still have a protocol available in mw.config.
* Since it was new in JS in 1.18 (which hasn't been released yet), I suggest we take it out right away, especially because the PHP counterpart has been deprecated as well. No release notes needed.
2011-09-09 01:03:27 +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
Krinkle
0e02d2f4cb (bug 29441) Expose CapitalLinks config in JS to allow modules to properly handle titles on case-sensitive wikis.
This brings us one step closer towards:
(bug 29397) Implement mw.Title module in core
2011-06-16 21:20:05 +00:00
Krinkle
7ff6dda4cd Revert r90232. 2011-06-16 21:18:40 +00:00
Krinkle
8f2c463b25 Implement mw.Title in core
* Based on UploadWizard/resources/mw.Title.js
* Refactored to use local scope and prototypes instead of per-instance private scope (less references, faster instantiation)
* Fix potential ReferenceError in the check for wgArticlePath (inline if statements will fail to evaluate for undeclared variables). Using mw.config instead
* The following were not ported because they are or were already redundant and/or merged with another method:
-- setNameText (redundant with the improved setName)
-- setPrefix (redundant wit the improved setNamespace)
* Ported all jasmine tests to QUnit. Left them exactly the same to make sure it's compatible with UploadWizard. Perhaps I'll expand or adjust the suite later to be less file-specific, but for now make sure it's compatible and the same.



@todo FIXME

* Removed assumption that every title has a namespace prefix in it by creating a separate RegExp when there is a namespace given 

** Fixes strip-bug in cases where a namespace appears to be part of a title when the namespace is also given: "Project:User:Foobar"

new mw.Title( 'User:Foobar', 4 ).toString()
> 'Project:Foobar'

** Fixes a thrown exception in case a colon is part of the title (colons are valid in MediaWiki pagenames!)

new mw.Title( 'Just some:Random page')
> Error: mw.Title> Unrecognized canonical namespace: just_some

* Added check for capitalLinks et (wasn't possible before due to bug X)

** Prevents breakages on wiktionary and other wikis with case sensitivity.
2011-06-16 21:16:50 +00:00
Tim Starling
9420ff446e Removed $wgProto. Previously, setting this undocumented global variable to anything other than the part of $wgServer before the first colon would cause various things to subtly screw up. Similarly, forgetting to set it when you override $wgServer in LocalSettings.php would break things too.
Exposing it in the default LocalSettings.php as I did in r90105 was not a good solution, really the only way to avoid breakage is to just get the protocol from $wgServer whenever you need the protocol.

Fixed $wgCookieSecure so that it will be enabled automatically if the user sets $wgServer to an https URL in LocalSettings.php. Added documentation for other cookie-related globals.

Grep indicates that $wgProto is not used by any extensions. $wgCookieSecure is used, hence the need for the Setup.php patch.
2011-06-16 05:13:29 +00:00
Krinkle
33e3d23c56 Merge conflict fix from r90096. 2011-06-14 22:51:47 +00:00
Krinkle
b3621a2826 wgNamespaceIds in JavaScript didn't include canonical namespaces. Adding them to it, in a similar way that Language->getNamespaceIds does it for the localized namespaces and the namespace aliases.
Fixes bug in mw.Title constructor when .setNamespace() is used with a canonical namespace on a non-English content-language wiki.
Example: On a German wiki "var foo = new mw.Title('bar').setNamespace('file')" will throw an Error, as wgNamespaceIds only contains localized namespaces + namespace aliases, not canonical ones (in contrary to the assumption that has been made in various places).

(bug 25375) Add canonical namespaces to JavaScript "wgNamespaceIds"
2011-06-14 22:49:38 +00:00
Roan Kattouw
674e20d91f (bug 29224) Also use a packed modules string for the startup modules (usually there's only one, but there's a hook to add more) 2011-06-01 13:51:50 +00:00
Sam Reed
16c194d0ae Fixup/add documentation
Remove trailing whitespace
2011-05-21 17:45:20 +00:00
Tim Starling
6fec4e3fde Revert r87635, r87637, r87639, r87643 (MW_MIN_PHP_VERSION etc.): breaks HipHop support. 2011-05-15 13:21:16 +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
Happy-melon
fd34d0354b * Implement MW_VERSION constant in Defines.php and use it in preference to $wgVersion. Defines.php will have been loaded anywhere that DefaultSettings.php has been loaded.
* Move the declaration of $wgFeedClasses from Defines.php to WebStart.php
2011-05-07 14:53:08 +00:00
Roan Kattouw
f56afa36a6 (bug 28738) Implement request splitting in mw.loader so ResourceLoader requests with query strings longer than a certain value are split up. The maximum query string length is configurable, and this behavior is disabled by default. It's needed in rare cases where there is a query string length or GET variable length limit in place that the wiki admin can't raise. 2011-05-01 18:41:42 +00:00
Nimish Gautam
61347cecbe added wgCookiePrefix to exported variables 2011-04-21 00:06:21 +00:00
Leo Koppelkamm
77e1e201f6 Followup r86088 per CR: Move month array builder into language; use mw.config.get(); Fix rowspans and some cleanup 2011-04-18 12:54:28 +00:00
Leo Koppelkamm
7d6ddfe836 Completely rewritten table sorting script.
Fixes Bug 8028, Bug 8115, Bug 15406, Bug 17141, Bug 8732

1. Sites can specify custom collations.
The script accepts an object "tableSorterCollation" which contains a lookup
table, how specific characters should be treated.
For example, after setting "tableSorterCollation={'ä':'ae', 'ß':'ss'};" in the
site's common.js any string containing an ä or Ä will be sorted as if it were a
'ae'.

2. Table rows can be forced to use a specific data type.
By setting class="sort-{Parsername}", the row will be parsed with the specified
algorithm. class="sort-date" would force date sorting etc.
The following parsers are available: text, IPAddress, number, url, currency,
date, isoDate, usLongDate, time

3. Execution time is reduced by half or more.

Sorting a 935 row * 8 columns table:

Browser     Before      After
--------    ------      -----
Chrome 10   90ms        42ms
Safari 5    115ms       48ms
Firefox 4   412ms       87ms
IE8         720ms       115ms

4. Based on the content language and the mdy vs dmy preference, the parser can
understand dates such as "17. März '11". wgMonthNames=[] and
wgMonthNamesShort=[] 
in the content language and the mdy vs dmy preference are exported to js; A
table containing the following dates would be sorted correctly:
17. Jan. 01
23 Feb 1992
9.02.05
13 November 2001
14 Oktober '76

Was tested in ie6-8, chrome, safari 5, ff3 & ff4
2011-04-14 21:47:00 +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
61195f5374 Per CR, remove round() call I accidentally reintroduced in r84401 2011-03-20 19:53:46 +00:00
Roan Kattouw
743026d69c (bug 26805) Introduce ResourceLoaderGetStartupModules hook to allow extensions to add modules to the startup set (normally this is jQuery and mediawiki). Applied patch by Michael Dale, with minor style tweaks 2011-03-20 17:15:51 +00:00
Roan Kattouw
1ce0c189ee Followup r84399: remove another round() call 2011-03-20 17:10:48 +00:00
Roan Kattouw
8d2ed2207a Remove stray round() call, rounding of timestamps was removed some time ago. Thanks to Michael for pointing this one out 2011-03-20 17:08:38 +00:00
Krinkle
e12336c269 Add missing to mw.config 2011-02-21 21:24:09 +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
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
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
f5533b0c98 Per Philip Tzou, move wgUserVariant from the set of config variables to the set of pageview-specific variables, because it depends on user settings and such 2011-02-16 17:06:24 +00:00
Roan Kattouw
ab5c4d69ca Expose $wgExtensionAssetsPath in JS 2011-02-16 14:28:26 +00:00
Sam Reed
e42253eb45 Minor documentation tweaks/improvements 2011-02-08 23:09:22 +00:00
Krinkle
a972a4c2de Obviously no need for a foreach loop here. (Follow-up r80790) 2011-01-23 02:22:27 +00:00
Krinkle
db27c3b0dd adding available skins to mw.config.values 2011-01-23 02:19:58 +00:00
Bryan Tong Minh
de79cb9cde Follow-up r79867: Read out EXIF orientation in JavaScript and rotate accordingly. Added JsJpegMeta library by Ben Leslie under the MIT license.
* Added JS variabele wgFileCanRotate. If anybody knows a way to make certain variables only available to certain modules, please tell me, could not find it.
* Added JsJpegMeta as mediawiki.util.jpegmeta
* Made BitmapHandler::getScaler and BitmapHandker::canRotate static
* Bumped style version
2011-01-22 22:34:36 +00:00
Roan Kattouw
41518a86b7 Coerce mtimes to TS_UNIX before outputting them, and fix a wrong timestamp format in ResourceLoaderUserModule. This should fix bug 26704 2011-01-13 14:42:19 +00:00
Roan Kattouw
3a241d498a Fix issue with missing keys in $wgFileExtensions caused by an array_diff() somewhere. Doesn't seem needed on any of the other vars at first glance 2011-01-12 20:58:36 +00:00
Roan Kattouw
7de66bd84f Add a hook for registering variables in ResourceLoaderStartUpModule::getConfig() to complement MakeGlobalVariablesScript 2011-01-09 11:44:52 +00:00
Tim Starling
ccfe5ad97b Fix for bug 26561: clickjacking attacks. See the bug report for full documentation. 2011-01-04 06:12:33 +00:00
Roan Kattouw
37d7dc5653 (bug 26399) Preload module info for all modules in startup module, to prevent lots of individual queries. Also improve preloadModuleInfo() to register the absence of message blobs for modules that do have messages (they were being missed because they were expected to have blobs for this reason) 2010-12-23 21:01:54 +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
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
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