Utilisateur:TiChou/t-Revert.js
Note : après avoir enregistré la page, vous devrez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
Mozilla / Firefox / Konqueror / Safari : maintenez la touche Majuscule (Shift) en cliquant sur le bouton Actualiser (Reload) ou pressez Maj-Ctrl-R (Cmd-R sur Apple Mac) ;
Firefox (sur GNU/Linux) / Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5./*
* t-Revert
*
* Outil de révocation et d'avertissement sur les pages de diff
*
* Auteur : [[:fr:User:TiChou]]
* Date création : 24 mars 2007
* Date révision : 23 août 2007
* Compatibilité : Firefox 2.x, Opera 9.x
*/
if (mw.config.get('wgAction') == 'view' && /^\?.*\bdiff=\b/.test(location.search)) {
if (typeof(wpfunctions) == "undefined")
mw.loader.load('https://fr.wikipedia.org/w/index.php?title=Utilisateur:TiChou/wpfunctions.js&action=raw&ctype=text/javascript');
function doRevert() {
var chkRevert = document.getElementById('rv-undo');
var chkAvert = document.getElementById('rv-avert');
if (!chkRevert.checked && !chkAvert.checked) return;
var raison = document.getElementById('rv-raison');
var message = document.getElementById('rv-message');
var bouton = document.getElementById('rv-go');
var contentSub = document.getElementById('contentSub');
chkRevert.disabled = true;
chkAvert.disabled = true;
raison.disabled = true;
message.disabled = true;
bouton.disabled = true;
var bodyContent = document.getElementById('bodyContent');
var otitle = bodyContent.getElementsByClassName('diff-otitle')[0];
var ntitle = bodyContent.getElementsByClassName('diff-ntitle')[0];
var undo = ntitle.getElementsByTagName('a')[2].href;
var regex = new RegExp(/\bundoafter=(\d+)&undo=(\d+)/);
var match = regex.exec(undo);
if (!match) return;
var revid1 = match[1];
var revid2 = match[2];
if (revid2 == 0) revid2 = mw.config.get('wgCurRevisionId');
var user1 = otitle.getElementsByTagName('br')[0].nextSibling.text;
var user2 = ntitle.getElementsByTagName('br')[0].nextSibling.text;
user1 = decodeEntities(user1);
user2 = decodeEntities(user2);
var div,span,text;
div = document.createElement('div');
div.id = 'rv-statut1';
div.style.display = 'none';
text = document.createTextNode('Annulation des modifications : ');
div.appendChild(text);
span = document.createElement('span');
div.appendChild(span);
contentSub.appendChild(div);
div = document.createElement('div');
div.id = 'rv-statut2';
div.style.display = 'none';
text = document.createTextNode('Avertissement de l\'utilisateur ' + user2 + ' : ');
div.appendChild(text);
span = document.createElement('span');
div.appendChild(span);
contentSub.appendChild(div);
var statut;
if (chkRevert.checked) {
statut = document.getElementById('rv-statut1').childNodes[1];
wpEditPage(mw.config.get('wgPageName'), { undoafter: revid1, undo: revid2 }, startRevert, endRevert, { user1: user1, user2: user2, statut: statut });
} else {
statut = document.getElementById('rv-statut2').childNodes[1];
wpEditPage('User Talk:' + user2, {}, startAvert, endAvert, { user2: user2, statut: statut });
}
statut.parentNode.style.display = 'block';
statut.style.color = 'orange';
text = document.createTextNode('en cours');
statut.appendChild(text);
}
function startRevert(wpTextbox1, wpSummary, doc, data) {
data.statut.style.textDecoration = 'blink';
if (!doc.getElementById('wikiDiff')) return { error: stopRevert, data: data };
wpSummary = 'Révocation des modifications de [[Special:Contributions/' + data.user2 + '|' + data.user2 + ']] ;'
+ ' retour à la version de [[';
if (/^\d+\.\d+\.\d+\.\d+$/.test(data.user1))
wpSummary += 'Special:Contributions/';
else
wpSummary += 'User:';
wpSummary += data.user1 + '|' + data.user1 + ']]';
var raison = document.getElementById('rv-raison').value;
if (raison) wpSummary += ' ; ' + raison;
return { wpTextbox1: wpTextbox1, wpSummary: wpSummary, data: data };
}
function stopRevert(data) {
data.statut.style.color = 'red';
data.statut.style.textDecoration = 'none';
data.statut.firstChild.textContent = 'impossible de défaire ; conflit avec les modifications intermédiaires';
}
function endRevert(doc, data) {
data.statut.style.color = 'green';
data.statut.style.textDecoration = 'none';
data.statut.firstChild.textContent = 'faite !';
if (document.getElementById('rv-avert').checked) {
data.statut = document.getElementById('rv-statut2').childNodes[1];
data.statut.parentNode.style.display = 'block';
data.statut.style.color = 'orange';
text = document.createTextNode('en cours');
data.statut.appendChild(text);
wpEditPage('User Talk:' + data.user2, {}, startAvert, endAvert, data);
} else {
window.location.replace(mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + wpURLEncode(mw.config.get('wgPageName')) + '&diff=cur&oldid=' + mw.config.get('wgCurRevisionId'));
}
}
function startAvert(wpTextbox1, wpSummary, doc, data) {
data.statut.style.textDecoration = 'blink';
var message = document.getElementById('rv-message').value;
wpSummary = 'Avertissement ! ' + lstAvert[message].string + ' !';
wpTextbox1 = '{{subst:' + lstAvert[message].template + (lstAvert[message].hasPage ? '|' + mw.config.get('wgPageName').replace(/_/g, ' ') : '') + '}}\u007E\u007E\u007E\u007E\n' + wpTextbox1;
return { wpTextbox1: wpTextbox1, wpSummary: wpSummary, data: data };
}
function endAvert(doc, data) {
data.statut.style.color = 'green';
data.statut.style.textDecoration = 'none';
data.statut.firstChild.textContent = 'fait !';
if (document.getElementById('rv-undo').checked)
window.location.replace(mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/index.php?title=' + wpURLEncode(mw.config.get('wgPageName')) + '&diff=cur&oldid=' + mw.config.get('wgCurRevisionId'));
}
function tRevert() {
var Content = document.getElementById('content');
if (Content.getElementsByClassName('firstrevisionheader').length) return;
var contentSub = document.getElementById('contentSub');
//contentSub.removeChild(contentSub.firstChild);
var text,input,label,select,option,button,br,div;
br = document.createElement('br');
contentSub.appendChild(br);
contentSub.style.fontSize = '100%';
input = document.createElement('input');
input.id = 'rv-undo';
input.name = 'rv-undo';
input.type = 'checkbox';
input.checked = true;
input.style.verticalAlign = 'middle';
contentSub.appendChild(input);
label = document.createElement('label');
label.setAttribute('for', 'rv-undo');
text = document.createTextNode('défaire');
label.appendChild(text);
contentSub.appendChild(label);
text = document.createTextNode('\u00a0•\u00a0');
contentSub.appendChild(text);
label = document.createElement('label');
label.setAttribute('for', 'rv-raison');
text = document.createTextNode('raison : ');
label.appendChild(text);
contentSub.appendChild(label);
input = document.createElement('input');
input.id = 'rv-raison';
input.name = 'rv-raison';
input.style.verticalAlign = 'middle';
contentSub.appendChild(input);
text = document.createTextNode('\u00a0\u00a0••\u00a0\u00a0');
contentSub.appendChild(text);
input = document.createElement('input');
input.id = 'rv-avert';
input.name = 'rv-avert';
input.type = 'checkbox';
input.checked = false;
input.style.verticalAlign = 'middle';
contentSub.appendChild(input);
label = document.createElement('label');
label.setAttribute('for', 'rv-avert');
text = document.createTextNode('avertir');
label.appendChild(text);
contentSub.appendChild(label);
text = document.createTextNode('\u00a0•\u00a0');
contentSub.appendChild(text);
label = document.createElement('label');
label.setAttribute('for', 'rv-message');
text = document.createTextNode('message : ');
label.appendChild(text);
contentSub.appendChild(label);
select = document.createElement('select');
select.id = 'rv-message';
select.name = 'rv-message';
select.style.verticalAlign = 'middle';
for (var i = 0, len = lstAvert.length; i < len; i++) {
option = document.createElement('option');
option.value = i;
option.text = lstAvert[i].string;
select.appendChild(option);
}
contentSub.appendChild(select);
text = document.createTextNode('\u00a0\u00a0••\u00a0\u00a0');
contentSub.appendChild(text);
button = document.createElement('button');
button.id = 'rv-go';
button.onclick = doRevert;
text = document.createTextNode('Go');
button.appendChild(text);
contentSub.appendChild(button);
}
if (typeof(lstAvert) == "undefined") {
var lstAvert = [
{ template: "Test 0" , string: "Test 0" , hasPage: false },
{ template: "Test 1" , string: "Test 1" , hasPage: false },
{ template: "Test 2" , string: "Test 2" , hasPage: false },
{ template: "Test 3" , string: "Test 3" , hasPage: false },
{ template: "Vandalisme" , string: "Vandal" , hasPage: true },
{ template: "Spammeur" , string: "Spam" , hasPage: true },
{ template: "Motivation_modif" , string: "Résumé" , hasPage: true },
{ template: "Signature" , string: "Signature" , hasPage: false },
{ template: "Bienvenue_copyright" , string: "Copyright" , hasPage: false }
];
}
addOnloadHook(tRevert);
}