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