X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=resources%2Fsrc%2Fstartup%2Fstartup.js;h=bebf4dcf4aabf17f14c93c14976a72c432d9668f;hb=04d1aa3033f40a38d721f7f0e88b5bac440d2869;hp=8e75535b2a74883ba97147a44987eaf2662c1833;hpb=b8010e74a998aa38a3a84f2cf2ea6dcc0cee167b;p=lhc%2Fweb%2Fwiklou.git diff --git a/resources/src/startup/startup.js b/resources/src/startup/startup.js index 8e75535b2a..da048ffdff 100644 --- a/resources/src/startup/startup.js +++ b/resources/src/startup/startup.js @@ -3,8 +3,8 @@ * * - 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 @@ -44,11 +44,11 @@ * * Other browsers that pass the check are considered Grade X. * - * @param {string} [str] User agent, defaults to navigator.userAgent + * @private + * @param {string} ua User agent string * @return {boolean} User agent is compatible with MediaWiki JS */ -function isCompatible( str ) { - var ua = str || navigator.userAgent; +function isCompatible( ua ) { return !!( // https://caniuse.com/#feat=es5 // https://caniuse.com/#feat=use-strict @@ -69,31 +69,33 @@ function isCompatible( str ) { // https://caniuse.com/#feat=addeventlistener 'addEventListener' in window && - // Hardcoded exceptions for browsers that pass the requirement but we don't want to - // support in the modern run-time. - // Note: Please extend the regex instead of adding new ones - !ua.match( /MSIE 10|webOS\/1\.[0-4]|SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight|PLAYSTATION|PlayStation/ ) + // Hardcoded exceptions for browsers that pass the requirement but we don't + // want to support in the modern run-time. + // + // Please extend the regex instead of adding new ones! + // And add a test case to startup.test.js + !ua.match( /MSIE 10|webOS\/1\.[0-4]|SymbianOS|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight|PLAYSTATION|PlayStation/ ) ); } -if ( !isCompatible() ) { +if ( !isCompatible( navigator.userAgent ) ) { // Handle Grade C // Undo speculative Grade A class. See ResourceLoaderClientHtml::getDocumentAttributes(). document.documentElement.className = document.documentElement.className .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()(); } - window.NORLQ = { + NORLQ = { push: function ( fn ) { fn(); } }; // Clear and disable the Grade A queue - window.RLQ = { + RLQ = { push: function () {} }; } else { @@ -110,33 +112,50 @@ if ( !isCompatible() ) { * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php. */ ( function () { + /* global mw */ mw.config = new mw.Map( $VARS.wgLegacyJavaScriptGlobals ); $CODE.registrations(); mw.config.set( $VARS.configuration ); + // For the current page + mw.config.set( window.RLCONF || {} ); + mw.loader.state( window.RLSTATE || {} ); + mw.loader.load( window.RLPAGEMODULES || [] ); - // Process callbacks for Grade A - // Must be after registrations and mw.config.set, which mw.loader depends on. - var queue = window.RLQ; - // Redefine push(), but keep type as array for storing callbacks that require modules. - window.RLQ = []; - /* global RLQ */ + // Process RLQ callbacks + // + // The code in these callbacks could've been exposed from load.php and + // requested client-side. Instead, they are pushed by the server directly + // (from ResourceLoaderClientHtml and other parts of MediaWiki). This + // saves the need for additional round trips. It also allows load.php + // to remain stateless and sending personal data in the HTML instead. + // + // The HTML inline script lazy-defines the 'RLQ' array. Now that we are + // processing it, replace it with an implementation where 'push' actually + // considers executing the code directly. This is to ensure any late + // arrivals will also be processed. Late arrival can happen because + // startup.js is executed asynchronously, concurrently with the streaming + // response of the HTML. + RLQ = window.RLQ || []; 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; } }; - while ( queue && queue[ 0 ] ) { - // Re-use our push() - RLQ.push( queue.shift() ); + while ( RLQ[ 0 ] ) { + // Process all values gathered so far + RLQ.push( RLQ.shift() ); } // Clear and disable the Grade C queue - window.NORLQ = { + NORLQ = { push: function () {} }; }() );