Merge "Don't fallback from uk to ru"
[lhc/web/wiklou.git] / resources / src / mediawiki.legacy / wikibits.js
1 /**
2 * MediaWiki legacy wikibits
3 */
4 ( function ( mw, $ ) {
5 var msg,
6 win = window,
7 ua = navigator.userAgent.toLowerCase(),
8 onloadFuncts = [],
9 loadedScripts = {};
10
11 /**
12 * User-agent sniffing.
13 *
14 * @deprecated since 1.17 Use jquery.client instead
15 */
16
17 msg = 'Use feature detection or module jquery.client instead.';
18
19 mw.log.deprecate( win, 'clientPC', ua, msg );
20
21 // Ignored dummy values
22 mw.log.deprecate( win, 'is_gecko', false, msg );
23 mw.log.deprecate( win, 'is_chrome_mac', false, msg );
24 mw.log.deprecate( win, 'is_chrome', false, msg );
25 mw.log.deprecate( win, 'webkit_version', false, msg );
26 mw.log.deprecate( win, 'is_safari_win', false, msg );
27 mw.log.deprecate( win, 'is_safari', false, msg );
28 mw.log.deprecate( win, 'webkit_match', false, msg );
29 mw.log.deprecate( win, 'is_ff2', false, msg );
30 mw.log.deprecate( win, 'ff2_bugs', false, msg );
31 mw.log.deprecate( win, 'is_ff2_win', false, msg );
32 mw.log.deprecate( win, 'is_ff2_x11', false, msg );
33 mw.log.deprecate( win, 'opera95_bugs', false, msg );
34 mw.log.deprecate( win, 'opera7_bugs', false, msg );
35 mw.log.deprecate( win, 'opera6_bugs', false, msg );
36 mw.log.deprecate( win, 'is_opera_95', false, msg );
37 mw.log.deprecate( win, 'is_opera_preseven', false, msg );
38 mw.log.deprecate( win, 'is_opera', false, msg );
39 mw.log.deprecate( win, 'ie6_bugs', false, msg );
40
41 /**
42 * DOM utilities for handling of events, text nodes and selecting elements
43 *
44 * @deprecated since 1.17 Use jQuery instead
45 */
46 msg = 'Use jQuery instead.';
47
48 // Ignored dummy values
49 mw.log.deprecate( win, 'doneOnloadHook', undefined, msg );
50 mw.log.deprecate( win, 'onloadFuncts', [], msg );
51 mw.log.deprecate( win, 'runOnloadHook', $.noop, msg );
52 mw.log.deprecate( win, 'changeText', $.noop, msg );
53 mw.log.deprecate( win, 'killEvt', $.noop, msg );
54 mw.log.deprecate( win, 'addHandler', $.noop, msg );
55 mw.log.deprecate( win, 'hookEvent', $.noop, msg );
56 mw.log.deprecate( win, 'addClickHandler', $.noop, msg );
57 mw.log.deprecate( win, 'removeHandler', $.noop, msg );
58 mw.log.deprecate( win, 'getElementsByClassName', function () { return []; }, msg );
59 mw.log.deprecate( win, 'getInnerText', function () { return ''; }, msg );
60
61 // Run a function after the window onload event is fired
62 mw.log.deprecate( win, 'addOnloadHook', function ( hookFunct ) {
63 if ( onloadFuncts ) {
64 onloadFuncts.push( hookFunct );
65 } else {
66 // If func queue is gone the event has happened already,
67 // run immediately instead of queueing.
68 hookFunct();
69 }
70 }, msg );
71
72 $( win ).on( 'load', function () {
73 var i, functs;
74
75 // Don't run twice
76 if ( !onloadFuncts ) {
77 return;
78 }
79
80 // Deference and clear onloadFuncts before running any
81 // hooks to make sure we don't miss any addOnloadHook
82 // calls.
83 functs = onloadFuncts.slice();
84 onloadFuncts = undefined;
85
86 // Execute the queued functions
87 for ( i = 0; i < functs.length; i++ ) {
88 functs[ i ]();
89 }
90 } );
91
92 /**
93 * Toggle checkboxes with shift selection
94 *
95 * @deprecated since 1.17 Use jquery.checkboxShiftClick instead
96 */
97 msg = 'Use jquery.checkboxShiftClick instead.';
98 mw.log.deprecate( win, 'checkboxes', [], msg );
99 mw.log.deprecate( win, 'lastCheckbox', null, msg );
100 mw.log.deprecate( win, 'setupCheckboxShiftClick', $.noop, msg );
101 mw.log.deprecate( win, 'addCheckboxClickHandlers', $.noop, msg );
102 mw.log.deprecate( win, 'checkboxClickHandler', $.noop, msg );
103
104 /**
105 * Add a button to the default editor toolbar
106 *
107 * @deprecated since 1.17 Use mw.toolbar instead
108 */
109 mw.log.deprecate( win, 'mwEditButtons', [], 'Use mw.toolbar instead.' );
110 mw.log.deprecate( win, 'mwCustomEditButtons', [], 'Use mw.toolbar instead.' );
111
112 /**
113 * Spinner creation, injection and removal
114 *
115 * @deprecated since 1.18 Use jquery.spinner instead
116 */
117 mw.log.deprecate( win, 'injectSpinner', $.noop, 'Use jquery.spinner instead.' );
118 mw.log.deprecate( win, 'removeSpinner', $.noop, 'Use jquery.spinner instead.' );
119
120 /**
121 * Escape utilities
122 *
123 * @deprecated since 1.18 Use mw.html instead
124 */
125 mw.log.deprecate( win, 'escapeQuotes', $.noop, 'Use mw.html instead.' );
126 mw.log.deprecate( win, 'escapeQuotesHTML', $.noop, 'Use mw.html instead.' );
127
128 /**
129 * Display a message to the user
130 *
131 * @deprecated since 1.17 Use mediawiki.notify instead
132 * @param {string|HTMLElement} message To be put inside the message box
133 */
134 mw.log.deprecate( win, 'jsMsg', function ( message ) {
135 if ( !arguments.length || message === '' || message === null ) {
136 return true;
137 }
138 if ( typeof message !== 'object' ) {
139 message = $.parseHTML( message );
140 }
141 mw.notify( message, { autoHide: true, tag: 'legacy' } );
142 return true;
143 }, 'Use mediawiki.notify instead.' );
144
145 /**
146 * Misc. utilities
147 *
148 * @deprecated since 1.17 Use mediawiki.util or jquery.accessKeyLabel instead
149 */
150 msg = 'Use mediawiki.util instead.';
151 mw.log.deprecate( win, 'addPortletLink', mw.util.addPortletLink, msg );
152 mw.log.deprecate( win, 'appendCSS', mw.util.addCSS, msg );
153 msg = 'Use jquery.accessKeyLabel instead.';
154 mw.log.deprecate( win, 'tooltipAccessKeyPrefix', 'alt-', msg );
155 mw.log.deprecate( win, 'tooltipAccessKeyRegexp', /\[(alt-)?(.)\]$/, msg );
156 // mw.util.updateTooltipAccessKeys already generates a deprecation message.
157 win.updateTooltipAccessKeys = function () {
158 return mw.util.updateTooltipAccessKeys.apply( null, arguments );
159 };
160
161 /**
162 * Wikipage import methods
163 *
164 * See https://www.mediawiki.org/wiki/ResourceLoader/Legacy_JavaScript#wikibits.js
165 */
166
167 /**
168 * @deprecated since 1.17 Use mw.loader instead. Warnings added in 1.25.
169 * @param {string} url
170 * @return {HTMLElement} Script tag
171 */
172 function importScriptURI( url ) {
173 var s;
174 if ( loadedScripts[ url ] ) {
175 return null;
176 }
177 loadedScripts[ url ] = true;
178 s = document.createElement( 'script' );
179 s.setAttribute( 'src', url );
180 document.getElementsByTagName( 'head' )[ 0 ].appendChild( s );
181 return s;
182 }
183
184 function importScript( page ) {
185 var uri = mw.config.get( 'wgScript' ) + '?title=' +
186 mw.util.wikiUrlencode( page ) +
187 '&action=raw&ctype=text/javascript';
188 return importScriptURI( uri );
189 }
190
191 /**
192 * @deprecated since 1.17 Use mw.loader instead. Warnings added in 1.25.
193 * @param {string} url
194 * @param {string} media
195 * @return {HTMLElement} Link tag
196 */
197 function importStylesheetURI( url, media ) {
198 var l = document.createElement( 'link' );
199 l.rel = 'stylesheet';
200 l.href = url;
201 if ( media ) {
202 l.media = media;
203 }
204 document.getElementsByTagName( 'head' )[ 0 ].appendChild( l );
205 return l;
206 }
207
208 function importStylesheet( page ) {
209 var uri = mw.config.get( 'wgScript' ) + '?title=' +
210 mw.util.wikiUrlencode( page ) +
211 '&action=raw&ctype=text/css';
212 return importStylesheetURI( uri );
213 }
214
215 msg = 'Use mw.loader instead.';
216 mw.log.deprecate( win, 'loadedScripts', loadedScripts, msg );
217 mw.log.deprecate( win, 'importScriptURI', importScriptURI, msg );
218 mw.log.deprecate( win, 'importStylesheetURI', importStylesheetURI, msg );
219 // Not quite deprecated yet.
220 win.importScript = importScript;
221 win.importStylesheet = importStylesheet;
222
223 // Replace document.write/writeln with basic html parsing that appends
224 // to the <body> to avoid blanking pages. Added JavaScript will not run.
225 $.each( [ 'write', 'writeln' ], function ( idx, method ) {
226 mw.log.deprecate( document, method, function () {
227 $( 'body' ).append( $.parseHTML( Array.prototype.join.call( arguments, '' ) ) );
228 }, 'Use jQuery or mw.loader.load instead.' );
229 } );
230
231 }( mediaWiki, jQuery ) );