mediawiki.searchSuggest: Show full article title as a tooltip for each suggestion
[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', mw.util.jsMessage, 'Use mediawiki.notify instead.' );
157
158 /**
159 * Misc. utilities
160 *
161 * To be removed in MediaWiki 1.23.
162 *
163 * @deprecated since 1.17 Use mediawiki.util instead
164 */
165 msg = 'Use mediawiki.util instead.';
166 mw.log.deprecate( win, 'tooltipAccessKeyPrefix', 'alt-', msg );
167 mw.log.deprecate( win, 'tooltipAccessKeyRegexp', /\[(alt-)?(.)\]$/, msg );
168 mw.log.deprecate( win, 'updateTooltipAccessKeys', mw.util.updateTooltipAccessKeys, msg );
169 mw.log.deprecate( win, 'addPortletLink', mw.util.addPortletLink, msg );
170 mw.log.deprecate( win, 'appendCSS', mw.util.addCSS, msg );
171
172 /**
173 * Wikipage import methods
174 */
175
176 // included-scripts tracker
177 win.loadedScripts = {};
178
179 win.importScript = function ( page ) {
180 var uri = mw.config.get( 'wgScript' ) + '?title=' +
181 mw.util.wikiUrlencode( page ) +
182 '&action=raw&ctype=text/javascript';
183 return win.importScriptURI( uri );
184 };
185
186 win.importScriptURI = function ( url ) {
187 if ( win.loadedScripts[url] ) {
188 return null;
189 }
190 win.loadedScripts[url] = true;
191 var s = document.createElement( 'script' );
192 s.setAttribute( 'src', url );
193 s.setAttribute( 'type', 'text/javascript' );
194 document.getElementsByTagName( 'head' )[0].appendChild( s );
195 return s;
196 };
197
198 win.importStylesheet = function ( page ) {
199 var uri = mw.config.get( 'wgScript' ) + '?title=' +
200 mw.util.wikiUrlencode( page ) +
201 '&action=raw&ctype=text/css';
202 return win.importStylesheetURI( uri );
203 };
204
205 win.importStylesheetURI = function ( url, media ) {
206 var l = document.createElement( 'link' );
207 l.rel = 'stylesheet';
208 l.href = url;
209 if ( media ) {
210 l.media = media;
211 }
212 document.getElementsByTagName('head')[0].appendChild( l );
213 return l;
214 };
215
216 if ( isIE6 ) {
217 win.importScriptURI( mw.config.get( 'stylepath' ) + '/common/IEFixes.js' );
218 }
219
220 }( mediaWiki, jQuery ) );