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