Misplaced Pages

User:Andrea105/monobook.js: Difference between revisions

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< User:Andrea105 Browse history interactivelyContent deleted Content added
Revision as of 02:40, 4 November 2009 view sourceAndrea105 (talk | contribs)4,299 edits Created page with 'importScript('User:Lupin/recent2.js');'  Latest revision as of 05:46, 21 February 2021 view source Ladsgroup (talk | contribs)Extended confirmed users, IP block exemptions, Pending changes reviewers, Rollbackers20,548 editsm Maintenance: Replacing legacy global variable (phab:T72470
(31 intermediate revisions by 2 users not shown)
Line 1: Line 1:
importScript('User:Lupin/recent2.js'); importScript('User:Lupin/recent2.js');

function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca;
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}


function eraseCookie(name) {
createCookie(name,"",-1);
}

function warningtab()
{
document.getElementById('column-one').getElementsByTagName('div').getElementsByTagName('ul').appendChild(tnaddlilink("javascript:markpage()", "pt"));
if(document.URL.indexOf("User_talk") != -1 && document.URL.indexOf("edit") != -1)
{
document.getElementById('column-one').getElementsByTagName('div').getElementsByTagName('ul').appendChild(tnaddlilink("javascript:uwtest1()", "t1"));
document.getElementById('column-one').getElementsByTagName('div').getElementsByTagName('ul').appendChild(tnaddlilink("javascript:uwvand2()", "w2"));
document.getElementById('column-one').getElementsByTagName('div').getElementsByTagName('ul').appendChild(tnaddlilink("javascript:uwvand4()", "w4"));
}
if( ((document.URL.indexOf("&from=") != -1) && (document.URL.indexOf("&token=") != -1)) || (document.URL.indexOf("&autoclick=wpSave") != -1) )
{
markpage();
}
}

function uwtest1()
{
document.editform.wpTextbox1.value += ( "\n===" + "{" + "{" + "subst:" + "CURRENTMONTHNAME" + "}" + "}" + " {" + "{" + "subst:" + "CURRENTYEAR" + "}" + "}" + "===" );
document.editform.wpTextbox1.value += ( "\n" + "{" + "{" + "subst:" + "uw-test1\|" + readCookie("pageattacked") + "}" + "}" + " ~" + "~" + "~" + "~" );
document.editform.wpSummary.value = "uw-test1";
document.editform.wpSave.click();
}

function uwvand2()
{
document.editform.wpTextbox1.value += ( "\n===" + "{" + "{" + "subst:" + "CURRENTMONTHNAME" + "}" + "}" + " {" + "{" + "subst:" + "CURRENTYEAR" + "}" + "}" + "===" );
document.editform.wpTextbox1.value += ( "\n" + "{" + "{" + "subst:" + "uw-vand2\|" + readCookie("pageattacked") + "}" + "}" + " ~" + "~" + "~" + "~" );
document.editform.wpSummary.value = "uw-vand2";
document.editform.wpSave.click();
}

function uwvand4()
{
document.editform.wpTextbox1.value += ( "\n===" + "{" + "{" + "subst:" + "CURRENTMONTHNAME" + "}" + "}" + " {" + "{" + "subst:" + "CURRENTYEAR" + "}" + "}" + "===" );
document.editform.wpTextbox1.value += ( "\n" + "{" + "{" + "subst:" + "uw-vand4\|" + readCookie("pageattacked") + "}" + "}" + " ~" + "~" + "~" + "~" );
document.editform.wpSummary.value = "uw-vand4";
document.editform.wpSave.click();
}

function markpage()
{
createCookie("pageattacked", wgPageName.replace(/_/g, ' '), 2);
}

$(warningtab);

function tnaddlilink(url, name)
{
var na = document.createElement('a');
na.setAttribute('href', url);
var txt = document.createTextNode(name);
na.appendChild(txt);
var li = document.createElement('li');
li.appendChild(na);
return li;
}

//ARV 2.0
// -----------------------------------------------------------------------------
// XMLHttpRequest support
// -----------------------------------------------------------------------------
if (document.implementation.createDocument) {
var gml_xmlparser = new DOMParser();
}

function gml_XMLParse(string) {
if (document.implementation.createDocument) {
return gml_xmlparser.parseFromString(string, "text/xml");
} else if (window.ActiveXObject) {
var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM");
gml_xmldoc.async = "false";
ret = gml_xmldoc.loadXML(string);
if (!ret)
return null;
return gml_xmldoc.documentElement;
}
return null;
}

var gml_xmlhttp;

function HTTPClient() {
var gml_http;
if(window.XMLHttpRequest) {
gml_http = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
gml_http = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
gml_http = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
gml_http = false;
}
}
}
return gml_http;
}
var AIVpageName = 'Misplaced Pages:Administrator_intervention_against_vandalism';
var section = '1';
var vandal;
var reason;

function addlilinkAIV(url, name, id){
addPortletLink( 'p-cactions', url, name, id, null, null );
}

function AIV(){
if (document.title.indexOf("User talk:") != -1){
username = encodeURIComponent( wgTitle );
var test = username.split('.');
if(test) {
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('/');
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('=');
}
}
addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report', 'td-report');
}
}

function AIVandal(vandalU){
vandal = vandalU;
if(vandal == document.getElementById('pt-userpage').getElementsByTagName('a').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', 'http://en.wikipedia.org/search/?title=' + AIVpageName + '&action=edit' + '&section=' + section + '', true);
gml_xmlhttp.onreadystatechange = AIVMore;
gml_xmlhttp.send(null);
}

function AIVparams( arr ) {
var resarr = Array();
for( var i in arr ) {
if( typeof arr == 'undefined' ) {
continue;
}
var res;
if( arr instanceof Array ){
var v = Array();
for(var j = 0; j < arr.length; ++j ) {
v = encodeURIComponent( arr );
}
res = v.join('|');
} else {
res = encodeURIComponent( arr );
}
resarr.push( encodeURIComponent( i ) + '=' + res );
}
return resarr.join('&');
}

function AIVMore() {
if (gml_xmlhttp.readyState != 4){
document.getElementById('bodyContent').innerHTML += '.';
return
}

// Insert the downloaded form in our current page, using
// only hidden form inputs.
var doc = gml_XMLParse(gml_xmlhttp.responseText);
var form = doc.getElementById('editform');

var x;
var t = form.wpTextbox1.value;
var myArray = t.split(" ");
var add = true;
document.getElementById('bodyContent').innerHTML += '<br />Searching for existing report...';
var test = "*{{vandal|" + vandal + "}}";
for (x=0; x < myArray.length; x++)
{
var myArray2 = myArray.split(/\n/);
var y;
for (y=0; y < myArray2.length; y++ ){
if(myArray2 == '{{vandal|' + vandal + '}}'){
add = false;
}
if(myArray2 == test){
add = false;
}
if(myArray2 == '{{IPvandal|' + vandal + '}}'){
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;
}
//let's do something expiremntal, to see if it's an IP address
var test = username.split('.');
if(test) {
form.wpTextbox1.value += '*{{IPvandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
}
else {
form.wpTextbox1.value += '*{{vandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
}

var params = {
action : 'edit',
title : AIVpageName,
section : section,
summary : 'Reporting ] using ].',
minor : null,
text : form.wpTextbox1.value,
token : form.wpEditToken.value
}

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) );
}

$(AIV);

Latest revision as of 05:46, 21 February 2021

importScript('User:Lupin/recent2.js');

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca;
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}


function eraseCookie(name) {
	createCookie(name,"",-1);
}

function warningtab()
{
  document.getElementById('column-one').getElementsByTagName('div').getElementsByTagName('ul').appendChild(tnaddlilink("javascript:markpage()", "pt"));
  if(document.URL.indexOf("User_talk") != -1 && document.URL.indexOf("edit") != -1)
  {
     document.getElementById('column-one').getElementsByTagName('div').getElementsByTagName('ul').appendChild(tnaddlilink("javascript:uwtest1()", "t1"));
     document.getElementById('column-one').getElementsByTagName('div').getElementsByTagName('ul').appendChild(tnaddlilink("javascript:uwvand2()", "w2"));
     document.getElementById('column-one').getElementsByTagName('div').getElementsByTagName('ul').appendChild(tnaddlilink("javascript:uwvand4()", "w4"));
  }
  if( ((document.URL.indexOf("&from=") != -1) && (document.URL.indexOf("&token=") != -1)) || (document.URL.indexOf("&autoclick=wpSave") != -1) )
  {
    markpage();
  }
}

function uwtest1()
{
  document.editform.wpTextbox1.value += ( "\n===" + "{" + "{" + "subst:" + "CURRENTMONTHNAME" + "}" + "}" + " {" + "{" + "subst:" + "CURRENTYEAR" + "}" + "}" + "===" );
  document.editform.wpTextbox1.value += ( "\n" + "{" + "{" + "subst:" + "uw-test1\|" + readCookie("pageattacked") + "}" + "}" + " ~" + "~" + "~" + "~" );
  document.editform.wpSummary.value = "uw-test1";
  document.editform.wpSave.click();
}

function uwvand2()
{
  document.editform.wpTextbox1.value += ( "\n===" + "{" + "{" + "subst:" + "CURRENTMONTHNAME" + "}" + "}" + " {" + "{" + "subst:" + "CURRENTYEAR" + "}" + "}" + "===" );
  document.editform.wpTextbox1.value += ( "\n" + "{" + "{" + "subst:" + "uw-vand2\|" + readCookie("pageattacked") + "}" + "}" + " ~" + "~" + "~" + "~" );
  document.editform.wpSummary.value = "uw-vand2";
  document.editform.wpSave.click();
}

function uwvand4()
{
  document.editform.wpTextbox1.value += ( "\n===" + "{" + "{" + "subst:" + "CURRENTMONTHNAME" + "}" + "}" + " {" + "{" + "subst:" + "CURRENTYEAR" + "}" + "}" + "===" );
  document.editform.wpTextbox1.value += ( "\n" + "{" + "{" + "subst:" + "uw-vand4\|" + readCookie("pageattacked") + "}" + "}" + " ~" + "~" + "~" + "~" );
  document.editform.wpSummary.value = "uw-vand4";
  document.editform.wpSave.click();
}

function markpage()
{
  createCookie("pageattacked", wgPageName.replace(/_/g, ' '), 2);
}

$(warningtab);

function tnaddlilink(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);
 
  var txt = document.createTextNode(name);
  na.appendChild(txt);
 
  var li = document.createElement('li');
  li.appendChild(na);
  return li;
}

//ARV 2.0
// -----------------------------------------------------------------------------
// XMLHttpRequest support
// -----------------------------------------------------------------------------
if (document.implementation.createDocument) {
  var gml_xmlparser = new DOMParser();
}

function gml_XMLParse(string) {
  if (document.implementation.createDocument) {
    return gml_xmlparser.parseFromString(string, "text/xml");
  } else if (window.ActiveXObject) {
    var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM");
    gml_xmldoc.async = "false";
    ret = gml_xmldoc.loadXML(string);      
    if (!ret)
      return null;
    return gml_xmldoc.documentElement;
  }
  return null;
}

var gml_xmlhttp;

function HTTPClient() {
  var gml_http;
  if(window.XMLHttpRequest) {
    gml_http = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      gml_http = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        gml_http = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        gml_http = false;
      }
    }
  }
  return gml_http;
}
var AIVpageName = 'Misplaced Pages:Administrator_intervention_against_vandalism';
var section = '1';
var vandal;
var reason;

function addlilinkAIV(url, name, id){
    addPortletLink( 'p-cactions', url, name, id, null, null );
}

function AIV(){
  if (document.title.indexOf("User talk:") != -1){
    username = encodeURIComponent( wgTitle );
    var test = username.split('.');
    if(test) {
    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('/');
    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('=');
      }
    }
    addlilinkAIV('javascript:AIVandal("' + username + '")', 'Report', 'td-report');
  }
}

function AIVandal(vandalU){
      vandal = vandalU;
      if(vandal ==  document.getElementById('pt-userpage').getElementsByTagName('a').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', 'http://en.wikipedia.org/search/?title=' + AIVpageName + '&action=edit' + '&section=' + section + '', true);
      gml_xmlhttp.onreadystatechange = AIVMore;
      gml_xmlhttp.send(null);
}

function AIVparams( arr ) {
	var resarr = Array();
	for( var i in arr ) {
		if( typeof arr == 'undefined' ) {
			continue;
		}
		var res;
		if( arr instanceof Array ){
			var v =  Array();
			for(var j = 0; j < arr.length; ++j ) {
				v = encodeURIComponent( arr );
			}
			res = v.join('|');
		} else {
			res = encodeURIComponent( arr );
		}
		resarr.push( encodeURIComponent( i ) + '=' + res );
	}
	return resarr.join('&');
}

function AIVMore() {
  if (gml_xmlhttp.readyState != 4){
    document.getElementById('bodyContent').innerHTML += '.';
    return
  }

  // Insert the downloaded form in our current page, using
  // only hidden form inputs.
  var doc = gml_XMLParse(gml_xmlhttp.responseText);
  var form = doc.getElementById('editform');

  var x;
  var t = form.wpTextbox1.value;
  var myArray = t.split(" ");
  var add = true;
  document.getElementById('bodyContent').innerHTML += '<br />Searching for existing report...';
  var test = "*{{vandal|" + vandal + "}}";
  for (x=0; x < myArray.length; x++)
  {
    var myArray2 = myArray.split(/\n/);
    var y;
    for (y=0; y < myArray2.length; y++ ){
      if(myArray2 == '{{vandal|' + vandal + '}}'){
        add = false;
      }
      if(myArray2 == test){
        add = false;
      }
      if(myArray2 == '{{IPvandal|' + vandal + '}}'){
        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;
  }
  //let's do something expiremntal, to see if it's an IP address
    var test = username.split('.');
    if(test) {
      form.wpTextbox1.value += '*{{IPvandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
    }
    else {
    form.wpTextbox1.value += '*{{vandal|' + vandal + '}} - ' + reason + ' --~' + '~' + '~' + '~';
    }

  var params = {
    action : 'edit',
    title : AIVpageName,
    section : section,
    summary : 'Reporting ] using ].',
    minor : null,
    text : form.wpTextbox1.value,
    token : form.wpEditToken.value
  }

  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) );
}

$(AIV);
User:Andrea105/monobook.js: Difference between revisions Add topic