Merge "Add part to update ctd_user_defined in populateChangeTagDef"
[lhc/web/wiklou.git] / resources / src / startup / startup.js
index c609852..5483ad2 100644 (file)
@@ -3,8 +3,8 @@
  *
  * - Beware: This file MUST parse without errors on even the most ancient of browsers!
  */
-/* eslint-disable vars-on-top, no-unmodified-loop-condition */
-/* global mw, isCompatible, $VARS, $CODE */
+/* eslint-disable no-implicit-globals, vars-on-top, no-unmodified-loop-condition */
+/* global $VARS, $CODE */
 
 /**
  * See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
@@ -47,7 +47,7 @@
  * @param {string} [str] User agent, defaults to navigator.userAgent
  * @return {boolean} User agent is compatible with MediaWiki JS
  */
-window.isCompatible = function ( str ) {
+function isCompatible( str ) {
        var ua = str || navigator.userAgent;
        return !!(
                // https://caniuse.com/#feat=es5
@@ -55,7 +55,7 @@ window.isCompatible = function ( str ) {
                // https://caniuse.com/#feat=json / https://phabricator.wikimedia.org/T141344#2784065
                ( function () {
                        'use strict';
-                       return !this && !!Function.prototype.bind && !!window.JSON;
+                       return !this && Function.prototype.bind && window.JSON;
                }() ) &&
 
                // https://caniuse.com/#feat=queryselector
@@ -72,44 +72,45 @@ window.isCompatible = function ( str ) {
                // 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/ ) ||
-                       ua.match( /PlayStation/i )
-               )
+               !ua.match( /MSIE 10|webOS\/1\.[0-4]|SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight|PLAYSTATION|PlayStation/ )
        );
-};
+}
 
-( function () {
-       var NORLQ, script;
+if ( !isCompatible() ) {
        // Handle Grade C
-       if ( !isCompatible() ) {
-               // Undo speculative Grade A <html> class. See ResourceLoaderClientHtml::getDocumentAttributes().
-               document.documentElement.className = document.documentElement.className
-                       .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
+       // Undo speculative Grade A <html> class. See ResourceLoaderClientHtml::getDocumentAttributes().
+       document.documentElement.className = document.documentElement.className
+               .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
 
-               // Process any callbacks for Grade C
-               NORLQ = window.NORLQ;
-               while ( NORLQ && NORLQ[ 0 ] ) {
-                       NORLQ.shift()();
+       // Process any callbacks for Grade C
+       while ( window.NORLQ && window.NORLQ[ 0 ] ) {
+               window.NORLQ.shift()();
+       }
+       window.NORLQ = {
+               push: function ( fn ) {
+                       fn();
                }
-               window.NORLQ = {
-                       push: function ( fn ) {
-                               fn();
-                       }
-               };
+       };
 
-               // Clear and disable the Grade A queue
-               window.RLQ = {
-                       push: function () {}
-               };
+       // Clear and disable the Grade A queue
+       window.RLQ = {
+               push: function () {}
+       };
+} else {
+       // Handle Grade A
 
-               return;
+       if ( window.performance && performance.mark ) {
+               performance.mark( 'mwStartup' );
        }
 
+       // This embeds mediawiki.js, which defines 'mw' and 'mw.loader'.
+       $CODE.defineLoader();
+
        /**
         * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
         */
-       function startUp() {
+       ( function () {
+               /* global mw */
                mw.config = new mw.Map( $VARS.wgLegacyJavaScriptGlobals );
 
                $CODE.registrations();
@@ -119,42 +120,25 @@ window.isCompatible = function ( str ) {
                // Process callbacks for Grade A
                // Must be after registrations and mw.config.set, which mw.loader depends on.
                var queue = window.RLQ;
-               window.RLQ = {
-                       push: function ( fn ) {
-                               if ( typeof fn === 'function' ) {
-                                       fn();
-                               } else {
-                                       // This callback has a requirement.
-                                       mw.loader.using( fn[ 0 ], fn[ 1 ] );
-                               }
+               // Redefine push(), but keep type as array for storing callbacks that require modules.
+               window.RLQ = [];
+               /* global RLQ */
+               RLQ.push = function ( fn ) {
+                       if ( typeof fn === 'function' ) {
+                               fn();
+                       } else {
+                               // This callback requires a module, handled in mediawiki.base.
+                               RLQ[ RLQ.length ] = fn;
                        }
                };
                while ( queue && queue[ 0 ] ) {
                        // Re-use our push()
-                       window.RLQ.push( queue.shift() );
+                       RLQ.push( queue.shift() );
                }
 
                // Clear and disable the Grade C queue
                window.NORLQ = {
                        push: function () {}
                };
-       }
-
-       if ( window.performance && performance.mark ) {
-               performance.mark( 'mwStartup' );
-       }
-
-       // This embeds mediawiki.js, which defines 'mw' and 'mw.loader'.
-       $CODE.defineLoader();
-
-       script = document.createElement( 'script' );
-       script.src = $VARS.baseModulesUri;
-       script.onload = function () {
-               // Clean up
-               script.onload = null;
-               script = null;
-               // Callback
-               startUp();
-       };
-       document.head.appendChild( script );
-}() );
+       }() );
+}