MediaWiki:Gadget-Botify.js: Difference between revisions

Jump to navigation Jump to search
POST and GET are similarly fast, so it's slower to check if bot first; if the POST succeeds, probably safe to assume the bot userright state
m (count arguments before callign callback)
(POST and GET are similarly fast, so it's slower to check if bot first; if the POST succeeds, probably safe to assume the bot userright state)
Line 7: Line 7:
function botify( addOrRemove, expiry, callback ) {
function botify( addOrRemove, expiry, callback ) {
//Create api options object
var apiOptions = {
var apiOptions = {
action: 'userrights',
action: 'userrights',
Line 12: Line 13:
};
};
apiOptions[addOrRemove] = 'bot';
apiOptions[addOrRemove] = 'bot';
if (addOrRemove === 'add') apiOptions.expiry = '1 minute' ; //TODO:Not working: It doesn't expire...
if (arguments.length >= 2 && addOrRemove === 'add') {
apiOptions.expiry = expiry ; //TODO:Not working: It doesn't expire...
}
var api = new mw.Api();
//Use POST to change bot userright
api.postWithToken('userrights', apiOptions).done(function(data){
(new mw.Api()).postWithToken('userrights', apiOptions).done(function(data){
console.log(data);
console.log(data);
console.log("User right changed");
console.log("Botify success.");
//TODO://Temporary for testing, don't forget to move the response() out
if (arguments.length >= 3) {
api.getUserInfo().done(function(data){
callback();
console.log(data.groups);
}
alert( (data.groups.indexOf("bot") > -1) ? "You are now a bot." : "You are now not a bot." );
if (arguments.length >= 3) callback();
});
}).fail(function(){
alert("Error in botify.");
});
});
Line 35: Line 37:
$('#choose_pages').on('submit', function(e){
$('#choose_pages').on('submit', function(e){
e.preventDefault();
e.preventDefault();
(new mw.Api()).getUserInfo().done(function(data){
botify('add', '1 minute', function(){
console.log(data.groups);
$('#choose_pages').off('submit').submit();
if (data.groups.indexOf("bot") === -1) botify('add', '1 minute', function(){$('#choose_pages').off('submit').submit()});
else $('#choose_pages').off('submit').submit();
});
});
});
});
3,972

edits

Navigation menu