Merge "Removing badge drop shadow per Vibha"
[lhc/web/wiklou.git] / resources / mediawiki.api / mediawiki.api.titleblacklist.js
1 /**
2 * @class mw.Api.plugin.titleblacklist
3 */
4 ( function ( mw, $ ) {
5
6 $.extend( mw.Api.prototype, {
7 /**
8 * Convinience method for `action=titleblacklist`.
9 * Note: This action is not provided by MediaWiki core, but as part of the TitleBlacklist extension.
10 *
11 * @param {mw.Title|string} title
12 * @param {Function} [ok] Success callback (deprecated)
13 * @param {Function} [err] Error callback (deprecated)
14 * @return {jQuery.Promise}
15 * @return {Function} return.done
16 * @return {Object|boolean} return.done.result False if title wasn't blacklisted, an object 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 } )
30 .done( function ( data ) {
31 var result;
32
33 // this fails open (if nothing valid is returned by the api, allows the title)
34 // also fails open when the API is not present, which will be most of the time
35 // as this API module is part of the TitleBlacklist extension.
36 if ( data.titleblacklist && data.titleblacklist.result && data.titleblacklist.result === 'blacklisted' ) {
37 if ( data.titleblacklist.reason ) {
38 result = {
39 reason: data.titleblacklist.reason,
40 line: data.titleblacklist.line,
41 message: data.titleblacklist.message
42 };
43 } else {
44 mw.log( 'mw.Api.titleblacklist::isBlacklisted> no reason data for blacklisted title', 'debug' );
45 result = {
46 reason: 'Blacklisted, but no reason supplied',
47 line: 'Unknown',
48 message: null
49 };
50 }
51 d.resolve( result );
52 } else {
53 d.resolve( false );
54 }
55 } )
56 .fail( d.reject );
57
58 return d.promise();
59 }
60
61 } );
62
63 /**
64 * @class mw.Api
65 * @mixins mw.Api.plugin.titleblacklist
66 */
67
68 }( mediaWiki, jQuery ) );