2 * This file is where we decide whether to initialise the Grade A run-time.
4 * - Beware: This file MUST parse without errors on even the most ancient of browsers!
6 /* eslint-disable vars-on-top, no-unmodified-loop-condition */
7 /* global mw, isCompatible, $VARS, $CODE */
10 * See <https://www.mediawiki.org/wiki/Compatibility#Browsers>
12 * Capabilities required for modern run-time:
14 * - DOM Level 4 & Selectors API Level 1
15 * - HTML5 & Web Storage
16 * - DOM Level 2 Events
18 * Browsers we support in our modern run-time (Grade A):
24 * - Mobile Safari 6.0+ (iOS 6+)
27 * Browsers we support in our no-javascript run-time (Grade C):
33 * - Mobile Safari 5.0+ (iOS 4+)
37 * - Symbian-based browsers
38 * - NetFront-based browser
40 * - Nokia's Ovi Browser
43 * - UC Mini (speed mode on)
45 * Other browsers that pass the check are considered Grade X.
47 * @param {string} [str] User agent, defaults to navigator.userAgent
48 * @return {boolean} User agent is compatible with MediaWiki JS
50 window
.isCompatible = function ( str
) {
51 var ua
= str
|| navigator
.userAgent
;
53 // https://caniuse.com/#feat=es5
54 // https://caniuse.com/#feat=use-strict
55 // https://caniuse.com/#feat=json / https://phabricator.wikimedia.org/T141344#2784065
58 return !this && !!Function
.prototype.bind
&& !!window
.JSON
;
61 // https://caniuse.com/#feat=queryselector
62 'querySelector' in document
&&
64 // https://caniuse.com/#feat=namevalue-storage
65 // https://developer.blackberry.com/html5/apis/v1_0/localstorage.html
66 // https://blog.whatwg.org/this-week-in-html-5-episode-30
67 'localStorage' in window
&&
69 // https://caniuse.com/#feat=addeventlistener
70 'addEventListener' in window
&&
72 // Hardcoded exceptions for browsers that pass the requirement but we don't want to
73 // support in the modern run-time.
74 // Note: Please extend the regex instead of adding new ones
76 ua
.match( /MSIE 10|webOS\/1\.[0-4]|SymbianOS|Series60|NetFront|Opera Mini|S40OviBrowser|MeeGo|Android.+Glass|^Mozilla\/5\.0 .+ Gecko\/$|googleweblight/ ) ||
77 ua
.match( /PlayStation/i )
85 if ( !isCompatible() ) {
86 // Undo speculative Grade A <html> class. See ResourceLoaderClientHtml::getDocumentAttributes().
87 document
.documentElement
.className
= document
.documentElement
.className
88 .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
90 // Process any callbacks for Grade C
92 while ( NORLQ
&& NORLQ
[ 0 ] ) {
96 push: function ( fn
) {
101 // Clear and disable the Grade A queue
110 * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
113 mw
.config
= new mw
.Map( $VARS
.wgLegacyJavaScriptGlobals
);
115 $CODE
.registrations();
117 mw
.config
.set( $VARS
.configuration
);
119 // Process callbacks for Grade A
120 // Must be after registrations and mw.config.set, which mw.loader depends on.
121 var queue
= window
.RLQ
;
122 // Redefine push(), but keep type as array for storing callbacks that require modules.
125 RLQ
.push = function ( fn
) {
126 if ( typeof fn
=== 'function' ) {
129 // This callback requires a module, handled in mediawiki.base.
130 RLQ
[ RLQ
.length
] = fn
;
133 while ( queue
&& queue
[ 0 ] ) {
135 RLQ
.push( queue
.shift() );
138 // Clear and disable the Grade C queue
144 if ( window
.performance
&& performance
.mark
) {
145 performance
.mark( 'mwStartup' );
148 // This embeds mediawiki.js, which defines 'mw' and 'mw.loader'.
149 $CODE
.defineLoader();
151 mw
.requestIdleCallback( startUp
);