User:Synoman Barris/common.js: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary Tag: Reverted |
||
Line 5: | Line 5: | ||
myUserName = mw.config.get('wgUserName'), |
myUserName = mw.config.get('wgUserName'), |
||
userName = mw.config.get('wgRelevantUserName'), |
userName = mw.config.get('wgRelevantUserName'), |
||
templateName = "uw- |
templateName = "uw-vandalism", |
||
blockReason, |
blockReason, |
||
api; |
api; |
||
Line 14: | Line 14: | ||
mw.util.addPortletLink( |
mw.util.addPortletLink( |
||
'p-cactions', 'javascript:void(0)', |
'p-cactions', 'javascript:void(0)', |
||
' |
'Delete and block vandal', 'ca-block', 'Delete user page and execute {{uw-vandalism}} on current user' |
||
); |
); |
||
} ); |
} ); |
||
$('#ca-spamublock').on('click', function() { |
$('#ca-spamublock').on('click', function() { |
||
if (confirm('This script will delete the current user page, block the relevant user or page creator as {{uw- |
if (confirm('This script will delete the current user page, block the relevant user or page creator as {{uw-vandalism}} 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?')) { |
||
$('#ca-spamublock').text('Please wait...'); |
$('#ca-spamublock').text('Please wait...'); |
||
if(!userName) { |
if(!userName) { |
||
Line 44: | Line 44: | ||
api.get({ |
api.get({ |
||
action: 'query', |
action: 'query', |
||
titles: 'User:'+myUserName+'/uw- |
titles: 'User:'+myUserName+'/uw-vandal' |
||
}).then(function(data) { |
}).then(function(data) { |
||
var query = data.query.pages; |
var query = data.query.pages; |
||
if(Object.keys(query)[0] > 0) { |
if(Object.keys(query)[0] > 0) { |
||
templateName = 'User:'+myUserName+'/uw- |
templateName = 'User:'+myUserName+'/uw-vandal'; |
||
} else { |
} else { |
||
templateName += "|sig=yes"; |
templateName += "|sig=yes"; |
||
Line 60: | Line 60: | ||
api.get({ |
api.get({ |
||
action: 'query', |
action: 'query', |
||
titles: 'User:'+myUserName+'/ |
titles: 'User:'+myUserName+'/vandalism message' |
||
}).then(function(data) { |
}).then(function(data) { |
||
var query = data.query.pages; |
var query = data.query.pages; |
||
Line 66: | Line 66: | ||
blockReason = '{{User:'+myUserName+'/spamublock-message}}'; |
blockReason = '{{User:'+myUserName+'/spamublock-message}}'; |
||
} else { |
} else { |
||
blockReason = ' |
blockReason = 'excessive Vandalism/spam/nonsense |
||
} |
} |
||
blockUser(); |
blockUser(); |
||
Line 75: | Line 75: | ||
api.postWithToken("delete", { |
api.postWithToken("delete", { |
||
action: 'delete', |
action: 'delete', |
||
reason: 'Nonsense/Bad page/Vandalism', |
|||
reason: '[[WP:G11|G11]]: Unambiguous [[WP:NOTADVERTISING|advertising]] or promotion', |
|||
title: pageName |
title: pageName |
||
}).then(function(deleteData) { |
}).then(function(deleteData) { |
||
Line 99: | Line 99: | ||
}).then(function(blockData) { |
}).then(function(blockData) { |
||
$("#mw-content-text").append( |
$("#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=' |
"<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='vandalism-blocked-reason'></span>)</i></p>" |
||
); |
); |
||
$('<span/>').text(blockReason).appendTo("#spamublock-blocked-reason"); |
$('<span/>').text(blockReason).appendTo("#spamublock-blocked-reason"); |
||
Line 118: | Line 118: | ||
section: 'new', |
section: 'new', |
||
sectiontitle: monthNames[d.getMonth()] + ' ' + d.getFullYear(), |
sectiontitle: monthNames[d.getMonth()] + ' ' + d.getFullYear(), |
||
summary: "You have been indefinitely blocked from editing because your account is being used only for |
summary: "You have been indefinitely blocked from editing because your account is being used only for Vandalism and your username is a violation of the username policy. (using [[User: Synoman Barris/ahh|You here]])", |
||
text: "\n"+templateName, |
text: "\n"+templateName, |
||
title: "User talk:"+userName |
title: "User talk:"+userName |
Revision as of 14:25, 5 March 2022
//<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-vandalism",
blockReason,
api;
if([0,2,3].indexOf(namespace) !== -1) {
mw.loader.using( [ 'mediawiki.api', 'mediawiki.util' ] ).done( function() {
api = new mw.Api();
mw.util.addPortletLink(
'p-cactions', 'javascript:void(0)',
'Delete and block vandal', 'ca-block', 'Delete user page and execute {{uw-vandalism}} on current user'
);
} );
$('#ca-spamublock').on('click', function() {
if (confirm('This script will delete the current user page, block the relevant user or page creator as {{uw-vandalism}} 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?')) {
$('#ca-spamublock').text('Please wait...');
if(!userName) {
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() {
api.get({
action: 'query',
titles: 'User:'+myUserName+'/uw-vandal'
}).then(function(data) {
var query = data.query.pages;
if(Object.keys(query)[0] > 0) {
templateName = 'User:'+myUserName+'/uw-vandal';
} else {
templateName += "|sig=yes";
}
templateName = "{{subst:"+templateName+"}}";
deleteUserPage();
});
}
function getBlockReason() {
api.get({
action: 'query',
titles: 'User:'+myUserName+'/vandalism message'
}).then(function(data) {
var query = data.query.pages;
if(Object.keys(query)[0] > 0) {
blockReason = '{{User:'+myUserName+'/spamublock-message}}';
} else {
blockReason = 'excessive Vandalism/spam/nonsense
}
blockUser();
});
}
function deleteUserPage() {
api.postWithToken("delete", {
action: 'delete',
reason: 'Nonsense/Bad page/Vandalism',
title: pageName
}).then(function(deleteData) {
$("#mw-content-text").html(
"<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>"
);
getBlockReason();
},function(error) {
$("#mw-content-text").html(
"<p><b>Error</b> deleting page "+pageName+": "+error+"</p>"
);
});
}
function blockUser() {
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='vandalism-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>"
);
});
}
function templateUser() {
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
d = new Date();
api.postWithToken( "edit", {
action: "edit",
section: 'new',
sectiontitle: monthNames[d.getMonth()] + ' ' + d.getFullYear(),
summary: "You have been indefinitely blocked from editing because your account is being used only for Vandalism and your username is a violation of the username policy. (using [[User: Synoman Barris/ahh|You here]])",
text: "\n"+templateName,
title: "User talk:"+userName
}).then(function(editData) {
$("#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>Complete (<a href='javascript:document.location.reload()'>reload</a>)</b></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>