Use global variables directly as globals, except for the specific
case of accessing it when it may not exist. In those cases we
use the fact that undefined properties of an object yield the
`undefined` value which we can cast to false. Accessing an undefined
variable would yield a ReferenceError exception.
Change-Id: I1d9e9aa5845ba3c756ad6e31358d8594e003b04b
*/
public static function makeLoaderConditionalScript( $script ) {
// Adds a function to lazy-created RLQ
*/
public static function makeLoaderConditionalScript( $script ) {
// Adds a function to lazy-created RLQ
- return '(window.RLQ=window.RLQ||[]).push(function(){' .
+ return '(RLQ=window.RLQ||[]).push(function(){' .
trim( $script ) . '});';
}
trim( $script ) . '});';
}
*/
public static function makeInlineCodeWithModule( $modules, $script ) {
// Adds an array to lazy-created RLQ
*/
public static function makeInlineCodeWithModule( $modules, $script ) {
// Adds an array to lazy-created RLQ
- return '(window.RLQ=window.RLQ||[]).push(['
+ return '(RLQ=window.RLQ||[]).push(['
. self::encodeJsonForScript( $modules ) . ','
. 'function(){' . trim( $script ) . '}'
. ']);';
. self::encodeJsonForScript( $modules ) . ','
. 'function(){' . trim( $script ) . '}'
. ']);';
return new WrappedString(
Html::inlineScript( $js, $nonce ),
return new WrappedString(
Html::inlineScript( $js, $nonce ),
- "<script$escNonce>(window.RLQ=window.RLQ||[]).push(function(){",
+ "<script$escNonce>(RLQ=window.RLQ||[]).push(function(){",
*
* - Beware: This file MUST parse without errors on even the most ancient of browsers!
*/
*
* - Beware: This file MUST parse without errors on even the most ancient of browsers!
*/
-/* eslint-disable no-implicit-globals, vars-on-top, no-unmodified-loop-condition */
-/* global $VARS, $CODE */
+/* eslint-disable no-implicit-globals */
+/* global $VARS, $CODE, RLQ:true, NORLQ:true */
/**
* See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
/**
* See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
.replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
// Process any callbacks for Grade C
.replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
// Process any callbacks for Grade C
- while ( window.NORLQ && window.NORLQ[ 0 ] ) {
- window.NORLQ.shift()();
+ while ( window.NORLQ && NORLQ[ 0 ] ) {
+ NORLQ.shift()();
push: function ( fn ) {
fn();
}
};
// Clear and disable the Grade A queue
push: function ( fn ) {
fn();
}
};
// Clear and disable the Grade A queue
push: function () {}
};
} else {
push: function () {}
};
} else {
// arrivals will also be processed. Late arrival can happen because
// startup.js is executed asynchronously, concurrently with the streaming
// response of the HTML.
// arrivals will also be processed. Late arrival can happen because
// startup.js is executed asynchronously, concurrently with the streaming
// response of the HTML.
- var queue = window.RLQ;
- window.RLQ = [];
- /* global RLQ */
+ RLQ = window.RLQ || [];
RLQ.push = function ( fn ) {
if ( typeof fn === 'function' ) {
fn();
} else {
RLQ.push = function ( fn ) {
if ( typeof fn === 'function' ) {
fn();
} else {
- // This callback requires a module, handled in mediawiki.base.
+ // If the first parameter is not a function, then it is an array
+ // containing a list of required module names and a function.
+ // Do an actual push for now, as this signature is handled
+ // later by mediawiki.base.js.
RLQ[ RLQ.length ] = fn;
}
};
RLQ[ RLQ.length ] = fn;
}
};
- while ( queue && queue[ 0 ] ) {
- // Re-use our new push() method
- RLQ.push( queue.shift() );
+ while ( RLQ[ 0 ] ) {
+ // Process all values gathered so far
+ RLQ.push( RLQ.shift() );
}
// Clear and disable the Grade C queue
}
// Clear and disable the Grade C queue
push: function () {}
};
}() );
push: function () {}
};
}() );
// Single only=scripts load
[
[ 'test.foo', ResourceLoaderModule::TYPE_SCRIPTS ],
// Single only=scripts load
[
[ 'test.foo', ResourceLoaderModule::TYPE_SCRIPTS ],
- "<script nonce=\"secret\">(window.RLQ=window.RLQ||[]).push(function(){"
+ "<script nonce=\"secret\">(RLQ=window.RLQ||[]).push(function(){"
. 'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.foo\u0026only=scripts\u0026skin=fallback");'
. "});</script>"
],
. 'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.foo\u0026only=scripts\u0026skin=fallback");'
. "});</script>"
],
// Private embed (only=scripts)
[
[ 'test.quux', ResourceLoaderModule::TYPE_SCRIPTS ],
// Private embed (only=scripts)
[
[ 'test.quux', ResourceLoaderModule::TYPE_SCRIPTS ],
- "<script nonce=\"secret\">(window.RLQ=window.RLQ||[]).push(function(){"
+ "<script nonce=\"secret\">(RLQ=window.RLQ||[]).push(function(){"
. "mw.test.baz({token:123});\nmw.loader.state({\"test.quux\":\"ready\"});"
. "});</script>"
],
// Load private module (combined)
[
[ 'test.quux', ResourceLoaderModule::TYPE_COMBINED ],
. "mw.test.baz({token:123});\nmw.loader.state({\"test.quux\":\"ready\"});"
. "});</script>"
],
// Load private module (combined)
[
[ 'test.quux', ResourceLoaderModule::TYPE_COMBINED ],
- "<script nonce=\"secret\">(window.RLQ=window.RLQ||[]).push(function(){"
+ "<script nonce=\"secret\">(RLQ=window.RLQ||[]).push(function(){"
. "mw.loader.implement(\"test.quux@1ev0ijv\",function($,jQuery,require,module){"
. "mw.test.baz({token:123});},{\"css\":[\".mw-icon{transition:none}"
. "\"]});});</script>"
. "mw.loader.implement(\"test.quux@1ev0ijv\",function($,jQuery,require,module){"
. "mw.test.baz({token:123});},{\"css\":[\".mw-icon{transition:none}"
. "\"]});});</script>"
// Load two modules in separate groups
[
[ [ 'test.group.foo', 'test.group.bar' ], ResourceLoaderModule::TYPE_COMBINED ],
// Load two modules in separate groups
[
[ [ 'test.group.foo', 'test.group.bar' ], ResourceLoaderModule::TYPE_COMBINED ],
- "<script nonce=\"secret\">(window.RLQ=window.RLQ||[]).push(function(){"
+ "<script nonce=\"secret\">(RLQ=window.RLQ||[]).push(function(){"
. 'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.group.bar\u0026skin=fallback");'
. 'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.group.foo\u0026skin=fallback");'
. "});</script>"
. 'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.group.bar\u0026skin=fallback");'
. 'mw.loader.load("http://127.0.0.1:8080/w/load.php?lang=en\u0026modules=test.group.foo\u0026skin=fallback");'
. "});</script>"
. 'RLSTATE={"test.exempt":"ready","test.private":"loading","test.styles.pure":"ready","test.styles.private":"ready","test.styles.deprecated":"ready"};'
. 'RLPAGEMODULES=["test"];'
. '</script>' . "\n"
. 'RLSTATE={"test.exempt":"ready","test.private":"loading","test.styles.pure":"ready","test.styles.private":"ready","test.styles.deprecated":"ready"};'
. 'RLPAGEMODULES=["test"];'
. '</script>' . "\n"
- . '<script>(window.RLQ=window.RLQ||[]).push(function(){'
+ . '<script>(RLQ=window.RLQ||[]).push(function(){'
. 'mw.loader.implement("test.private@{blankVer}",null,{"css":[]});'
. '});</script>' . "\n"
. '<link rel="stylesheet" href="/w/load.php?lang=nl&modules=test.styles.deprecated%2Cpure&only=styles&skin=fallback"/>' . "\n"
. 'mw.loader.implement("test.private@{blankVer}",null,{"css":[]});'
. '});</script>' . "\n"
. '<link rel="stylesheet" href="/w/load.php?lang=nl&modules=test.styles.deprecated%2Cpure&only=styles&skin=fallback"/>' . "\n"
'test.styles.deprecated',
] );
// phpcs:disable Generic.Files.LineLength
'test.styles.deprecated',
] );
// phpcs:disable Generic.Files.LineLength
- $expected = '<script>(window.RLQ=window.RLQ||[]).push(function(){'
+ $expected = '<script>(RLQ=window.RLQ||[]).push(function(){'
. 'mw.log.warn("This page is using the deprecated ResourceLoader module \"test.styles.deprecated\".\nDeprecation message.");'
. '});</script>';
// phpcs:enable
. 'mw.log.warn("This page is using the deprecated ResourceLoader module \"test.styles.deprecated\".\nDeprecation message.");'
. '});</script>';
// phpcs:enable
'modules' => [ 'test.private' ],
'only' => ResourceLoaderModule::TYPE_COMBINED,
'extra' => [],
'modules' => [ 'test.private' ],
'only' => ResourceLoaderModule::TYPE_COMBINED,
'extra' => [],
- 'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.private@{blankVer}",null,{"css":[]});});</script>',
+ 'output' => '<script>(RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.private@{blankVer}",null,{"css":[]});});</script>',
'modules' => [ 'test.scripts.user' ],
'only' => ResourceLoaderModule::TYPE_SCRIPTS,
'extra' => [],
'modules' => [ 'test.scripts.user' ],
'only' => ResourceLoaderModule::TYPE_SCRIPTS,
'extra' => [],
- 'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test.scripts.user\u0026only=scripts\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
+ 'output' => '<script>(RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test.scripts.user\u0026only=scripts\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
],
[
'context' => [],
'modules' => [ 'test.user' ],
'only' => ResourceLoaderModule::TYPE_COMBINED,
'extra' => [],
],
[
'context' => [],
'modules' => [ 'test.user' ],
'only' => ResourceLoaderModule::TYPE_COMBINED,
'extra' => [],
- 'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test.user\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
+ 'output' => '<script>(RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test.user\u0026skin=fallback\u0026user=Example\u0026version=0a56zyi");});</script>',
],
[
'context' => [ 'debug' => 'true' ],
],
[
'context' => [ 'debug' => 'true' ],
'modules' => [ 'test.shouldembed' ],
'only' => ResourceLoaderModule::TYPE_COMBINED,
'extra' => [],
'modules' => [ 'test.shouldembed' ],
'only' => ResourceLoaderModule::TYPE_COMBINED,
'extra' => [],
- 'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.shouldembed@09p30q0",null,{"css":[]});});</script>',
+ 'output' => '<script>(RLQ=window.RLQ||[]).push(function(){mw.loader.implement("test.shouldembed@09p30q0",null,{"css":[]});});</script>',
'modules' => [ 'test.scripts.shouldembed' ],
'only' => ResourceLoaderModule::TYPE_SCRIPTS,
'extra' => [],
'modules' => [ 'test.scripts.shouldembed' ],
'only' => ResourceLoaderModule::TYPE_SCRIPTS,
'extra' => [],
- 'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.state({"test.scripts.shouldembed":"ready"});});</script>',
+ 'output' => '<script>(RLQ=window.RLQ||[]).push(function(){mw.loader.state({"test.scripts.shouldembed":"ready"});});</script>',
],
[
'context' => [],
'modules' => [ 'test', 'test.shouldembed' ],
'only' => ResourceLoaderModule::TYPE_COMBINED,
'extra' => [],
],
[
'context' => [],
'modules' => [ 'test', 'test.shouldembed' ],
'only' => ResourceLoaderModule::TYPE_COMBINED,
'extra' => [],
- 'output' => '<script>(window.RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test\u0026skin=fallback");mw.loader.implement("test.shouldembed@09p30q0",null,{"css":[]});});</script>',
+ 'output' => '<script>(RLQ=window.RLQ||[]).push(function(){mw.loader.load("/w/load.php?lang=nl\u0026modules=test\u0026skin=fallback");mw.loader.implement("test.shouldembed@09p30q0",null,{"css":[]});});</script>',