Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

User:Shane/bsgbook.js/autoreport.js: Difference between revisions

Shane (talk | contribs)
core code; moving "adding" to tabs.js
Shane (talk | contribs)
updated for cross-wiki use
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* {{shortcut|BW:AVI}} <pre><nowiki> */
/* {{shortcut|BW:AVI}} <pre><nowiki> */
if (shortwikiloc == "en") {
var AIVpageName = 'Battlestar_Wiki:Administrators%27_noticeboard';
var section = '4';
}
if (shortwikiloc == "md") {
var AIVpageName = 'Battlestar_Wiki_Media:Administrators%27_noticeboard';
var section = '5';
}


var pageName;
var pageName;
var AIVpageName = 'Battlestar_Wiki:Administrators%27_noticeboard';
var section = '4';
var vandal;
var vandal;
var reason;
var reason;
Line 21: Line 29:
         return;
         return;
       document.getElementById('bodyContent').innerHTML += '<br />Grabbing page...';
       document.getElementById('bodyContent').innerHTML += '<br />Grabbing page...';
       gml_xmlhttp.open('GET', 'http://www.battlestarwiki.org/en/index.php?title=' + AIVpageName + '&action=edit' + '&section=' + section + '', true);
       gml_xmlhttp.open('GET', wikiloc + 'index.php?title=' + AIVpageName + '&action=edit' + '&section=' + section + '', true);
       gml_xmlhttp.onreadystatechange = AIVMore;
       gml_xmlhttp.onreadystatechange = AIVMore;
       gml_xmlhttp.send(null);
       gml_xmlhttp.send(null);
Line 65: Line 73:
   }
   }
   form.wpTextbox1.value += '*{{vandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
   form.wpTextbox1.value += '*{{vandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
   form.wpSummary.value = 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[BW:AVI]].';
   form.wpSummary.value = 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[:en:BW:AVI|BW:AVI]].';
   newform = document.createElement('form');
   newform = document.createElement('form');
   l = form.getElementsByTagName('textarea');
   l = form.getElementsByTagName('textarea');
Line 78: Line 86:
   for (i = l.length; i--; ) {
   for (i = l.length; i--; ) {
     if (l[i].name == 'wpSummary') {
     if (l[i].name == 'wpSummary') {
       l[i].value = 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[BW:AVI]].';
       l[i].value = 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[:en:BW:AVI|BW:AVI]].';
     } else if (l[i].name == 'wpMinoredit') {
     } else if (l[i].name == 'wpMinoredit') {
       l[i].value = '1';
       l[i].value = '1';

Latest revision as of 03:09, 1 September 2006

/* {{shortcut|BW:AVI}} <pre><nowiki> */

if (shortwikiloc == "en") {
	var AIVpageName = 'Battlestar_Wiki:Administrators%27_noticeboard';
	var section = '4';
}

if (shortwikiloc == "md") {
	var AIVpageName = 'Battlestar_Wiki_Media:Administrators%27_noticeboard';
	var section = '5';
}

var pageName;
var vandal;
var reason;

function AIVandal(vandalU){
      vandal = vandalU;
      if(vandal ==  document.getElementById('pt-userpage').getElementsByTagName('a')[0].innerHTML){
        alert('You don\'t want to report yourself, do you?');
        return;
      }
      reason = prompt('Reason:');
      if(!reason)
        return;
      document.getElementById('bodyContent').innerHTML = 'Please wait' + '...';
      gml_xmlhttp = HTTPClient();
      if (!gml_xmlhttp)
        return;
      document.getElementById('bodyContent').innerHTML += '<br />Grabbing page...';
      gml_xmlhttp.open('GET', wikiloc + 'index.php?title=' + AIVpageName + '&action=edit' + '&section=' + section + '', true);
      gml_xmlhttp.onreadystatechange = AIVMore;
      gml_xmlhttp.send(null);
}

function AIVMore() {
  if (gml_xmlhttp.readyState != 4){
    document.getElementById('bodyContent').innerHTML += '.';
    return
  }
  var form, newform, l;
  // Insert the downloaded form in our current page, using
  // only hidden form inputs.
  doc = gml_XMLParse(gml_xmlhttp.responseText);
  form = doc.getElementById('editform');

  var x;
  var t = form.wpTextbox1.value;
  myArray = t.split(" ");
  var add;
  add = true;
  document.getElementById('bodyContent').innerHTML += '<br />Searching for existing report...';
  var test = "*{{vandal|" + vandal + "}}";
  for (x in myArray)
  {
    myArray2 = myArray[x].split(/\n/);
    for (y in myArray2){
      if(myArray2[y] == '{{vandal|' + vandal + '}}'){
        add = false;
      }
      if(myArray2[y] == test){
        add = false;
      }
    }
  }
  if(add == true){
    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;
  }
  form.wpTextbox1.value += '*{{vandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
  form.wpSummary.value = 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[:en:BW:AVI|BW:AVI]].';
  newform = document.createElement('form');
  l = form.getElementsByTagName('textarea');
  for (i = l.length; i--; ) {
    var t = document.createElement('input');
    t.type = 'hidden';
    t.name = l[i].name;
    t.value = l[i].value;
    newform.appendChild(t);
  }
  l = form.getElementsByTagName('input');
  for (i = l.length; i--; ) {
    if (l[i].name == 'wpSummary') {
      l[i].value = 'Reporting [[Special:Contributions/' + vandal + '|' + vandal + ']] using [[:en:BW:AVI|BW:AVI]].';
    } else if (l[i].name == 'wpMinoredit') {
      l[i].value = '1';
    } else if (l[i].name == 'wpWatchthis') {
      if (!l[i].checked)
        continue;
      l[i].value = "on";
    } else if (l[i].name == 'wpPreview') {
      continue;
    } else if (l[i].name == 'wpDiff') {
      continue;
    }
    l[i].type = 'hidden';
    newform.appendChild(l[i]);
  }
  newform.name = form.name;
  newform.method = form.method;
  newform.id = form.id;
  newform.action = form.action;
  document.getElementById('bodyContent').innerHTML += '<br />Submitting form...';
  document.getElementById('bodyContent').appendChild(newform);
  // Submit the form
  newform.submit();
}

/* </nowiki></pre> */