summaryrefslogtreecommitdiff
path: root/www/wiki/resources/src/mediawiki.legacy/wikibits.js
blob: 27d049eb3a4577a5e143134896e6b91f41d3fce2 (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
/**
 * MediaWiki legacy wikibits
 */
( function ( mw, $ ) {
	var msg,
		loadedScripts = {};

	function wikiUrlencode( page ) {
		return encodeURIComponent( String( page ) )
			.replace( /'/g, '%27' )
			.replace( /%20/g, '_' )
			// wfUrlencode replacements
			.replace( /%3B/g, ';' )
			.replace( /%40/g, '@' )
			.replace( /%24/g, '$' )
			.replace( /%21/g, '!' )
			.replace( /%2A/g, '*' )
			.replace( /%28/g, '(' )
			.replace( /%29/g, ')' )
			.replace( /%2C/g, ',' )
			.replace( /%2F/g, '/' )
			.replace( /%7E/g, '~' )
			.replace( /%3A/g, ':' );
	}

	/**
	 * @deprecated since 1.17 Use jQuery instead
	 */
	mw.log.deprecate( window, 'addOnloadHook', function ( fn ) {
		$( function () { fn(); } );
	}, 'Use jQuery instead.' );

	/**
	 * Wikipage import methods
	 *
	 * See https://www.mediawiki.org/wiki/ResourceLoader/Legacy_JavaScript#wikibits.js
	 */

	/**
	 * @deprecated since 1.17 Use mw.loader instead. Warnings added in 1.25.
	 * @param {string} url
	 * @return {HTMLElement} Script tag
	 */
	function importScriptURI( url ) {
		var s;
		if ( loadedScripts[ url ] ) {
			return null;
		}
		loadedScripts[ url ] = true;
		s = document.createElement( 'script' );
		s.setAttribute( 'src', url );
		document.head.appendChild( s );
		return s;
	}

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

	/**
	 * @deprecated since 1.17 Use mw.loader instead. Warnings added in 1.25.
	 * @param {string} url
	 * @param {string} media
	 * @return {HTMLElement} Link tag
	 */
	function importStylesheetURI( url, media ) {
		var l = document.createElement( 'link' );
		l.rel = 'stylesheet';
		l.href = url;
		if ( media ) {
			l.media = media;
		}
		document.head.appendChild( l );
		return l;
	}

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

	msg = 'Use mw.loader instead.';
	mw.log.deprecate( window, 'loadedScripts', loadedScripts, msg );
	mw.log.deprecate( window, 'importScriptURI', importScriptURI, msg );
	mw.log.deprecate( window, 'importStylesheetURI', importStylesheetURI, msg );
	// Not quite deprecated yet.
	window.importScript = importScript;
	window.importStylesheet = importStylesheet;

	/**
	 * Replace document.write/writeln with basic html parsing that appends
	 * to the <body> to avoid blanking pages. Added JavaScript will not run.
	 *
	 * @deprecated since 1.26
	 */
	[ 'write', 'writeln' ].forEach( function ( method ) {
		mw.log.deprecate( document, method, function () {
			$( 'body' ).append( $.parseHTML( Array.prototype.join.call( arguments, '' ) ) );
		}, 'Use jQuery or mw.loader.load instead.', 'document.' + method );
	} );

}( mediaWiki, jQuery ) );