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