Merge "mw.Map: add ability to map over an existing object other than 'window'"
[lhc/web/wiklou.git] / resources / mediawiki / mediawiki.js
index acda5d6..1f89792 100644 (file)
@@ -21,6 +21,7 @@ var mw = ( function ( $, undefined ) {
         * fine. No need for optimization here, which would only result in losing logs.
         *
         * @private
+        * @method log_
         * @param {string} msg text for the log entry.
         * @param {Error} [e]
         */
@@ -74,11 +75,11 @@ var mw = ( function ( $, undefined ) {
         * @class mw.Map
         *
         * @constructor
-        * @param {boolean} [global=false] Whether to store the values in the global window
-        *  object or a exclusively in the object property 'values'.
+        * @param {Object|boolean} [values] Value-bearing object to map, or boolean
+        *  true to map over the global object. Defaults to an empty object.
         */
-       function Map( global ) {
-               this.values = global === true ? window : {};
+       function Map( values ) {
+               this.values = values === true ? window : ( values || {} );
                return this;
        }
 
@@ -318,6 +319,9 @@ var mw = ( function ( $, undefined ) {
                }
        };
 
+       /**
+        * @class mw
+        */
        return {
                /* Public Members */
 
@@ -1227,7 +1231,7 @@ var mw = ( function ( $, undefined ) {
                                 */
                                work: function () {
                                        var     reqBase, splits, maxQueryLength, q, b, bSource, bGroup, bSourceGroup,
-                                               source, group, g, i, modules, maxVersion, sourceLoadScript,
+                                               source, concatSource, group, g, i, modules, maxVersion, sourceLoadScript,
                                                currReqBase, currReqBaseLength, moduleMap, l,
                                                lastDotIndex, prefix, suffix, bytesAdded, async;
 
@@ -1256,14 +1260,16 @@ var mw = ( function ( $, undefined ) {
 
                                        mw.loader.store.init();
                                        if ( mw.loader.store.enabled ) {
+                                               concatSource = [];
                                                batch = $.grep( batch, function ( module ) {
                                                        var source = mw.loader.store.get( module );
                                                        if ( source ) {
-                                                               $.globalEval( source );
-                                                               return false; // Don't fetch
+                                                               concatSource.push( source );
+                                                               return false;
                                                        }
-                                                       return true; // Fetch
+                                                       return true;
                                                } );
+                                               $.globalEval( concatSource.join( ';' ) );
                                        }
 
                                        // Early exit if there's nothing to load...
@@ -1460,16 +1466,19 @@ var mw = ( function ( $, undefined ) {
                                 * @param {Function|Array} script Function with module code or Array of URLs to
                                 *  be used as the src attribute of a new `<script>` tag.
                                 * @param {Object} style Should follow one of the following patterns:
+                                *
                                 *     { "css": [css, ..] }
                                 *     { "url": { <media>: [url, ..] } }
+                                *
                                 * And for backwards compatibility (needs to be supported forever due to caching):
+                                *
                                 *     { <media>: css }
                                 *     { <media>: [url, ..] }
                                 *
                                 * The reason css strings are not concatenated anymore is bug 31676. We now check
                                 * whether it's safe to extend the stylesheet (see #canExpandStylesheetWith).
                                 *
-                                * @param {Object} msgs List of key/value pairs to be added to {@link mw#messages}.
+                                * @param {Object} msgs List of key/value pairs to be added to mw#messages.
                                 */
                                implement: function ( module, script, style, msgs ) {
                                        // Validate input
@@ -1790,14 +1799,18 @@ var mw = ( function ( $, undefined ) {
                                         * code for a full account of why we need a try / catch: <http://git.io/4NEwKg>.
                                         */
                                        init: function () {
-                                               var raw, data;
+                                               var raw, data, optedIn;
 
                                                if ( mw.loader.store.enabled !== null ) {
                                                        // #init already ran.
                                                        return;
                                                }
 
-                                               if ( !mw.config.get( 'wgResourceLoaderStorageEnabled' ) || mw.config.get( 'debug' ) ) {
+                                               // Temporarily allow users to opt-in during mw.loader.store test phase by
+                                               // manually setting a cookie (bug 56397).
+                                               optedIn = /ResourceLoaderStorageEnabled=1/.test( document.cookie );
+
+                                               if ( !( mw.config.get( 'wgResourceLoaderStorageEnabled' ) || optedIn ) || mw.config.get( 'debug' ) ) {
                                                        // Disabled by configuration, or because debug mode is set.
                                                        mw.loader.store.enabled = false;
                                                        return;