Merge "(bug 47070) check content model namespace on import."
[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 isGecko = /gecko/.test( ua ) && !/khtml|spoofer|netscape\/7\.0/.test( ua ),
10 onloadFuncts = [];
11
12 if ( mw.config.get( 'wgBreakFrames' ) ) {
13 // Note: In IE < 9 strict comparison to window is non-standard (the standard didn't exist yet)
14 // it works only comparing to window.self or window.window (http://stackoverflow.com/q/4850978/319266)
15 if ( win.top !== win.self ) {
16 // Un-trap us from framesets
17 win.top.location = win.location;
18 }
19 }
20
21 /**
22 * Legacy function to scroll to an id while viewing the page over a redirect.
23 * Superseeded by module 'mediawiki.action.view.redirectToFragment' in version 1.23.
24 * Kepted because cache can contain still inline script calls to this function.
25 * Should be removed in version 1.24.
26 * @deprecated since 1.23 Use mediawiki.action.view.redirectToFragment instead
27 */
28 mw.log.deprecate( win, 'redirectToFragment', function ( fragment ) {
29 var webKitVersion,
30 match = navigator.userAgent.match( /AppleWebKit\/(\d+)/ );
31 if ( match ) {
32 webKitVersion = parseInt( match[1], 10 );
33 if ( webKitVersion < 420 ) {
34 // Released Safari w/ WebKit 418.9.1 messes up horribly
35 // Nightlies of 420+ are ok
36 return;
37 }
38 }
39 if ( !win.location.hash ) {
40 win.location.hash = fragment;
41
42 // Mozilla needs to wait until after load, otherwise the window doesn't
43 // scroll. See <https://bugzilla.mozilla.org/show_bug.cgi?id=516293>.
44 // There's no obvious way to detect this programmatically, so we use
45 // version-testing. If Firefox fixes the bug, they'll jump twice, but
46 // better twice than not at all, so make the fix hit future versions as
47 // well.
48 if ( isGecko ) {
49 $( function () {
50 if ( win.location.hash === fragment ) {
51 win.location.hash = fragment;
52 }
53 } );
54 }
55 }
56 }, 'Use the module mediawiki.action.view.redirectToFragment instead.' );
57
58 /**
59 * User-agent sniffing.
60 * To be removed in MediaWiki 1.23.
61 *
62 * @deprecated since 1.17 Use jquery.client instead
63 */
64
65 msg = 'Use feature detection or module jquery.client instead';
66
67 mw.log.deprecate( win, 'clientPC', ua, msg );
68
69 // Ignored dummy values
70 mw.log.deprecate( win, 'is_gecko', false, msg );
71 mw.log.deprecate( win, 'is_chrome_mac', false, msg );
72 mw.log.deprecate( win, 'is_chrome', false, msg );
73 mw.log.deprecate( win, 'webkit_version', false, msg );
74 mw.log.deprecate( win, 'is_safari_win', false, msg );
75 mw.log.deprecate( win, 'is_safari', false, msg );
76 mw.log.deprecate( win, 'webkit_match', false, msg );
77 mw.log.deprecate( win, 'is_ff2', false, msg );
78 mw.log.deprecate( win, 'ff2_bugs', false, msg );
79 mw.log.deprecate( win, 'is_ff2_win', false, msg );
80 mw.log.deprecate( win, 'is_ff2_x11', false, msg );
81 mw.log.deprecate( win, 'opera95_bugs', false, msg );
82 mw.log.deprecate( win, 'opera7_bugs', false, msg );
83 mw.log.deprecate( win, 'opera6_bugs', false, msg );
84 mw.log.deprecate( win, 'is_opera_95', false, msg );
85 mw.log.deprecate( win, 'is_opera_preseven', false, msg );
86 mw.log.deprecate( win, 'is_opera', false, msg );
87 mw.log.deprecate( win, 'ie6_bugs', false, msg );
88
89 /**
90 * DOM utilities for handling of events, text nodes and selecting elements
91 *
92 * To be removed in MediaWiki 1.23.
93 *
94 * @deprecated since 1.17 Use jQuery instead
95 */
96 msg = 'Use jQuery instead';
97
98 // Ignored dummy values
99 mw.log.deprecate( win, 'doneOnloadHook', undefined, msg );
100 mw.log.deprecate( win, 'onloadFuncts', [], msg );
101 mw.log.deprecate( win, 'runOnloadHook', $.noop, msg );
102 mw.log.deprecate( win, 'changeText', $.noop, msg );
103 mw.log.deprecate( win, 'killEvt', $.noop, msg );
104 mw.log.deprecate( win, 'addHandler', $.noop, msg );
105 mw.log.deprecate( win, 'hookEvent', $.noop, msg );
106 mw.log.deprecate( win, 'addClickHandler', $.noop, msg );
107 mw.log.deprecate( win, 'removeHandler', $.noop, msg );
108 mw.log.deprecate( win, 'getElementsByClassName', function () { return []; }, msg );
109 mw.log.deprecate( win, 'getInnerText', function () { return ''; }, msg );
110
111 // Run a function after the window onload event is fired
112 mw.log.deprecate( win, 'addOnloadHook', function ( hookFunct ) {
113 if ( onloadFuncts ) {
114 onloadFuncts.push(hookFunct);
115 } else {
116 // If func queue is gone the event has happened already,
117 // run immediately instead of queueing.
118 hookFunct();
119 }
120 }, msg );
121
122 $( win ).on( 'load', function () {
123 var i, functs;
124
125 // Don't run twice
126 if ( !onloadFuncts ) {
127 return;
128 }
129
130 // Deference and clear onloadFuncts before running any
131 // hooks to make sure we don't miss any addOnloadHook
132 // calls.
133 functs = onloadFuncts.slice();
134 onloadFuncts = undefined;
135
136 // Execute the queued functions
137 for ( i = 0; i < functs.length; i++ ) {
138 functs[i]();
139 }
140 } );
141
142 /**
143 * Toggle checkboxes with shift selection
144 *
145 * To be removed in MediaWiki 1.23.
146 *
147 * @deprecated since 1.17 Use jquery.checkboxShiftClick instead
148 */
149 msg = 'Use jquery.checkboxShiftClick instead';
150 mw.log.deprecate( win, 'checkboxes', [], msg );
151 mw.log.deprecate( win, 'lastCheckbox', null, msg );
152 mw.log.deprecate( win, 'setupCheckboxShiftClick', $.noop, msg );
153 mw.log.deprecate( win, 'addCheckboxClickHandlers', $.noop, msg );
154 mw.log.deprecate( win, 'checkboxClickHandler', $.noop, msg );
155
156 /**
157 * Add a button to the default editor toolbar
158 *
159 * To be removed in MediaWiki 1.23.
160 *
161 * @deprecated since 1.17 Use mw.toolbar instead
162 */
163 mw.log.deprecate( win, 'mwEditButtons', [], 'Use mw.toolbar instead' );
164 mw.log.deprecate( win, 'mwCustomEditButtons', [], 'Use mw.toolbar instead' );
165
166 /**
167 * Spinner creation, injection and removal
168 *
169 * To be removed in MediaWiki 1.23.
170 *
171 * @deprecated since 1.18 Use jquery.spinner instead
172 */
173 mw.log.deprecate( win, 'injectSpinner', $.noop, 'Use jquery.spinner instead' );
174 mw.log.deprecate( win, 'removeSpinner', $.noop, 'Use jquery.spinner instead' );
175
176 /**
177 * Escape utilities
178 *
179 * To be removed in MediaWiki 1.23.
180 *
181 * @deprecated since 1.18 Use mw.html instead
182 */
183 mw.log.deprecate( win, 'escapeQuotes', $.noop,'Use mw.html instead' );
184 mw.log.deprecate( win, 'escapeQuotesHTML', $.noop,'Use mw.html instead' );
185
186 /**
187 * Display a message to the user
188 *
189 * To be removed in MediaWiki 1.23.
190 *
191 * @deprecated since 1.17 Use mediawiki.notify instead
192 * @param {string|HTMLElement} message To be put inside the message box
193 */
194 mw.log.deprecate( win, 'jsMsg', mw.util.jsMessage, 'Use mediawiki.notify instead' );
195
196 /**
197 * Misc. utilities
198 *
199 * To be removed in MediaWiki 1.23.
200 *
201 * @deprecated since 1.17 Use mediawiki.util instead
202 */
203 msg = 'Use mediawiki.util instead';
204 mw.log.deprecate( win, 'tooltipAccessKeyPrefix', 'alt-', msg );
205 mw.log.deprecate( win, 'tooltipAccessKeyRegexp', /\[(alt-)?(.)\]$/, msg );
206 mw.log.deprecate( win, 'updateTooltipAccessKeys', mw.util.updateTooltipAccessKeys, msg );
207 mw.log.deprecate( win, 'addPortletLink', mw.util.addPortletLink, msg );
208 mw.log.deprecate( win, 'appendCSS', mw.util.addCSS, msg );
209
210 /**
211 * Wikipage import methods
212 */
213
214 // included-scripts tracker
215 win.loadedScripts = {};
216
217 win.importScript = function ( page ) {
218 var uri = mw.config.get( 'wgScript' ) + '?title=' +
219 mw.util.wikiUrlencode( page ) +
220 '&action=raw&ctype=text/javascript';
221 return win.importScriptURI( uri );
222 };
223
224 win.importScriptURI = function ( url ) {
225 if ( win.loadedScripts[url] ) {
226 return null;
227 }
228 win.loadedScripts[url] = true;
229 var s = document.createElement( 'script' );
230 s.setAttribute( 'src', url );
231 s.setAttribute( 'type', 'text/javascript' );
232 document.getElementsByTagName( 'head' )[0].appendChild( s );
233 return s;
234 };
235
236 win.importStylesheet = function ( page ) {
237 var uri = mw.config.get( 'wgScript' ) + '?title=' +
238 mw.util.wikiUrlencode( page ) +
239 '&action=raw&ctype=text/css';
240 return win.importStylesheetURI( uri );
241 };
242
243 win.importStylesheetURI = function( url, media ) {
244 var l = document.createElement( 'link' );
245 l.rel = 'stylesheet';
246 l.href = url;
247 if ( media ) {
248 l.media = media;
249 }
250 document.getElementsByTagName('head')[0].appendChild( l );
251 return l;
252 };
253
254 if ( isIE6 ) {
255 win.importScriptURI( mw.config.get( 'stylepath' ) + '/common/IEFixes.js' );
256 }
257
258 }( mediaWiki, jQuery ) );