Debian Codegraph @

extensions/TitleBlacklist/modules/mediawiki.api.titleblacklist.js

raw symbols SCIP
1 /**
2 * @class mw.Api.plugin.titleblacklist
3 */
4 ( function () {
5
6 Object.assign( mw.Api.prototype, {
7 /**
8 * Convenience method for `action=titleblacklist`.
9 *
10 * @param {mw.Title|string} title
11 * @param {Function} [ok] Success callback (deprecated)
12 * @param {Function} [err] Error callback (deprecated)
13 * @return {jQuery.Promise}
14 * @return {Function} return.done
15 * @return {Object|boolean} return.done.result False if title wasn't blacklisted, an object
16 * with 'reason', 'line'
17 * and 'message' properties if title was blacklisted.
18 */
19 isBlacklisted: function ( title, ok, err ) {
20 var d = $.Deferred();
21 // Backwards compatibility (< MW 1.20)
22 d.done( ok );
23 d.fail( err );
24
25 this.get( {
26 action: 'titleblacklist',
27 tbaction: 'create',
28 tbtitle: title.toString(),
29 errorformat: 'html',
30 errorlang: mw.config.get( 'wgUserLanguage' ),
31 errorsuselocal: '',
32 formatversion: 2
33 } )
34 .done( function ( data ) {
35 var result;
36
37 // this fails open (if nothing valid is returned by the api, allows the title)
38 // also fails open when the API is not present, which will be most of the time
39 // as this API module is part of the TitleBlacklist extension.
40 if ( data.titleblacklist && data.titleblacklist.result && data.titleblacklist.result === 'blacklisted' ) {
41 if ( data.titleblacklist.reason ) {
42 result = {
43 reason: data.titleblacklist.reason,
44 line: data.titleblacklist.line,
45 message: data.titleblacklist.message
46 };
47 } else {
48 mw.log( 'mw.Api.titleblacklist::isBlacklisted> no reason data for blacklisted title', 'debug' );
49 result = {
50 reason: 'Blacklisted, but no reason supplied',
51 line: 'Unknown',
52 message: null
53 };
54 }
55 d.resolve( result );
56 } else {
57 d.resolve( false );
58 }
59 } )
60 .fail( d.reject );
61
62 return d.promise();
63 }
64
65 } );
66
67 /**
68 * @class mw.Api
69 * @mixes mw.Api.plugin.titleblacklist
70 */
71
72 }() );