Utilisateur:Dr Brains/RevocationDeluxe.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) ;
Chrome / Internet Explorer / Opera : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl-F5./* ******************************************************************************
1. Permet à un utilisateur non-sysop d'effectuer une révocation depuis l'historique
2. Permet aux administrateur de personnaliser le résumé de modification lors d'une révocation
{{Projet:JavaScript/Script}}
******************************************************************************* */
//<source lang=javascript><pre><nowiki>
////////////////////////////////////////// VARIABLES //////////////////////////////
var RevocationDeluxe_StandardSummary = "Révocation des modifications de [[Special:Contributions/$2|$2]] (retour à la dernière version de [[User:$1|$1]]) : ";
var RevocationDeluxe_StandardURL = mw.config.get('wgServer') + mw.config.get('wgScript') + '?title=' + mw.config.get('wgPageName').replace(/&/, "%26") + '&oldid=$3&action=edit';
var RevocationDeluxe_StandardText = "révoquer";
var RevocationDeluxe_StandardAsk = "Commentaire de révocation ?";
////////////////////////////////////////// LANCEMENT //////////////////////////////
if(mw.config.get('wgUserGroups').indexOf("sysop")!=-1){
addOnloadHook(RevocationDeluxe_SysopAddRollbackSummary);
}else{
if(mw.config.get('wgAction')=="history") addOnloadHook(RevocationDeluxe_CreateRollbackLink);
if((mw.config.get('wgAction')=="edit")&&(document.URL.indexOf('&AutoUndo=1')!=-1)) addOnloadHook(RevocationDeluxe_AutoUndo);
}
////////////////////////////////////////// AJOUT LIENS "RÉVOQUER" (non-sysop) //////////////////////////////
function RevocationDeluxe_CreateRollbackLink(){
var HistoryPanel = document.getElementById('mw-history-compare');
var Lis = HistoryPanel.getElementsByTagName('li');
var PremiereLigne = Lis[0];
var DernierUser = RevocationDeluxe_GetUserName(PremiereLigne);
var DernierOldid = RevocationDeluxe_GetOldid(PremiereLigne);
var PremierUser = false;
var PremierOldid = false;
for(var b=0;b<Lis.length;b++){
if((RevocationDeluxe_GetUserName(Lis[b])!=DernierUser)&&(!PremierOldid)){
PremierOldid = RevocationDeluxe_GetOldid(Lis[b]);
PremierUser = RevocationDeluxe_GetUserName(Lis[b]);
}
}
RevocationDeluxe_StandardSummary = RevocationDeluxe_StandardSummary.split('$1').join(PremierUser).split('$2').join(DernierUser);
RevocationDeluxe_StandardURL = RevocationDeluxe_StandardURL.split('$3').join(PremierOldid);
var RollBackLink = document.createElement('a');
RollBackLink.innerHTML = RevocationDeluxe_StandardText;
RollBackLink.href = "javascript:RevocationDeluxe_AskSummary();";
var FirstUndoSpan = RevocationDeluxe_GetUndoSpan(PremiereLigne);
$(RollBackLink).insertAfter(FirstUndoSpan);
$(document.createTextNode(' | ')).insertAfter(FirstUndoSpan);
}
////////////////////////////////////////// RÉCUPÉRATION DU NOM D'UTILISATEUR (non-sysop) //////////////////////////////
function RevocationDeluxe_GetUserName(Li){
return $(Li).find('a.mw-userlink').text() || false;
}
////////////////////////////////////////// RÉCUPÉRATION DE L'OLDID DE RÉVOCATION (non-sysop) //////////////////////////////
function RevocationDeluxe_GetOldid(Li){
var Oldid = false;
var Links = Li.getElementsByTagName('a');
for(var a=0;a<Links.length;a++){
if((Links[a].title == mw.config.get('wgPageName').replace(/_/g," "))&&(Links[a].href.indexOf('&diff')!=-1))
Oldid = decodeURIComponent(Links[a].href).split('&diff=')[1].split('&')[0];
}
return Oldid;
}
////////////////////////////////////////// RÉCUPÉRATION DU LIEN "RÉVOQUER" (non-sysop) //////////////////////////////
function RevocationDeluxe_GetUndoSpan(Li){
return $(Li).find('span.mw-history-undo')[0] || false;
}
////////////////////////////////////////// RÉCUPÉRATION DU SOMMAIRE DE MODIFICATION (non-sysop) //////////////////////////////
function RevocationDeluxe_AskSummary(){
var CustomSummary = prompt(RevocationDeluxe_StandardAsk, "");
if(!CustomSummary) return;
RevocationDeluxe_StandardSummary += CustomSummary;
document.location = RevocationDeluxe_StandardURL + '&AutoUndo=1&Summary='+encodeURIComponent(RevocationDeluxe_StandardSummary);
}
////////////////////////////////////////// RÉVOCATION AUTOMATIQUE (non-sysop) //////////////////////////////
function RevocationDeluxe_AutoUndo(){
document.editform.style.display = "none";
var Summary = document.URL.split('&Summary=')[1];
document.editform.wpSummary.value = decodeURIComponent(Summary);
document.editform.submit();
}
////////////////////////////////////////// MODIFICATION LIENS "RÉVOQUER" (sysop) //////////////////////////////
function RevocationDeluxe_SysopAddRollbackSummary(){
var Content = document.getElementById("bodyContent");
if(!Content) Content = document.getElementById("mw_contentholder");
if(!Content) Content = document.getElementById("article");
if(!Content) return;
$(Content).find('span.mw-rollback-link a').each(function () {
var Link = this.getAttribute("href");
this.setAttribute("href", "javascript:RevocationDeluxe_SysopAskSummary('" + encodeURIComponent(Link) + "');");
});
}
////////////////////////////////////////// RÉCUPÉRATION DU SOMMAIRE DE MODIFICATION (sysop) //////////////////////////////
function RevocationDeluxe_SysopAskSummary(hrefLink){
var CustomSummary = prompt(RevocationDeluxe_StandardAsk, "");
if (CustomSummary!=null && CustomSummary!=""){
window.open(hrefLink + "&summary=" + encodeURIComponent(RevocationDeluxe_StandardSummary) + encodeURIComponent(CustomSummary) );
}
}
//</nowiki></pre></source>