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