deferred: make DeferredUpdates::attemptUpdate() use callback owners for $fnameTrxOwner
[lhc/web/wiklou.git] / resources / src / mediawiki.legacy / wikibits.js
1 /**
2 * MediaWiki legacy wikibits
3 */
4 ( function () {
5 var msg,
6 loadedScripts = {};
7
8 function wikiUrlencode( page ) {
9 return encodeURIComponent( String( page ) )
10 .replace( /'/g, '%27' )
11 .replace( /%20/g, '_' )
12 // wfUrlencode replacements
13 .replace( /%3B/g, ';' )
14 .replace( /%40/g, '@' )
15 .replace( /%24/g, '$' )
16 .replace( /%21/g, '!' )
17 .replace( /%2A/g, '*' )
18 .replace( /%28/g, '(' )
19 .replace( /%29/g, ')' )
20 .replace( /%2C/g, ',' )
21 .replace( /%2F/g, '/' )
22 .replace( /%7E/g, '~' )
23 .replace( /%3A/g, ':' );
24 }
25
26 /**
27 * @deprecated since 1.17 Use jQuery instead
28 */
29 mw.log.deprecate( window, 'addOnloadHook', function ( fn ) {
30 $( function () {
31 fn();
32 } );
33 }, 'Use jQuery instead.' );
34
35 /**
36 * Wikipage import methods
37 *
38 * See https://www.mediawiki.org/wiki/ResourceLoader/Legacy_JavaScript#wikibits.js
39 */
40
41 /**
42 * @deprecated since 1.17 Use mw.loader instead. Warnings added in 1.25.
43 * @param {string} url
44 * @return {HTMLElement} Script tag
45 */
46 function importScriptURI( url ) {
47 var s;
48 if ( loadedScripts[ url ] ) {
49 return null;
50 }
51 loadedScripts[ url ] = true;
52 s = document.createElement( 'script' );
53 s.setAttribute( 'src', url );
54 document.head.appendChild( s );
55 return s;
56 }
57
58 function importScript( page ) {
59 var uri = mw.config.get( 'wgScript' ) + '?title=' + wikiUrlencode( page ) +
60 '&action=raw&ctype=text/javascript';
61 return importScriptURI( uri );
62 }
63
64 /**
65 * @deprecated since 1.17 Use mw.loader instead. Warnings added in 1.25.
66 * @param {string} url
67 * @param {string} media
68 * @return {HTMLElement} Link tag
69 */
70 function importStylesheetURI( url, media ) {
71 var l = document.createElement( 'link' );
72 l.rel = 'stylesheet';
73 l.href = url;
74 if ( media ) {
75 l.media = media;
76 }
77 document.head.appendChild( l );
78 return l;
79 }
80
81 function importStylesheet( page ) {
82 var uri = mw.config.get( 'wgScript' ) + '?title=' + wikiUrlencode( page ) +
83 '&action=raw&ctype=text/css';
84 return importStylesheetURI( uri );
85 }
86
87 msg = 'Use mw.loader instead.';
88 mw.log.deprecate( window, 'loadedScripts', loadedScripts, msg );
89 mw.log.deprecate( window, 'importScriptURI', importScriptURI, msg );
90 mw.log.deprecate( window, 'importStylesheetURI', importStylesheetURI, msg );
91 // Not quite deprecated yet.
92 window.importScript = importScript;
93 window.importStylesheet = importStylesheet;
94
95 /**
96 * Replace document.write/writeln with basic html parsing that appends
97 * to the <body> to avoid blanking pages. Added JavaScript will not run.
98 *
99 * @deprecated since 1.26
100 */
101 [ 'write', 'writeln' ].forEach( function ( method ) {
102 mw.log.deprecate( document, method, function () {
103 $( 'body' ).append( $.parseHTML( Array.prototype.join.call( arguments, '' ) ) );
104 }, 'Use jQuery or mw.loader.load instead.', 'document.' + method );
105 } );
106
107 }() );