wiki.techinc.nl/resources/mediawiki.api/mediawiki.api.titleblacklist.js

52 lines
1.8 KiB
JavaScript
Raw Normal View History

[mediawiki.api] clean up * Adding return values to most of the ajax functions so that the jqXHR object (originally returned by jQuery.ajax) is available. Some functions documented they already did this, some don't. Now they all do and are also documented as such. * Renaming a few 'callback' arguments to 'success' to avoid confusion with 'error'. * Removed unused variables ** mw.Api's instance this.url was unused ** var cachedToken was unused in mediawiki.api.titleblacklist.js * Making closure argument order the same and referencing mediaWiki as a global (mw is something thought not to be a global but mediaWiki certainly is, no need to access window from the global scope and then the mediaWiki property of it). Also renamed any used of $j to $. Adding 'undefined' to the closure arguments where missing. * Re-written the mw.Api constructor's logic for options. Now keeping a defaultOptions privately "statically" cached outside the constructor and using that to build the options object. * Made all non-block comments the same comment style (some were /* */ or /* \n */) * Completed parameter documentation and wrote TODO as @todo and added an example use for mw.Api in the documentation. * Some other random whitespacing, line breaking, merged var statement, and moved them out of blocks (since JS doesn't have block scope) into the main function body for clarity. And some other random JS Lint/JS Hint stuff. * Added comment to api.titleblacklist module about the module not being in core but in the TitleBlacklist extension.
2011-12-21 23:52:37 +00:00
/**
* Additional mw.Api methods to assist with API calls to the API module of the TitleBlacklist extension.
*/
[mediawiki.api] clean up * Adding return values to most of the ajax functions so that the jqXHR object (originally returned by jQuery.ajax) is available. Some functions documented they already did this, some don't. Now they all do and are also documented as such. * Renaming a few 'callback' arguments to 'success' to avoid confusion with 'error'. * Removed unused variables ** mw.Api's instance this.url was unused ** var cachedToken was unused in mediawiki.api.titleblacklist.js * Making closure argument order the same and referencing mediaWiki as a global (mw is something thought not to be a global but mediaWiki certainly is, no need to access window from the global scope and then the mediaWiki property of it). Also renamed any used of $j to $. Adding 'undefined' to the closure arguments where missing. * Re-written the mw.Api constructor's logic for options. Now keeping a defaultOptions privately "statically" cached outside the constructor and using that to build the options object. * Made all non-block comments the same comment style (some were /* */ or /* \n */) * Completed parameter documentation and wrote TODO as @todo and added an example use for mw.Api in the documentation. * Some other random whitespacing, line breaking, merged var statement, and moved them out of blocks (since JS doesn't have block scope) into the main function body for clarity. And some other random JS Lint/JS Hint stuff. * Added comment to api.titleblacklist module about the module not being in core but in the TitleBlacklist extension.
2011-12-21 23:52:37 +00:00
( function( $, mw, undefined ) {
[mediawiki.api] clean up * Adding return values to most of the ajax functions so that the jqXHR object (originally returned by jQuery.ajax) is available. Some functions documented they already did this, some don't. Now they all do and are also documented as such. * Renaming a few 'callback' arguments to 'success' to avoid confusion with 'error'. * Removed unused variables ** mw.Api's instance this.url was unused ** var cachedToken was unused in mediawiki.api.titleblacklist.js * Making closure argument order the same and referencing mediaWiki as a global (mw is something thought not to be a global but mediaWiki certainly is, no need to access window from the global scope and then the mediaWiki property of it). Also renamed any used of $j to $. Adding 'undefined' to the closure arguments where missing. * Re-written the mw.Api constructor's logic for options. Now keeping a defaultOptions privately "statically" cached outside the constructor and using that to build the options object. * Made all non-block comments the same comment style (some were /* */ or /* \n */) * Completed parameter documentation and wrote TODO as @todo and added an example use for mw.Api in the documentation. * Some other random whitespacing, line breaking, merged var statement, and moved them out of blocks (since JS doesn't have block scope) into the main function body for clarity. And some other random JS Lint/JS Hint stuff. * Added comment to api.titleblacklist module about the module not being in core but in the TitleBlacklist extension.
2011-12-21 23:52:37 +00:00
$.extend( mw.Api.prototype, {
/**
[mediawiki.api] clean up * Adding return values to most of the ajax functions so that the jqXHR object (originally returned by jQuery.ajax) is available. Some functions documented they already did this, some don't. Now they all do and are also documented as such. * Renaming a few 'callback' arguments to 'success' to avoid confusion with 'error'. * Removed unused variables ** mw.Api's instance this.url was unused ** var cachedToken was unused in mediawiki.api.titleblacklist.js * Making closure argument order the same and referencing mediaWiki as a global (mw is something thought not to be a global but mediaWiki certainly is, no need to access window from the global scope and then the mediaWiki property of it). Also renamed any used of $j to $. Adding 'undefined' to the closure arguments where missing. * Re-written the mw.Api constructor's logic for options. Now keeping a defaultOptions privately "statically" cached outside the constructor and using that to build the options object. * Made all non-block comments the same comment style (some were /* */ or /* \n */) * Completed parameter documentation and wrote TODO as @todo and added an example use for mw.Api in the documentation. * Some other random whitespacing, line breaking, merged var statement, and moved them out of blocks (since JS doesn't have block scope) into the main function body for clarity. And some other random JS Lint/JS Hint stuff. * Added comment to api.titleblacklist module about the module not being in core but in the TitleBlacklist extension.
2011-12-21 23:52:37 +00:00
* 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}
*/
[mediawiki.api] clean up * Adding return values to most of the ajax functions so that the jqXHR object (originally returned by jQuery.ajax) is available. Some functions documented they already did this, some don't. Now they all do and are also documented as such. * Renaming a few 'callback' arguments to 'success' to avoid confusion with 'error'. * Removed unused variables ** mw.Api's instance this.url was unused ** var cachedToken was unused in mediawiki.api.titleblacklist.js * Making closure argument order the same and referencing mediaWiki as a global (mw is something thought not to be a global but mediaWiki certainly is, no need to access window from the global scope and then the mediaWiki property of it). Also renamed any used of $j to $. Adding 'undefined' to the closure arguments where missing. * Re-written the mw.Api constructor's logic for options. Now keeping a defaultOptions privately "statically" cached outside the constructor and using that to build the options object. * Made all non-block comments the same comment style (some were /* */ or /* \n */) * Completed parameter documentation and wrote TODO as @todo and added an example use for mw.Api in the documentation. * Some other random whitespacing, line breaking, merged var statement, and moved them out of blocks (since JS doesn't have block scope) into the main function body for clarity. And some other random JS Lint/JS Hint stuff. * Added comment to api.titleblacklist module about the module not being in core but in the TitleBlacklist extension.
2011-12-21 23:52:37 +00:00
isBlacklisted: function( title, success, err ) {
var params = {
action: 'titleblacklist',
tbaction: 'create',
tbtitle: title.toString()
},
ok = function( data ) {
var result;
[mediawiki.api] clean up * Adding return values to most of the ajax functions so that the jqXHR object (originally returned by jQuery.ajax) is available. Some functions documented they already did this, some don't. Now they all do and are also documented as such. * Renaming a few 'callback' arguments to 'success' to avoid confusion with 'error'. * Removed unused variables ** mw.Api's instance this.url was unused ** var cachedToken was unused in mediawiki.api.titleblacklist.js * Making closure argument order the same and referencing mediaWiki as a global (mw is something thought not to be a global but mediaWiki certainly is, no need to access window from the global scope and then the mediaWiki property of it). Also renamed any used of $j to $. Adding 'undefined' to the closure arguments where missing. * Re-written the mw.Api constructor's logic for options. Now keeping a defaultOptions privately "statically" cached outside the constructor and using that to build the options object. * Made all non-block comments the same comment style (some were /* */ or /* \n */) * Completed parameter documentation and wrote TODO as @todo and added an example use for mw.Api in the documentation. * Some other random whitespacing, line breaking, merged var statement, and moved them out of blocks (since JS doesn't have block scope) into the main function body for clarity. And some other random JS Lint/JS Hint stuff. * Added comment to api.titleblacklist module about the module not being in core but in the TitleBlacklist extension.
2011-12-21 23:52:37 +00:00
// 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 };
}
success( result );
} else {
[mediawiki.api] clean up * Adding return values to most of the ajax functions so that the jqXHR object (originally returned by jQuery.ajax) is available. Some functions documented they already did this, some don't. Now they all do and are also documented as such. * Renaming a few 'callback' arguments to 'success' to avoid confusion with 'error'. * Removed unused variables ** mw.Api's instance this.url was unused ** var cachedToken was unused in mediawiki.api.titleblacklist.js * Making closure argument order the same and referencing mediaWiki as a global (mw is something thought not to be a global but mediaWiki certainly is, no need to access window from the global scope and then the mediaWiki property of it). Also renamed any used of $j to $. Adding 'undefined' to the closure arguments where missing. * Re-written the mw.Api constructor's logic for options. Now keeping a defaultOptions privately "statically" cached outside the constructor and using that to build the options object. * Made all non-block comments the same comment style (some were /* */ or /* \n */) * Completed parameter documentation and wrote TODO as @todo and added an example use for mw.Api in the documentation. * Some other random whitespacing, line breaking, merged var statement, and moved them out of blocks (since JS doesn't have block scope) into the main function body for clarity. And some other random JS Lint/JS Hint stuff. * Added comment to api.titleblacklist module about the module not being in core but in the TitleBlacklist extension.
2011-12-21 23:52:37 +00:00
success ( false );
}
[mediawiki.api] clean up * Adding return values to most of the ajax functions so that the jqXHR object (originally returned by jQuery.ajax) is available. Some functions documented they already did this, some don't. Now they all do and are also documented as such. * Renaming a few 'callback' arguments to 'success' to avoid confusion with 'error'. * Removed unused variables ** mw.Api's instance this.url was unused ** var cachedToken was unused in mediawiki.api.titleblacklist.js * Making closure argument order the same and referencing mediaWiki as a global (mw is something thought not to be a global but mediaWiki certainly is, no need to access window from the global scope and then the mediaWiki property of it). Also renamed any used of $j to $. Adding 'undefined' to the closure arguments where missing. * Re-written the mw.Api constructor's logic for options. Now keeping a defaultOptions privately "statically" cached outside the constructor and using that to build the options object. * Made all non-block comments the same comment style (some were /* */ or /* \n */) * Completed parameter documentation and wrote TODO as @todo and added an example use for mw.Api in the documentation. * Some other random whitespacing, line breaking, merged var statement, and moved them out of blocks (since JS doesn't have block scope) into the main function body for clarity. And some other random JS Lint/JS Hint stuff. * Added comment to api.titleblacklist module about the module not being in core but in the TitleBlacklist extension.
2011-12-21 23:52:37 +00:00
};
return this.get( params, { ok: ok, err: err } );
}
} );
[mediawiki.api] clean up * Adding return values to most of the ajax functions so that the jqXHR object (originally returned by jQuery.ajax) is available. Some functions documented they already did this, some don't. Now they all do and are also documented as such. * Renaming a few 'callback' arguments to 'success' to avoid confusion with 'error'. * Removed unused variables ** mw.Api's instance this.url was unused ** var cachedToken was unused in mediawiki.api.titleblacklist.js * Making closure argument order the same and referencing mediaWiki as a global (mw is something thought not to be a global but mediaWiki certainly is, no need to access window from the global scope and then the mediaWiki property of it). Also renamed any used of $j to $. Adding 'undefined' to the closure arguments where missing. * Re-written the mw.Api constructor's logic for options. Now keeping a defaultOptions privately "statically" cached outside the constructor and using that to build the options object. * Made all non-block comments the same comment style (some were /* */ or /* \n */) * Completed parameter documentation and wrote TODO as @todo and added an example use for mw.Api in the documentation. * Some other random whitespacing, line breaking, merged var statement, and moved them out of blocks (since JS doesn't have block scope) into the main function body for clarity. And some other random JS Lint/JS Hint stuff. * Added comment to api.titleblacklist module about the module not being in core but in the TitleBlacklist extension.
2011-12-21 23:52:37 +00:00
} )( jQuery, mediaWiki );