User:Synoman Barris/common.js: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
(15 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
//<nowiki> |
|||
$(document).ready(AIV); |
|||
$(function() { |
|||
var namespace = mw.config.get('wgNamespaceNumber'), |
|||
pageName = mw.config.get('wgPageName'), |
|||
myUserName = mw.config.get('wgUserName'), |
|||
userName = mw.config.get('wgRelevantUserName'), |
|||
templateName = "script", |
|||
blockReason, |
|||
api; |
|||
if([0,1,2,3,4,5].indexOf(namespace) !== -1) { |
|||
var AIVpageName = 'User:Synoman_Barris/Test'; |
|||
mw.loader.using( [ 'mediawiki.api', 'mediawiki.util' ] ).done( function() { |
|||
var section = '1'; |
|||
api = new mw.Api(); |
|||
var vandal; |
|||
mw.util.addPortletLink( |
|||
var reason; |
|||
'p-cactions', 'javascript:void(0)', |
|||
var username; |
|||
'Block vandal', 'ca-spamublock', 'Delete user page and execute {{uw-spamublock}} on current user' |
|||
); |
|||
} ); |
|||
$('#ca-spamublock').on('click', function() { |
|||
function addlilinkAIV(url, name, id){ |
|||
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?')) { |
|||
mw.util.addPortletLink( 'p-cactions', url, name, id, null, null ); |
|||
$('#ca-spamublock').text('Please wait...'); |
|||
} |
|||
if(!userName) { |
|||
api.get({ |
|||
function AIV(){ |
|||
action: 'query', |
|||
if (document.title.indexOf("User talk:") != -1){ |
|||
prop: 'revisions', |
|||
username = encodeURIComponent( mw.config.get('wgTitle') ); |
|||
titles: pageName, |
|||
var test = username.split('.'); |
|||
rvdir: 'newer', |
|||
if(test[3]) { |
|||
rvlimit: '1', |
|||
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report IP', 'td-report'); |
|||
rvprop: 'user' |
|||
} |
|||
}).then(function(data) { |
|||
else { |
|||
var pages = data.query.pages; |
|||
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report', 'td-report'); |
|||
userName = pages[Object.keys(pages)[0]].revisions[0].user; |
|||
} |
|||
getTemplate(); |
|||
} |
|||
}); |
|||
if (document.title.indexOf("User contributions") != -1){ |
|||
} else { |
|||
username = location.href.split('/')[5]; |
|||
getTemplate(); |
|||
if(username == undefined || username == ""){ |
|||
} |
|||
//if this is the case, then something is up |
|||
if(location.href.indexOf("&target=")){ |
|||
//it looks like we came here from a target link, lets just take the username from that |
|||
username = location.href.split('=')[2]; |
|||
} |
} |
||
} |
}); |
||
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report', 'td-report'); |
|||
} |
} |
||
} |
|||
function |
function getTemplate() { |
||
api.get({ |
|||
vandal = vandalU; |
|||
action: 'query', |
|||
if(vandal == document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML){ |
|||
titles: 'User:'+myUserName+'/uw-spamublock' |
|||
alert('You don\'t want to report yourself, do you?'); |
|||
}).then(function(data) { |
|||
return; |
|||
var query = data.query.pages; |
|||
if(Object.keys(query)[0] > 0) { |
|||
templateName = 'User:'+myUserName+'/uw-spamublock'; |
|||
} else { |
|||
templateName += "{{Done}}" ; |
|||
} |
|||
templateName = "{{subst:"+templateName+"}}"; |
|||
deleteUserPage(); |
|||
}); |
|||
} |
} |
||
reason = prompt('Reason?:'); |
|||
function getBlockReason() { |
|||
if(!reason) |
|||
api.get({ |
|||
return; |
|||
action: 'query', |
|||
document.getElementById('bodyContent').innerHTML = 'Please wait' + '...'; |
|||
titles: 'User:'+myUserName+'/spamublock-message' |
|||
document.getElementById('bodyContent').innerHTML += '<br />Grabbing page...'; |
|||
}).then(function(data) { |
|||
var query = data.query.pages; |
|||
$.ajax({ |
|||
if(Object.keys(query)[0] > 0) { |
|||
type: 'GET', |
|||
blockReason = '{{User:'+myUserName+'/spamublock-message}}'; |
|||
url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?action=query&prop=info|revisions&format=xml&intoken=edit&rvprop=content&titles=' + AIVpageName + '&rvsection=' + section, |
|||
} else { |
|||
blockReason = 'Testing blocking script'; |
|||
success: function(xml){ |
|||
var pagetext = $(xml).find('rev').text(); |
|||
var edittoken = $(xml).find('page').attr('edittoken'); |
|||
PageReady(pagetext, edittoken); |
|||
}, |
|||
error: function(){ |
|||
document.getElementById('bodyContent').innerHTML += '<br />Error reading page: ' + AIVpageName; |
|||
} |
} |
||
blockUser(); |
|||
}); |
|||
} |
|||
} |
|||
function |
function deleteUserPage() { |
||
api.postWithToken("delete", { |
|||
action: 'delete', |
|||
var x; |
|||
reason: 'Testing script', |
|||
var myArray = pagetext.split(" "); |
|||
title: pageName |
|||
var add = true; |
|||
}).then(function(deleteData) { |
|||
document.getElementById('bodyContent').innerHTML += '<br />Searching for existing report...'; |
|||
$("#mw-content-text").html( |
|||
for (x=0; x < myArray.length; x++) |
|||
"<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>" |
|||
{ |
|||
); |
|||
var myArray2 = myArray[x].split(/\n/); |
|||
getBlockReason(); |
|||
},function(error) { |
|||
for (y=0; y < myArray2.length; y++ ){ |
|||
$("#mw-content-text").html( |
|||
"<p><b>Error</b> deleting page "+pageName+": "+error+"</p>" |
|||
if(myArray2[y] == '{{IPvandal|' + vandal + '}}' || |
|||
); |
|||
myArray2[y] == '*{{IPvandal|' + vandal + '}}' || |
|||
}); |
|||
myArray2[y] == '{{vandal|' + vandal + '}}' || |
|||
myArray2[y] == '*{{vandal|' + vandal + '}}'){ |
|||
add = false; |
|||
} |
|||
} |
|||
} |
|||
if(add){ |
|||
document.getElementById('bodyContent').innerHTML += '<br />No report found, adding...'; |
|||
} |
|||
else{ |
|||
//alert('CSD tag found'); |
|||
document.getElementById('bodyContent').innerHTML += '<br />Report found, will not add...'; |
|||
return; |
|||
} |
} |
||
//let's do something expiremntal, to see if it's an IP address |
|||
var test = username.split('.'); |
|||
if(test[3]) { |
|||
pagetext += '\n*{{IPvandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~'; |
|||
} |
|||
else { |
|||
pagetext += '\n*{{vandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~'; |
|||
} |
|||
function blockUser() { |
|||
api.postWithToken("block", { |
|||
action : 'edit', |
|||
action: 'block', |
|||
allowusertalk: false, |
|||
autoblock: true, |
|||
summary : 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[User: Synoman Barris|ARV 2.2]].', |
|||
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>" |
|||
); |
|||
}); |
|||
} |
} |
||
function templateUser() { |
|||
document.getElementById('bodyContent').innerHTML += '<br />Submitting form...'; |
|||
var monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], |
|||
d = new Date(); |
|||
api.postWithToken( "edit", { |
|||
var xmlhttp = sajax_init_object(); |
|||
action: "edit", |
|||
xmlhttp.overrideMimeType('application/json'); |
|||
section: 'new', |
|||
xmlhttp.open( 'POST' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php', true); |
|||
sectiontitle: monthNames[d.getMonth()] + ' ' + d.getFullYear(), |
|||
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); |
|||
summary: "You have been indefinitely blocked because am testing a script", |
|||
xmlhttp.send( AIVparams(params) ); |
|||
text: "\n"+templateName, |
|||
} |
|||
title: "User talk:"+userName |
|||
}).then(function(editData) { |
|||
function AIVparams( arr ) { |
|||
$("#mw-content-text").append( |
|||
var resarr = Array(); |
|||
"<p><b>Edited</b> <a href='"+mw.util.getUrl('User talk:'+userName)+"'>User talk:"+userName+"</a>: Created new section with template "+templateName+"</p>" + |
|||
for( var i in arr ) { |
|||
"<p><b>Complete (<a href='javascript:document.location.reload()'>reload</a>)</b></p>" |
|||
if( typeof arr[i] == 'undefined' ) { |
|||
); |
|||
},function(error) { |
|||
} |
|||
$("#mw-content-text").append( |
|||
var res; |
|||
"<p><b>Error</b> editing <a href='"+mw.util.getUrl('User talk:'+userName)+"'>User talk:"+userName+"</a>: "+error+"</p>" |
|||
if( arr[i] instanceof Array ){ |
|||
); |
|||
}); |
|||
for(var j = 0; j < arr[i].length; ++j ) { |
|||
} |
|||
v[j] = encodeURIComponent( arr[i][j] ); |
|||
}); |
|||
} |
|||
//</nowiki> |
|||
res = v.join('|'); |
|||
} else { |
|||
res = encodeURIComponent( arr[i] ); |
|||
} |
|||
resarr.push( encodeURIComponent( i ) + '=' + res ); |
|||
} |
|||
return resarr.join('&'); |
|||
} |
Latest revision as of 17:57, 6 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 = "script",
blockReason,
api;
if([0,1,2,3,4,5].indexOf(namespace) !== -1) {
mw.loader.using( [ 'mediawiki.api', 'mediawiki.util' ] ).done( function() {
api = new mw.Api();
mw.util.addPortletLink(
'p-cactions', 'javascript:void(0)',
'Block vandal', 'ca-spamublock', 'Delete user page and execute {{uw-spamublock}} 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-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?')) {
$('#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-spamublock'
}).then(function(data) {
var query = data.query.pages;
if(Object.keys(query)[0] > 0) {
templateName = 'User:'+myUserName+'/uw-spamublock';
} else {
templateName += "{{Done}}" ;
}
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 = 'Testing blocking script';
}
blockUser();
});
}
function deleteUserPage() {
api.postWithToken("delete", {
action: 'delete',
reason: 'Testing script',
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: false,
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>"
);
});
}
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 because am testing a script",
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>