2 * This script provides a function which is run to evaluate whether or not to
3 * continue loading jQuery and the MediaWiki modules. This code should work on
4 * even the most ancient of browsers, so be very careful when editing.
6 /*jshint unused: false, evil: true */
7 /*globals mw, RLQ: true, $VARS, $CODE, performance */
9 var mediaWikiLoadStart
= ( new Date() ).getTime(),
11 mwPerformance
= ( window
.performance
&& performance
.mark
) ? performance
: {
15 mwPerformance
.mark( 'mwLoadStart' );
18 * Returns false for Grade C supported browsers.
20 * This function should only be used by the Startup module, do not expand it to
21 * be generally useful beyond startup.
24 * - https://www.mediawiki.org/wiki/Compatibility#Browsers
25 * - https://jquery.com/browser-support/
27 function isCompatible( ua
) {
28 if ( ua
=== undefined ) {
29 ua
= navigator
.userAgent
;
32 // Browsers with outdated or limited JavaScript engines get the no-JS experience
34 // Internet Explorer < 9
35 ( ua
.indexOf( 'MSIE' ) !== -1 && parseFloat( ua
.split( 'MSIE' )[ 1 ] ) < 9 ) ||
37 ( ua
.indexOf( 'Firefox/' ) !== -1 && parseFloat( ua
.split( 'Firefox/' )[ 1 ] ) < 3 ) ||
39 ( ua
.indexOf( 'Opera/' ) !== -1 && ( ua
.indexOf( 'Version/' ) === -1 ?
41 parseFloat( ua
.split( 'Opera/' )[ 1 ] ) < 10 :
42 // "Opera/9.80 ... Version/x.y"
43 parseFloat( ua
.split( 'Version/' )[ 1 ] ) < 12
45 // "Mozilla/0.0 ... Opera x.y"
46 ( ua
.indexOf( 'Opera ' ) !== -1 && parseFloat( ua
.split( ' Opera ' )[ 1 ] ) < 10 ) ||
48 ua
.match( /BlackBerry[^\/]*\/[1-5]\./ ) ||
50 ua
.match( /webOS\/1\.[0-4]/ ) ||
51 // Anything PlayStation based.
52 ua
.match( /PlayStation/i ) ||
53 // Any Symbian based browsers
54 ua
.match( /SymbianOS|Series60/ ) ||
55 // Any NetFront based browser
56 ua
.match( /NetFront/ ) ||
57 // Opera Mini, all versions
58 ua
.match( /Opera Mini/ ) ||
59 // Nokia's Ovi Browser
60 ua
.match( /S40OviBrowser/ ) ||
62 ua
.match( /MeeGo/ ) ||
63 // Google Glass browser groks JS but UI is too limited
64 ( ua
.match( /Glass/ ) && ua
.match( /Android/ ) )
68 // Conditional script injection
70 if ( !isCompatible() ) {
71 // Undo class swapping in case of an unsupported browser.
72 // See OutputPage::getHeadScripts().
73 document
.documentElement
.className
= document
.documentElement
.className
74 .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
79 * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
82 mw
.config
= new mw
.Map( $VARS
.wgLegacyJavaScriptGlobals
);
84 $CODE
.registrations();
86 mw
.config
.set( $VARS
.configuration
);
88 // Must be after mw.config.set because these callbacks may use mw.loader which
89 // needs to have values 'skin', 'debug' etc. from mw.config.
90 var RLQ
= window
.RLQ
|| [];
91 while ( RLQ
.length
) {
95 push: function ( fn
) {
101 var script
= document
.createElement( 'script' );
102 script
.src
= $VARS
.baseModulesUri
;
103 script
.onload
= script
.onreadystatechange = function () {
104 if ( !script
.readyState
|| /loaded|complete/.test( script
.readyState
) ) {
106 script
.onload
= script
.onreadystatechange
= null;
112 document
.getElementsByTagName( 'head' )[ 0 ].appendChild( script
);