summaryrefslogtreecommitdiff
path: root/skins/common/wikibits.js
blob: d28ca0a3da058350caf5a5d8016c0d62b1cf13fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/**
 * MediaWiki legacy wikibits
 */
( function ( mw, $ ) {
	var msg,
		win = window,
		ua = navigator.userAgent.toLowerCase(),
		isIE6 = ( /msie ([0-9]{1,}[\.0-9]{0,})/.exec( ua ) && parseFloat( RegExp.$1 ) <= 6.0 ),
		isGecko = /gecko/.test( ua ) && !/khtml|spoofer|netscape\/7\.0/.test( ua ),
		onloadFuncts = [];

if ( mw.config.get( 'wgBreakFrames' ) ) {
	// Note: In IE < 9 strict comparison to window is non-standard (the standard didn't exist yet)
	// it works only comparing to window.self or window.window (http://stackoverflow.com/q/4850978/319266)
	if ( win.top !== win.self ) {
		// Un-trap us from framesets
		win.top.location = win.location;
	}
}

win.redirectToFragment = function ( fragment ) {
	var webKitVersion,
		match = navigator.userAgent.match( /AppleWebKit\/(\d+)/ );
	if ( match ) {
		webKitVersion = parseInt( match[1], 10 );
		if ( webKitVersion < 420 ) {
			// Released Safari w/ WebKit 418.9.1 messes up horribly
			// Nightlies of 420+ are ok
			return;
		}
	}
	if ( !win.location.hash ) {
		win.location.hash = fragment;

		// Mozilla needs to wait until after load, otherwise the window doesn't
		// scroll.  See <https://bugzilla.mozilla.org/show_bug.cgi?id=516293>.
		// There's no obvious way to detect this programmatically, so we use
		// version-testing.  If Firefox fixes the bug, they'll jump twice, but
		// better twice than not at all, so make the fix hit future versions as
		// well.
		if ( isGecko ) {
			$( function () {
				if ( win.location.hash === fragment ) {
					win.location.hash = fragment;
				}
			} );
		}
	}
};

/**
 * User-agent sniffing.
 * To be removed in MediaWiki 1.23.
 *
 * @deprecated since 1.17 Use jquery.client instead
 */

msg = 'Use feature detection or module jquery.client instead';

mw.log.deprecate( win, 'clientPC', ua, msg );

// Ignored dummy values
mw.log.deprecate( win, 'is_gecko', false, msg );
mw.log.deprecate( win, 'is_chrome_mac', false, msg );
mw.log.deprecate( win, 'is_chrome', false, msg );
mw.log.deprecate( win, 'webkit_version', false, msg );
mw.log.deprecate( win, 'is_safari_win', false, msg );
mw.log.deprecate( win, 'is_safari', false, msg );
mw.log.deprecate( win, 'webkit_match', false, msg );
mw.log.deprecate( win, 'is_ff2', false, msg );
mw.log.deprecate( win, 'ff2_bugs', false, msg );
mw.log.deprecate( win, 'is_ff2_win', false, msg );
mw.log.deprecate( win, 'is_ff2_x11', false, msg );
mw.log.deprecate( win, 'opera95_bugs', false, msg );
mw.log.deprecate( win, 'opera7_bugs', false, msg );
mw.log.deprecate( win, 'opera6_bugs', false, msg );
mw.log.deprecate( win, 'is_opera_95', false, msg );
mw.log.deprecate( win, 'is_opera_preseven', false, msg );
mw.log.deprecate( win, 'is_opera', false, msg );
mw.log.deprecate( win, 'ie6_bugs', false, msg );

/**
 * DOM utilities for handling of events, text nodes and selecting elements
 *
 * To be removed in MediaWiki 1.23.
 *
 * @deprecated since 1.17 Use jQuery instead
 */
msg = 'Use jQuery instead';

// Ignored dummy values
mw.log.deprecate( win, 'doneOnloadHook', undefined, msg );
mw.log.deprecate( win, 'onloadFuncts', [], msg );
mw.log.deprecate( win, 'runOnloadHook', $.noop, msg );
mw.log.deprecate( win, 'changeText', $.noop, msg );
mw.log.deprecate( win, 'killEvt', $.noop, msg );
mw.log.deprecate( win, 'addHandler', $.noop, msg );
mw.log.deprecate( win, 'hookEvent', $.noop, msg );
mw.log.deprecate( win, 'addClickHandler', $.noop, msg );
mw.log.deprecate( win, 'removeHandler', $.noop, msg );
mw.log.deprecate( win, 'getElementsByClassName', function () { return []; }, msg );
mw.log.deprecate( win, 'getInnerText', function () { return ''; }, msg );

// Run a function after the window onload event is fired
mw.log.deprecate( win, 'addOnloadHook', function ( hookFunct ) {
	if ( onloadFuncts ) {
		onloadFuncts.push(hookFunct);
	} else {
		// If func queue is gone the event has happened already,
		// run immediately instead of queueing.
		hookFunct();
	}
}, msg );

$( win ).on( 'load', function () {
	var i, functs;

	// Don't run twice
	if ( !onloadFuncts ) {
		return;
	}

	// Deference and clear onloadFuncts before running any
	// hooks to make sure we don't miss any addOnloadHook
	// calls.
	functs = onloadFuncts.slice();
	onloadFuncts = undefined;

	// Execute the queued functions
	for ( i = 0; i < functs.length; i++ ) {
		functs[i]();
	}
} );

/**
 * Toggle checkboxes with shift selection
 *
 * To be removed in MediaWiki 1.23.
 *
 * @deprecated since 1.17 Use jquery.checkboxShiftClick instead
 */
msg = 'Use jquery.checkboxShiftClick instead';
mw.log.deprecate( win, 'checkboxes', [], msg );
mw.log.deprecate( win, 'lastCheckbox', null, msg );
mw.log.deprecate( win, 'setupCheckboxShiftClick', $.noop, msg );
mw.log.deprecate( win, 'addCheckboxClickHandlers', $.noop, msg );
mw.log.deprecate( win, 'checkboxClickHandler', $.noop, msg );

/**
 * Add a button to the default editor toolbar
 *
 * To be removed in MediaWiki 1.23.
 *
 * @deprecated since 1.17 Use mw.toolbar instead
 */
mw.log.deprecate( win, 'mwEditButtons', [], 'Use mw.toolbar instead' );
mw.log.deprecate( win, 'mwCustomEditButtons', [], 'Use mw.toolbar instead' );

/**
 * Spinner creation, injection and removal
 *
 * To be removed in MediaWiki 1.23.
 *
 * @deprecated since 1.18 Use jquery.spinner instead
 */
mw.log.deprecate( win, 'injectSpinner', $.noop, 'Use jquery.spinner instead' );
mw.log.deprecate( win, 'removeSpinner', $.noop, 'Use jquery.spinner instead' );

/**
 * Escape utilities
 *
 * To be removed in MediaWiki 1.23.
 *
 * @deprecated since 1.18 Use mw.html instead
 */
mw.log.deprecate( win, 'escapeQuotes', $.noop,'Use mw.html instead' );
mw.log.deprecate( win, 'escapeQuotesHTML', $.noop,'Use mw.html instead' );

/**
 * Display a message to the user
 *
 * To be removed in MediaWiki 1.23.
 *
 * @deprecated since 1.17 Use mediawiki.notify instead
 * @param {string|HTMLElement} message To be put inside the message box
 */
mw.log.deprecate( win, 'jsMsg', mw.util.jsMessage, 'Use mediawiki.notify instead' );

/**
 * Misc. utilities
 *
 * To be removed in MediaWiki 1.23.
 *
 * @deprecated since 1.17 Use mediawiki.util instead
 */
msg = 'Use mediawiki.util instead';
mw.log.deprecate( win, 'tooltipAccessKeyPrefix', 'alt-', msg );
mw.log.deprecate( win, 'tooltipAccessKeyRegexp', /\[(alt-)?(.)\]$/, msg );
mw.log.deprecate( win, 'updateTooltipAccessKeys', mw.util.updateTooltipAccessKeys, msg );
mw.log.deprecate( win, 'addPortletLink', mw.util.addPortletLink, msg );
mw.log.deprecate( win, 'appendCSS', mw.util.addCSS, msg );

/**
 * Wikipage import methods
 */

// included-scripts tracker
win.loadedScripts = {};

win.importScript = function ( page ) {
	var uri = mw.config.get( 'wgScript' ) + '?title=' +
		mw.util.wikiUrlencode( page ) +
		'&action=raw&ctype=text/javascript';
	return win.importScriptURI( uri );
};

win.importScriptURI = function ( url ) {
	if ( win.loadedScripts[url] ) {
		return null;
	}
	win.loadedScripts[url] = true;
	var s = document.createElement( 'script' );
	s.setAttribute( 'src', url );
	s.setAttribute( 'type', 'text/javascript' );
	document.getElementsByTagName( 'head' )[0].appendChild( s );
	return s;
};

win.importStylesheet = function( page ) {
	return win.importStylesheetURI( mw.config.get( 'wgScript' ) + '?action=raw&ctype=text/css&title=' + mw.util.wikiUrlencode( page ) );
};

win.importStylesheetURI = function( url, media ) {
	var l = document.createElement( 'link' );
	l.rel = 'stylesheet';
	l.href = url;
	if ( media ) {
		l.media = media;
	}
	document.getElementsByTagName('head')[0].appendChild( l );
	return l;
};

if ( isIE6 ) {
	win.importScriptURI( mw.config.get( 'stylepath' ) + '/common/IEFixes.js' );
}

}( mediaWiki, jQuery ) );