Merge "Add tests for WikiMap and WikiReference"
[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 */
170 function importScriptURI( url ) {
171 if ( loadedScripts[ url ] ) {
172 return null;
173 }
174 loadedScripts[ url ] = true;
175 var s = document.createElement( 'script' );
176 s.setAttribute( 'src', url );
177 s.setAttribute( 'type', 'text/javascript' );
178 document.getElementsByTagName( 'head' )[ 0 ].appendChild( s );
179 return s;
180 }
181
182 function importScript( page ) {
183 var uri = mw.config.get( 'wgScript' ) + '?title=' +
184 mw.util.wikiUrlencode( page ) +
185 '&action=raw&ctype=text/javascript';
186 return importScriptURI( uri );
187 }
188
189 /**
190 * @deprecated since 1.17 Use mw.loader instead. Warnings added in 1.25.
191 */
192 function importStylesheetURI( url, media ) {
193 var l = document.createElement( 'link' );
194 l.rel = 'stylesheet';
195 l.href = url;
196 if ( media ) {
197 l.media = media;
198 }
199 document.getElementsByTagName( 'head' )[ 0 ].appendChild( l );
200 return l;
201 }
202
203 function importStylesheet( page ) {
204 var uri = mw.config.get( 'wgScript' ) + '?title=' +
205 mw.util.wikiUrlencode( page ) +
206 '&action=raw&ctype=text/css';
207 return importStylesheetURI( uri );
208 }
209
210 msg = 'Use mw.loader instead.';
211 mw.log.deprecate( win, 'loadedScripts', loadedScripts, msg );
212 mw.log.deprecate( win, 'importScriptURI', importScriptURI, msg );
213 mw.log.deprecate( win, 'importStylesheetURI', importStylesheetURI, msg );
214 // Not quite deprecated yet.
215 win.importScript = importScript;
216 win.importStylesheet = importStylesheet;
217
218 // Replace document.write/writeln with basic html parsing that appends
219 // to the <body> to avoid blanking pages. Added JavaScript will not run.
220 $.each( [ 'write', 'writeln' ], function ( idx, method ) {
221 mw.log.deprecate( document, method, function () {
222 $( 'body' ).append( $.parseHTML( Array.prototype.join.call( arguments, '' ) ) );
223 }, 'Use jQuery or mw.loader.load instead.' );
224 } );
225
226 }( mediaWiki, jQuery ) );