User:MusikAnimal/spamublock.js: Difference between revisions

Content deleted Content added
p-cactions
add draftspace
 
(12 intermediate revisions by 2 users not shown)
Line 1:
//<nowiki>
$(function() {
var namespace = mw.config.get('wgNamespaceNumber'),
pageName = mw.config.get('wgPageName'),
myUserName = mw.config.get('wgUserName'),
userName = mw.config.get('wgRelevantUserName'),
templateName = "uw-spamublock";,
blockReason,
api;
 
if([0,2,3,118].indexOf(namespace) !== -1) {
mw.loader.using( [ 'mediawiki.api', 'mediawiki.util' ] ).done( function() {
mw.util.addPortletLink(
api = new mw.Api();
'p-cactions', 'javascript:void(0)',
mw.util.addPortletLink(
'{{spamublock}}', 't-spamublock', 'Delete user page and execute {{uw-spamublock}} on current user'
'p-cactions', 'javascript:void(0)',
);
'{{spamublock}}', 'ca-spamublock', 'Delete user page and execute {{uw-spamublock}} on current user'
);
} );
 
$('#tca-spamublock').on('click', function() {
if (confirm('This script will delete the current user page, block the relevant user or page creator as {{uw-spamublock}} and leave that template on their talk page, or the template specified at [[Special:MyPage/uw-spamublock]], if present.\n\nARE YOU SURE YOU WANT TO PROCEED?')) {
$('#tca-spamublock').text('Please wait...');
if(!userName) {
getTemplate();
api.get({
}
action: 'query',
});
prop: 'revisions',
}
titles: pageName,
rvdir: 'newer',
rvlimit: '1',
rvprop: 'user'
}).then(function(data) {
var pages = data.query.pages;
userName = pages[Object.keys(pages)[0]].revisions[0].user;
getTemplate();
});
} else {
getTemplate();
}
}
});
}
 
function getTemplate() {
var api = new mw.Api();
api.get({
action: 'query',
titles: 'User:'+myUserName+'/uw-spamublock'
}).then(function(data) {
var query = data.query.pages;
if(Object.keys(query)[0] > 0) {
templateName = 'User:'+myUserName+'/uw-spamublock';
} else {
templateName += "|sig=yes";
}
templateName = "{{subst:"+templateName+"}}";
deleteUserPage();
});
}
function getBlockReason() {
api.get({
action: 'query',
titles: 'User:'+myUserName+'/spamublock-message'
}).then(function(data) {
var query = data.query.pages;
if(Object.keys(query)[0] > 0) {
blockReason = '{{User:'+myUserName+'/spamublock-message}}';
} else {
blockReason = '{{uw-spamublock}} <!-- Promotional username, promotional edits -->';
}
blockUser();
});
}
 
function getTemplatedeleteUserPage() {
api.postWithToken("delete", {
api.get({
action: 'querydelete',
reason: '[[WP:G11|G11]]: Unambiguous [[WP:NOTADVERTISING|advertising]] or promotion',
titles: 'User:'+myUserName+'/uw-spamublock'
title: pageName
}).then(function(data) {
}).then(function(deleteData) {
var query = data.query.pages;
$("#mw-content-text").html(
if(Object.keys(query)[0] > 0) {
"<p><b>Deleted</b> page <a href='"+mw.util.getUrl(pageName)+"'>"+pageName+"</a> <i>(<a href='"+mw.util.getUrl('WP:G11')+"'>G11</a>: Unambiguous <a href='"+mw.util.getUrl('WP:NOTADVERTISING')+"'>advertising</a> or promotion)</i></p>"
templateName = 'User:'+myUserName+'/uw-spamublock';
);
} else {
getBlockReason();
templateName += "|sig=yes";
},function(error) {
}
$("#mw-content-text").html(
templateName = "{{subst:"+templateName+"}}";
"<p><b>Error</b> deleting page "+pageName+": "+error+"</p>"
deleteUserPage();
} );
});
}
}
 
function deleteUserPageblockUser() {
api.postWithToken("deleteblock", {
action: 'deleteblock',
allowusertalk: true,
reason: '[[WP:G11|G11]]: Unambiguous [[WP:NOTADVERTISING|advertising]] or promotion',
autoblock: true,
title: pageName
nocreate: true,
}).then(function(deleteData) {
reason: blockReason,
$("#mw-content-text").html(
user: userName
"<p><b>Deleted</b> page <a href='"+mw.util.getUrl(pageName)+"'>"+pageName+"</a> <i>(<a href='"+mw.util.getUrl('WP:G11')+"'>G11</a>: Unambiguous <a href='"+mw.util.getUrl('WP:NOTADVERTISING')+"'>advertising</a> or promotion)</i></p>"
}).then(function(blockData) {
);
$("#mw-content-text").append(
blockUser();
"<p><b>Blocked</b> <a href='"+mw.util.getUrl('User:'+userName)+"'>"+userName+"</a> (account creation blocked) with an expiry time of indefinite <i>(<span id='spamublock-blocked-reason'></span>)</i></p>"
},function(error) {
);
$("#mw-content-text").html(
$('<span/>').text(blockReason).appendTo("#spamublock-blocked-reason");
"<p><b>Error</b> deleting page "+pageName+": "+error+"</p>"
templateUser();
);
}, function(error) {
});
$("#mw-content-text").append(
}
"<p><b>Error</b> blocking <a href='"+mw.util.getUrl('User:'+userName)+"'>"+userName+"</a>: "+error+"</p>"
);
});
}
 
function blockUsertemplateUser() {
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
var blockReason = '{{uw-spamublock}} <!-- Promotional username, promotional edits -->';
d = new Date();
api.postWithToken("block", {
action: 'block',
allowusertalk: true,
autoblock: true,
nocreate: true,
reason: blockReason,
user: userName
}).then(function(blockData) {
$("#mw-content-text").append(
"<p><b>Blocked</b> <a href='"+mw.util.getUrl('User:'+userName)+"'>"+userName+"</a> (account creation blocked) with an expiry time of indefinite <i>(<span id='spamublock-blocked-reason'></span>)</i></p>"
);
$('<span/>').text(blockReason).appendTo("#spamublock-blocked-reason");
templateUser();
}, function(error) {
$("#mw-content-text").append(
"<p><b>Error</b> blocking <a href='"+mw.util.getUrl('User:'+userName)+"'>"+userName+"</a>: "+error+"</p>"
);
});
}
 
api.postWithToken( "edit", {
function templateUser() {
action: "edit",
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
section: 'new',
d = new Date();
sectiontitle: monthNames[d.getMonth()] + ' ' + d.getFullYear(),
 
summary: "You have been indefinitely blocked from editing because your account is being used only for [[WP:SPAM|spam or advertising]] and your username is a violation of the [[WP:U|username policy]]. (using [[User:MusikAnimal/spamublock|spamublock.js]])",
api.postWithToken( "edit", {
text: "\n"+templateName,
action: "edit",
title: "User talk:"+userName
section: 'new',
}).then(function(editData) {
sectiontitle: monthNames[d.getMonth()] + ' ' + d.getFullYear(),
$("#mw-content-text").append(
summary: "You have been indefinitely blocked from editing because your account is being used only for [[WP:SPAM|spam or advertising]] and your username is a violation of the [[WP:U|username policy]]. (using [[User:MusikAnimal/spamublock|spamublock.js]])",
"<p><b>Edited</b> <a href='"+mw.util.getUrl('User talk:'+userName)+"'>User talk:"+userName+"</a>: Created new section with template "+templateName+"</p>" +
text: "\n"+templateName,
"<p><b>Complete (<a href='javascript:document.___location.reload()'>reload</a>)</b></p>"
title: "User talk:"+userName
);
}).then(function(editData) {
},function(error) {
$("#mw-content-text").append(
$("#mw-content-text").append(
"<p><b>Edited</b> <a href='"+mw.util.getUrl('User talk:'+userName)+"'>User talk:"+userName+"</a>: Created new section with template "+templateName+"</p>" +
"<p><b>CompleteError</b> editing (<a href='javascript:document"+mw.___locationutil.reloadgetUrl('User talk:'+userName)+"'>reloadUser talk:"+userName+"</a>)</b>: "+error+"</p>"
);
});
},function(error) {
}
$("#mw-content-text").append(
});
"<p><b>Error</b> editing <a href='"+mw.util.getUrl('User talk:'+userName)+"'>User talk:"+userName+"</a>: "+error+"</p>"
);
});
}
}());
//</nowiki>