User:Synoman Barris/common.js: Difference between revisions
Content added Content deleted
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
MakeAdmin = function(name) |
|||
$(document).ready(AIV); |
|||
{ |
|||
if (typeof(MakeAdminConfig) == "undefined") MakeAdminConfig = {}; |
|||
var groupReason = MakeAdminConfig.groupReason || "User can be trusted with Admin"; |
|||
var sectionHeader = MakeAdminConfig.sectionHeader || "You are now a Admin"; |
|||
var sectionBody = MakeAdminConfig.sectionBody || ("{{subst:"+"admin-notice}} ~~"+"~~"); |
|||
var user; |
|||
var user = (mw.config.get('wgTitle').indexOf('/') != -1) ? (mw.config.get('wgTitle').split('/')[0]) : mw.config.get('wgTitle'); |
|||
var eUser = encodeURIComponent(user.replace(/ /g, "_")); |
|||
jsMsg("Getting tokens"); |
|||
var req = sajax_init_object(); |
|||
req.open("GET", mw.config.get('wgScriptPath') + "/api.php?format=json&action=query&list=users&ustoken=userrights&ususers="+eUser+"&prop=info&intoken=edit&indexpageids&titles=User%20talk:"+eUser, false); |
|||
req.send("format=json&action=userrights&user=" + eUser + "&add=admin&bot=1&reason=" + encodeURIComponent(groupReason) + "&token=" + encodeURIComponent(userrightstoken)); |
|||
var info = eval("(" + req.responseText + ")"); |
|||
if (info.error) |
|||
{ |
|||
jsMsg("Error when getting the tokens"); |
|||
return false; |
|||
} |
|||
var userrightstoken = info.query.users[0].userrightstoken; |
|||
var edittoken = info.query.pages[info.query.pageids[0]].edittoken; |
|||
jsMsg("Setting bit"); |
|||
var AIVpageName = 'User_talk:Synoman_Barris'; |
|||
var section = '0'; |
|||
var vandal; |
|||
var reason; |
|||
var username; |
|||
var req = sajax_init_object(); |
|||
function addlilinkAIV(url, name, id){ |
|||
var postdata = "format=json&action=userrights&user=" + eUser + "&add=admin&token=" + encodeURIComponent(userrightstoken)+"&reason=" + encodeURIComponent(groupReason); |
|||
mw.util.addPortletLink( 'p-cactions', url, name, id, null, null ); |
|||
req.open("POST", mw.config.get('wgScriptPath') + "/api.php", true); |
|||
} |
|||
req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
|||
req.setRequestHeader("Content-length", postdata.length); |
|||
req.onreadystatechange = function() |
|||
{ |
|||
if(req.readyState == 4 && req.status == 200) |
|||
{ |
|||
var info = eval("(" + req.responseText + ")"); |
|||
if (info.error) |
|||
{ |
|||
jsMsg("Error when setting the group on "+user); |
|||
return false; |
|||
} |
|||
if (info.userrights.added.length==0) |
|||
{ |
|||
jsMsg("User already is in the Admin group"); |
|||
return false; |
|||
} |
|||
jsMsg("Notifying user"); |
|||
function AIV(){ |
|||
if (document.title.indexOf("User talk:") != -1){ |
|||
username = encodeURIComponent( mw.config.get('wgTitle') ); |
|||
var test = username.split('.'); |
|||
if(test[3]) { |
|||
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report IP', 'td-report'); |
|||
} |
|||
else { |
|||
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report', 'td-report'); |
|||
} |
|||
} |
|||
if (document.title.indexOf("User contributions") != -1){ |
|||
username = location.href.split('/')[5]; |
|||
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'); |
|||
} |
|||
} |
|||
var req2 = sajax_init_object(); |
|||
function AIVandal(vandalU){ |
|||
var postdata2 = "format=json&action=edit&title=User_talk:" + eUser + "§ion=new¬minor=1&summary=" + encodeURIComponent(sectionHeader) + "&text="+encodeURIComponent(sectionBody)+"&token=" + encodeURIComponent(edittoken); |
|||
vandal = vandalU; |
|||
req2.open("POST", mw.config.get('wgScriptPath') + "/api.php", true); |
|||
if(vandal == document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML){ |
|||
req2.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); |
|||
alert('You don\'t want to report yourself, do you?'); |
|||
req2.setRequestHeader("Content-length", postdata2.length); |
|||
return; |
|||
req2.onreadystatechange = function() |
|||
} |
|||
{ |
|||
reason = prompt('Reason?:'); |
|||
if(req2.readyState == 4 && req2.status == 200) |
|||
if(!reason) |
|||
{ |
|||
var info = eval("(" + req2.responseText + ")"); |
|||
document.getElementById('bodyContent').innerHTML = 'Please wait' + '...'; |
|||
if (info.error) |
|||
document.getElementById('bodyContent').innerHTML += '<br />Grabbing page...'; |
|||
{ |
|||
jsMsg("Error when setting the group on "+user); |
|||
$.ajax({ |
|||
return false; |
|||
type: 'GET', |
|||
} |
|||
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, |
|||
jsMsg("Done making "+user+" a Admin"); |
|||
dataType: "xml", |
|||
} |
|||
}; |
|||
req2.send(postdata2); |
|||
} |
|||
}; |
|||
req.send(postdata); |
|||
error: function(){ |
|||
document.getElementById('bodyContent').innerHTML += '<br />Error reading page: ' + AIVpageName; |
|||
} |
|||
}); |
|||
} |
} |
||
function PageReady(pagetext, edittoken){ |
|||
var x; |
|||
var myArray = pagetext.split(" "); |
|||
var add = true; |
|||
document.getElementById('bodyContent').innerHTML += '<br />Searching for existing report...'; |
|||
for (x=0; x < myArray.length; x++) |
|||
{ |
|||
var myArray2 = myArray[x].split(/\n/); |
|||
var y; |
|||
for (y=0; y < myArray2.length; y++ ){ |
|||
if( mw.config.get('wgNamespaceNumber') == 2 || mw.config.get('wgNamespaceNumber') == 3 ) |
|||
if(myArray2[y] == '{{IPvandal|' + vandal + '}}' || |
|||
{ |
|||
myArray2[y] == '*{{IPvandal|' + vandal + '}}' || |
|||
addOnloadHook(function(){addPortletLink( "p-cactions", "javascript:MakeAdmin()", (typeof(MakeAdminConfig)!="undefined"&&MakeAdminConfig.portletTitle)||"+admin", "portlet-make-admin");}); |
|||
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 + ' --~' + '~' + '~' + '~'; |
|||
} |
|||
var params = { |
|||
action : 'edit', |
|||
title : AIVpageName, |
|||
section : section, |
|||
summary : 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[User: Synoman Barris|ARV 2.2]].', |
|||
minor : null, |
|||
text : pagetext, |
|||
token : edittoken |
|||
} |
|||
document.getElementById('bodyContent').innerHTML += '<br />Submitting form...'; |
|||
var xmlhttp = sajax_init_object(); |
|||
xmlhttp.overrideMimeType('application/json'); |
|||
xmlhttp.open( 'POST' , mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php', true); |
|||
xmlhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded'); |
|||
xmlhttp.send( AIVparams(params) ); |
|||
} |
|||
function AIVparams( arr ) { |
|||
var resarr = Array(); |
|||
for( var i in arr ) { |
|||
if( typeof arr[i] == 'undefined' ) { |
|||
continue; |
|||
} |
|||
var res; |
|||
if( arr[i] instanceof Array ){ |
|||
var v = Array(); |
|||
for(var j = 0; j < arr[i].length; ++j ) { |
|||
v[j] = encodeURIComponent( arr[i][j] ); |
|||
} |
|||
res = v.join('|'); |
|||
} else { |
|||
res = encodeURIComponent( arr[i] ); |
|||
} |
|||
resarr.push( encodeURIComponent( i ) + '=' + res ); |
|||
} |
|||
return resarr.join('&'); |
|||
} |
} |