Merge "Revert "Add executable rights for executable (bash) files""
[lhc/web/wiklou.git] / resources / src / startup.js
1 /**
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.
5 */
6
7 var mediaWikiLoadStart = ( new Date() ).getTime();
8
9 if ( !window.performance ) {
10 window.performance = {};
11 }
12 if ( !performance.mark ) {
13 performance.mark = function () {};
14 }
15 performance.mark( 'mediaWikiStartUp' );
16
17 /**
18 * Returns false for Grade C supported browsers.
19 *
20 * This function should only be used by the Startup module, do not expand it to
21 * be generally useful beyond startup.
22 *
23 * See also:
24 * - https://www.mediawiki.org/wiki/Compatibility#Browsers
25 * - https://jquery.com/browser-support/
26 */
27
28 /*jshint unused: false, evil: true */
29 /*globals mw, RLQ: true, $VARS, $CODE */
30 function isCompatible( ua ) {
31 if ( ua === undefined ) {
32 ua = navigator.userAgent;
33 }
34
35 // Browsers with outdated or limited JavaScript engines get the no-JS experience
36 return !(
37 // Internet Explorer < 8
38 ( ua.indexOf( 'MSIE' ) !== -1 && parseFloat( ua.split( 'MSIE' )[1] ) < 8 ) ||
39 // Firefox < 3
40 ( ua.indexOf( 'Firefox/' ) !== -1 && parseFloat( ua.split( 'Firefox/' )[1] ) < 3 ) ||
41 // Opera < 12
42 ( ua.indexOf( 'Opera/' ) !== -1 && ( ua.indexOf( 'Version/' ) === -1 ?
43 // "Opera/x.y"
44 parseFloat( ua.split( 'Opera/' )[1] ) < 10 :
45 // "Opera/9.80 ... Version/x.y"
46 parseFloat( ua.split( 'Version/' )[1] ) < 12
47 ) ) ||
48 // "Mozilla/0.0 ... Opera x.y"
49 ( ua.indexOf( 'Opera ' ) !== -1 && parseFloat( ua.split( ' Opera ' )[1] ) < 10 ) ||
50 // BlackBerry < 6
51 ua.match( /BlackBerry[^\/]*\/[1-5]\./ ) ||
52 // Open WebOS < 1.5
53 ua.match( /webOS\/1\.[0-4]/ ) ||
54 // Anything PlayStation based.
55 ua.match( /PlayStation/i ) ||
56 // Any Symbian based browsers
57 ua.match( /SymbianOS|Series60/ ) ||
58 // Any NetFront based browser
59 ua.match( /NetFront/ ) ||
60 // Opera Mini, all versions
61 ua.match( /Opera Mini/ ) ||
62 // Nokia's Ovi Browser
63 ua.match( /S40OviBrowser/ ) ||
64 // MeeGo's browser
65 ua.match( /MeeGo/ ) ||
66 // Google Glass browser groks JS but UI is too limited
67 ( ua.match( /Glass/ ) && ua.match( /Android/ ) )
68 );
69 }
70
71 /**
72 * The $CODE and $VARS placeholders are substituted in ResourceLoaderStartUpModule.php.
73 */
74 function startUp() {
75 mw.config = new mw.Map( $VARS.wgLegacyJavaScriptGlobals );
76
77 $CODE.registrations();
78
79 mw.config.set( $VARS.configuration );
80
81 // Must be after mw.config.set because these callbacks may use mw.loader which
82 // needs to have values 'skin', 'debug' etc. from mw.config.
83 window.RLQ = window.RLQ || [];
84 while ( RLQ.length ) {
85 RLQ.shift()();
86 }
87 window.RLQ = {
88 push: function ( fn ) {
89 fn();
90 }
91 };
92 }
93
94 // Conditional script injection
95 if ( isCompatible() ) {
96 ( function () {
97 var script = document.createElement( 'script' );
98 script.src = $VARS.baseModulesUri;
99 document.getElementsByTagName( 'head' )[0].appendChild( script );
100 }() );
101 } else {
102 // Undo class swapping in case of an unsupported browser.
103 // See OutputPage::getHeadScripts().
104 document.documentElement.className = document.documentElement.className
105 .replace( /(^|\s)client-js(\s|$)/, '$1client-nojs$2' );
106 }