summaryrefslogtreecommitdiff
path: root/resources/mediawiki.api/mediawiki.api.titleblacklist.js
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2012-05-03 13:01:35 +0200
committerPierre Schmitz <pierre@archlinux.de>2012-05-03 13:01:35 +0200
commitd9022f63880ce039446fba8364f68e656b7bf4cb (patch)
tree16b40fbf17bf7c9ee6f4ead25b16dd192378050a /resources/mediawiki.api/mediawiki.api.titleblacklist.js
parent27cf83d177256813e2e802241085fce5dd0f3fb9 (diff)
Update to MediaWiki 1.19.0
Diffstat (limited to 'resources/mediawiki.api/mediawiki.api.titleblacklist.js')
-rw-r--r--resources/mediawiki.api/mediawiki.api.titleblacklist.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/resources/mediawiki.api/mediawiki.api.titleblacklist.js b/resources/mediawiki.api/mediawiki.api.titleblacklist.js
new file mode 100644
index 00000000..5435945b
--- /dev/null
+++ b/resources/mediawiki.api/mediawiki.api.titleblacklist.js
@@ -0,0 +1,51 @@
+/**
+ * Additional mw.Api methods to assist with API calls to the API module of the TitleBlacklist extension.
+ */
+
+( function( $, mw, undefined ) {
+
+ $.extend( mw.Api.prototype, {
+ /**
+ * 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}
+ */
+ isBlacklisted: function( title, success, err ) {
+ var params = {
+ action: 'titleblacklist',
+ tbaction: 'create',
+ tbtitle: title.toString()
+ },
+ ok = 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 };
+ }
+ success( result );
+ } else {
+ success ( false );
+ }
+ };
+
+ return this.get( params, { ok: ok, err: err } );
+ }
+
+ } );
+} )( jQuery, mediaWiki );