Remove RELEASE-NOTES-1.19 from r108145, moved to 1.18 in r108629
[mediawiki.git] / resources / mediawiki / mediawiki.api.titleblacklist.js
blob5435945b60b68aa322414e87006eb04fa8375fe9
1 /**
2  * Additional mw.Api methods to assist with API calls to the API module of the TitleBlacklist extension.
3  */
5 ( function( $, mw, undefined ) {
7         $.extend( mw.Api.prototype, {
8                 /**
9                  * Convinience method for 'action=titleblacklist'.
10                  * Note: This action is not provided by MediaWiki core, but as part of the TitleBlacklist extension.
11                  *
12                  * @param title {mw.Title}
13                  * @param success {Function} Called on successfull request. First argument is false if title wasn't blacklisted,
14                  *  object with 'reason', 'line' and 'message' properties if title was blacklisted.
15                  * @param err {Function} optional callback to run if api error
16                  * @return {jqXHR}
17                  */
18                 isBlacklisted: function( title, success, err ) {
19                         var     params = {
20                                         action: 'titleblacklist',
21                                         tbaction: 'create',
22                                         tbtitle: title.toString()
23                                 },
24                                 ok = function( data ) {
25                                         var result;
27                                         // this fails open (if nothing valid is returned by the api, allows the title)
28                                         // also fails open when the API is not present, which will be most of the time
29                                         // as this API module is part of the TitleBlacklist extension.
30                                         if ( data.titleblacklist && data.titleblacklist.result && data.titleblacklist.result === 'blacklisted') {
31                                                 if ( data.titleblacklist.reason ) {
32                                                         result = {
33                                                                 reason: data.titleblacklist.reason,
34                                                                 line: data.titleblacklist.line,
35                                                                 message: data.titleblacklist.message
36                                                         };
37                                                 } else {
38                                                         mw.log('mw.Api.titleblacklist::isBlacklisted> no reason data for blacklisted title', 'debug');
39                                                         result = { reason: 'Blacklisted, but no reason supplied', line: 'Unknown', message: null };
40                                                 }
41                                                 success( result );
42                                         } else {
43                                                 success ( false );
44                                         }
45                                 };
47                         return this.get( params, { ok: ok, err: err } );
48                 }
50         } );
51 } )( jQuery, mediaWiki );