Merge "Removing badge drop shadow per Vibha"
[lhc/web/wiklou.git] / resources / mediawiki.api / mediawiki.api.titleblacklist.js
index 1f7e275..8c46717 100644 (file)
@@ -1,33 +1,39 @@
 /**
- * Additional mw.Api methods to assist with API calls to the API module of the TitleBlacklist extension.
+ * @class mw.Api.plugin.titleblacklist
  */
-
 ( function ( mw, $ ) {
 
        $.extend( mw.Api.prototype, {
                /**
-                * Convinience method for 'action=titleblacklist'.
+                * Convinience method for `action=titleblacklist`.
                 * Note: This action is not provided by MediaWiki core, but as part of the TitleBlacklist extension.
                 *
-                * @param title {mw.Title}
-                * @param success {Function} Called on successfull request. First argument is false if title wasn't blacklisted,
-                *  object with 'reason', 'line' and 'message' properties if title was blacklisted.
-                * @param err {Function} optional callback to run if api error
-                * @return {jqXHR}
+                * @param {mw.Title|string} title
+                * @param {Function} [ok] Success callback (deprecated)
+                * @param {Function} [err] Error callback (deprecated)
+                * @return {jQuery.Promise}
+                * @return {Function} return.done
+                * @return {Object|boolean} return.done.result False if title wasn't blacklisted, an object with 'reason', 'line'
+                *  and 'message' properties if title was blacklisted.
                 */
-               isBlacklisted: function ( title, success, err ) {
-                       var     params = {
+               isBlacklisted: function ( title, ok, err ) {
+                       var d = $.Deferred();
+                       // Backwards compatibility (< MW 1.20)
+                       d.done( ok );
+                       d.fail( err );
+
+                       this.get( {
                                        action: 'titleblacklist',
                                        tbaction: 'create',
                                        tbtitle: title.toString()
-                               },
-                               ok = function ( data ) {
+                               } )
+                               .done( function ( data ) {
                                        var result;
 
                                        // this fails open (if nothing valid is returned by the api, allows the title)
                                        // also fails open when the API is not present, which will be most of the time
                                        // as this API module is part of the TitleBlacklist extension.
-                                       if ( data.titleblacklist && data.titleblacklist.result && data.titleblacklist.result === 'blacklisted') {
+                                       if ( data.titleblacklist && data.titleblacklist.result && data.titleblacklist.result === 'blacklisted' ) {
                                                if ( data.titleblacklist.reason ) {
                                                        result = {
                                                                reason: data.titleblacklist.reason,
                                                                message: data.titleblacklist.message
                                                        };
                                                } else {
-                                                       mw.log('mw.Api.titleblacklist::isBlacklisted> no reason data for blacklisted title', 'debug');
-                                                       result = { reason: 'Blacklisted, but no reason supplied', line: 'Unknown', message: null };
+                                                       mw.log( 'mw.Api.titleblacklist::isBlacklisted> no reason data for blacklisted title', 'debug' );
+                                                       result = {
+                                                               reason: 'Blacklisted, but no reason supplied',
+                                                               line: 'Unknown',
+                                                               message: null
+                                                       };
                                                }
-                                               success( result );
+                                               d.resolve( result );
                                        } else {
-                                               success ( false );
+                                               d.resolve( false );
                                        }
-                               };
+                               } )
+                               .fail( d.reject );
 
-                       return this.get( params, { ok: ok, err: err } );
+                       return d.promise();
                }
 
        } );
 
+       /**
+        * @class mw.Api
+        * @mixins mw.Api.plugin.titleblacklist
+        */
+
 }( mediaWiki, jQuery ) );