User:Nakor/LiveRC.js

/*

LiveWP

 * Documentation : fr:User:EDUCA33E/LiveRC/Documentation
 * Author : fr:User:EDUCA33E
 * Dev & enhancements : fr:User:TiChou, pl:User:Leafnode, it:User:Jalo & fr:User:Nakor, fr:User:Arkanosis & fr:User:Argos42
 * Version: 0.4.0 (beta)

LiveDiff
";   }    else {      LP.innerHTML = " ";    }  }  if (dLP.style.display == "none") {    var elcb = document.getElementById( 'shidPrev' );    elcb.checked="true";    dLP.style.display = "inline";  }  if (typeof (setupTooltips) != 'undefined') {    setupTooltips(dLP, false, true);  }

var entete = document.getElementById( 'livePreviewTitle' ); entete.innerHTML='' + page + ' • ' + '(Hist)';

var asNextDiff = getElementWithId('differences-nextlink', 'a', doc); if ((asNextDiff == null) && lrcPatrol) { var optAvert = ""; var optl = lstAvert.length; for (j=0; j'+lstAvert[j].string+' '; }

// Get username of submitter var user1 = getElementWithId('mw-diff-otitle2', 'div', doc); if (user1 != null) { var usertmp=user1.innerHTML; if (!usertmp) usertmp=user1.firstChild.xml; // user1 = usertmp.replace(new RegExp(/(.*)<\/a> \((.*)<\/a>(.*)\((.*)\)/g), "$2");      user1 = user1.replace(new RegExp(/(.*)<(.*)>/g), "$1");    }    var user2 = getElementWithId('mw-diff-ntitle2', 'div', doc);    if (user2 != null) {      var usertmp=user2.innerHTML;      if (!usertmp) usertmp=user2.firstChild.xml;      // user2 = usertmp.replace(new RegExp(/(.*)<\/a>  \((.*)<\/a>(.*)\([" + lang_messages.SAME_EDITOR + "] ";    }

entete.innerHTML = ' '; document.getElementById('LiveRevertMessage').focus; } }

function getLiveAverto(user) { var link = document.getElementById('LiveAvertoLink'); link.href = "javascript:;"; link.style.color = "silver"; link.style.cursor = "default"; link.style.textDecoration = "none"; document.getElementById('averto').disabled = true; var message = document.getElementById('averto').value; wpajax.http({ url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=User_Talk:' + encodeURIComponent(user) + '&action=edit',               onSuccess: postLiveAverto,                user: user, message: message }); }

function postLiveAverto(xmlreq, data) { var parser = new DOMParser; var doc = parser.parseFromString(xmlreq.responseText, 'application/xhtml+xml');

var user = data.user; var message = data.message.replace(new RegExp(/\\'/g),"'"); var wpTextbox1 = encodeURIComponent(doc.getElementById('wpTextbox1').value + '\n\n ~\n');

var inputs = doc.getElementById('editform').getElementsByTagName('input'); var editform = new Array; for (i=0; i<inputs.length; i++) { editform[inputs[i].name] = inputs[i].value; } var wpStarttime = encodeURIComponent(editform['wpStarttime']); var wpEdittime = encodeURIComponent(editform['wpEdittime']); var wpEditToken = encodeURIComponent(editform['wpEditToken']);

var wpSummary = encodeURIComponent('LiveRC : ' + lang_messages.WARNING + ' ' + message.replace(new RegExp(/\|(.*)/), ' ' + lang_messages.ON_ARTICLE + ' $1') + ' !');

var headers = new Array; headers['Content-Type'] = 'application/x-www-form-urlencoded'; wpajax.http({ url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=User_Talk:' + encodeURI(user) + '&action=submit',               method: "POST", headers: headers,                data: 'wpSave=1&wpTextbox1=' + wpTextbox1 + '&wpStarttime=' + wpStarttime + '&wpEdittime=' + wpEdittime                    + '&wpEditToken=' + wpEditToken + '&wpSummary=' + wpSummary}); }

function getLiveMessage(where, user1, user2, page, oldid) { var links = [ document.getElementById('LiveRevertLink') ]; var i,len=links.length; for (i=0; i<len; i++) { links[i].href = "javascript:;"; links[i].style.color = "silver"; links[i].style.cursor = "default"; links[i].style.textDecoration = "none"; } document.getElementById('LiveRevertMessage').disabled = true; var message = document.getElementById('LiveRevertMessage').value; wpajax.http({ url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + encodeURI(page) + '&action=edit&oldid=' + oldid,               onSuccess: postLiveRevert,                where: where, page: page, user1: user1, user2: user2, message: message }); }

function postLiveRevert(xmlreq, data) { var parser = new DOMParser; var doc = parser.parseFromString(xmlreq.responseText, 'application/xhtml+xml');

var where = data.where; var page = data.page; var user1 = data.user1; var user2 = data.user2; var message = data.message;

var wpTextbox1 = encodeURIComponent(doc.getElementById('wpTextbox1').value);

var inputs = doc.getElementById('editform').getElementsByTagName('input'); var editform = new Array; for (i=0; i<inputs.length; i++) { editform[inputs[i].name] = inputs[i].value; } var wpStarttime = encodeURIComponent(editform['wpStarttime']); var wpEdittime = encodeURIComponent(editform['wpEdittime']); var wpEditToken = encodeURIComponent(editform['wpEditToken']);

switch(where) { case 'liverevert': var wpSummary = lang_menu[0].RVMES1 + ' ' + user2       + '; '+lang_menu[0].RVMES2+' ' + user1 + ''; break; /*   case 'livevandalism': var wpSummary = 'LiveRC : Révocation de vandalisme par ' + user2       + '; retour a la version de ' + user1 + ''; break; */ } if (message) wpSummary = wpSummary + ' ; ' + message; wpSummary = encodeURIComponent(wpSummary);

var headers = new Array; headers['Content-Type'] = 'application/x-www-form-urlencoded'; wpajax.http({ url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + encodeURIComponent(page) + '&action=submit',               method: "POST", headers: headers,                data: 'wpSave=1&wpTextbox1=' + wpTextbox1 + '&wpStarttime=' + wpStarttime + '&wpEdittime=' + wpEdittime                    + '&wpEditToken=' + wpEditToken + '&wpSummary=' + wpSummary}); }

/*

LiveArticle
'; }

function blankPage( page,message){ wpajax.http({ url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + page + '&action=edit',               onSuccess: postBlankPage, page: page, message: message}); } function postBlankPage(xmlreq, data){ var page=data.page; var message=data.message var parser = new DOMParser; var doc = parser.parseFromString(xmlreq.responseText, 'application/xhtml+xml');

var inputs = doc.getElementById('editform').getElementsByTagName('input'); var editform = new Array; for (i=0; i<inputs.length; i++) { editform[inputs[i].name] = inputs[i].value; } var wpStarttime = encodeURIComponent(editform['wpStarttime']); var wpEdittime = encodeURIComponent(editform['wpEdittime']); var wpEditToken = encodeURIComponent(editform['wpEditToken']);

var headers = new Array; headers['Content-Type'] = 'application/x-www-form-urlencoded'; wpajax.http({ url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + page + '&action=submit',               method: "POST", headers: headers,                data: 'wpSave=1&wpTextbox1=&wpStarttime=' + wpStarttime + '&wpEdittime=' + wpEdittime                    + '&wpEditToken=' + wpEditToken + '&wpSummary=suppression immédiate:%20'+message});

}

/*

LiveContrib
'; }

/*

LiveFilter


function liveFilter(id) { var el = document.getElementById( 'livePreviewTitle' ); el.innerHTML="Filter: ..."; wpajax.http({ url: mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=Special:AbuseLog&details='+id,                onSuccess: getFilter, mid: id}); }

function getFilter(xmlreq, data) { doc = gml_XMLParse(xmlreq.responseText); bC = getElementWithId('bodyContent', 'div', doc); if (bC == null) bC  = getElementWithId('article', 'div', doc); var LP = document.getElementById( 'livePreview' ); var dLP = document.getElementById( 'divLivePreview' ); LP.innerHTML = bC.innerHTML; if (LP.innerHTML == "undefined") LP.innerHTML = bC.xml; if (dLP.style.display == "none") { var elcb = document.getElementById( 'shidPrev' ); elcb.checked="true"; dLP.style.display = "inline"; } var elt = document.getElementById( 'livePreviewTitle' ); elt.innerHTML='Détails'; }

/*

LiveRC
*/