2013-03-03 22:56:35 +00:00
|
|
|
/**
|
|
|
|
* @class mw.Api.plugin.titleblacklist
|
|
|
|
*/
|
2018-12-05 22:02:53 +00:00
|
|
|
( function () {
|
2013-03-03 22:56:35 +00:00
|
|
|
|
2024-06-20 19:26:22 +00:00
|
|
|
Object.assign( mw.Api.prototype, {
|
2013-03-03 22:56:35 +00:00
|
|
|
/**
|
2021-10-14 05:48:54 +00:00
|
|
|
* Convenience method for `action=titleblacklist`.
|
2013-03-03 22:56:35 +00:00
|
|
|
*
|
|
|
|
* @param {mw.Title|string} title
|
|
|
|
* @param {Function} [ok] Success callback (deprecated)
|
|
|
|
* @param {Function} [err] Error callback (deprecated)
|
|
|
|
* @return {jQuery.Promise}
|
|
|
|
* @return {Function} return.done
|
2018-12-05 22:02:53 +00:00
|
|
|
* @return {Object|boolean} return.done.result False if title wasn't blacklisted, an object
|
|
|
|
* with 'reason', 'line'
|
2013-03-03 22:56:35 +00:00
|
|
|
* and 'message' properties if title was blacklisted.
|
|
|
|
*/
|
|
|
|
isBlacklisted: function ( title, ok, err ) {
|
|
|
|
var d = $.Deferred();
|
|
|
|
// Backwards compatibility (< MW 1.20)
|
|
|
|
d.done( ok );
|
|
|
|
d.fail( err );
|
|
|
|
|
|
|
|
this.get( {
|
2018-12-05 22:02:53 +00:00
|
|
|
action: 'titleblacklist',
|
|
|
|
tbaction: 'create',
|
|
|
|
tbtitle: title.toString()
|
|
|
|
} )
|
2013-03-03 22:56:35 +00:00
|
|
|
.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.reason ) {
|
|
|
|
result = {
|
|
|
|
reason: data.titleblacklist.reason,
|
|
|
|
line: data.titleblacklist.line,
|
|
|
|
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
|
|
|
|
};
|
|
|
|
}
|
|
|
|
d.resolve( result );
|
|
|
|
} else {
|
|
|
|
d.resolve( false );
|
|
|
|
}
|
|
|
|
} )
|
|
|
|
.fail( d.reject );
|
|
|
|
|
|
|
|
return d.promise();
|
|
|
|
}
|
|
|
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class mw.Api
|
2024-05-31 15:45:47 +00:00
|
|
|
* @mixes mw.Api.plugin.titleblacklist
|
2013-03-03 22:56:35 +00:00
|
|
|
*/
|
|
|
|
|
2018-12-05 22:02:53 +00:00
|
|
|
}() );
|