_ _    _ _____  ___   __                       
 __      _(_) | _(_)___ / ( _ ) / /_   ___ ___  _ __ ___  
 \ \ /\ / / | |/ / | |_ \ / _ \| '_ \ / __/ _ \| '_ ` _ \ 
  \ V  V /| |   <| |___) | (_) | (_) | (_| (_) | | | | | |
   \_/\_/ |_|_|\_\_|____/ \___/ \___(_)___\___/|_| |_| |_|

MediaWiki:Gadget-DeleteBot.js

Dans cet article, nous allons plonger dans le monde fascinant de MediaWiki:Gadget-DeleteBot.js. De son impact sur la société à ses applications dans la vie quotidienne, MediaWiki:Gadget-DeleteBot.js représente un sujet d'intérêt universel qui a retenu l'attention de personnes de tous âges et de tous horizons. Dans cette optique, nous explorerons ses origines, son évolution et sa pertinence dans le monde d'aujourd'hui, ainsi que les opinions et perspectives d'experts dans le domaine. Préparez-vous à vous plonger dans une analyse approfondie et diversifiée de MediaWiki:Gadget-DeleteBot.js, qui vous laissera sans aucun doute une nouvelle compréhension et une nouvelle inspiration sur ce sujet passionnant.
/*

Outil automatique pour supprimer plusieurs pages appartenant à la catégorie courante.

Nécessite les outils de sysop (delete).

* Documentation : ]


* Auteur : ]
* Licence : Domaine public

* {{Catégorisation JS|DeleteBot}}
*/


var DeleteBot_Text_DeleteAll = "Tout supprimer";
var DeleteBot_Text_ConfirmDeleteThisPage = "Supprimer « $1 » ?";
var DeleteBot_Text_Summary = "";
var DeleteBot_Text_OKInput = "Valider";
var DeleteBot_Text_CancelInput = "Annuler";
var DeleteBot_Text_Legend = "Supprimer les pages de la catégorie « $1 »";
var DeleteBot_Text_ListLegend = "Liste des pages";
var DeleteBot_Text_SummaryLegend = "Résumé de suppression";
var DeleteBot_Text_ButtonsLegend = "Supprimer";
var DeleteBot_Text_OtherReason = "Autre motif";

var DeleteBot_Param_NoConfirm = false;

// --------------------------------------------------------------------------------------------
// Fonction de requête
 
var DeleteBot_ajax = {
  http:function(bundle){ var xmlhttp; try{ xmlhttp = new XMLHttpRequest(); }catch(e){ try{ xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try{ xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ xmlhttp = false; }}}; if(xmlhttp){ xmlhttp.onreadystatechange = function(){ if (xmlhttp.readyState == 4){ DeleteBot_ajax.httpComplete(xmlhttp,bundle);}}; xmlhttp.open(bundle.method ? bundle.method : "GET",bundle.url,bundle.async == false ? false : true); if (bundle.headers) { for (var field in bundle.headers){ try{ xmlhttp.setRequestHeader(field,bundle.headers); }catch(err){}}}; xmlhttp.send(bundle.data ? bundle.data : null); }; return xmlhttp;}, 
  httpComplete: function(xmlhttp,bundle){ if(xmlhttp.status == 200 || xmlhttp.status == 302){ if(bundle.onSuccess) bundle.onSuccess(xmlhttp,bundle); }else if(bundle.onFailure){ bundle.onFailure(xmlhttp,bundle); }else{ }}
};
 
// --------------------------------------------------------------------------------------------
// Ajout du lien "Tout supprimer"
 
function DeleteBot_AddLink(){
     if(typeof(DeleteBot_LangCustom)=="function") DeleteBot_LangCustom();
     if(typeof(DeleteBot_SiteCustom)=="function") DeleteBot_SiteCustom();
     if(typeof(DeleteBot_UserCustom)=="function") DeleteBot_UserCustom();
     var OngletsCactions = document.getElementById('p-cactions');
     if(OngletsCactions){
          var CactionsUl = OngletsCactions.getElementsByTagName('ul');
          CactionsUl.innerHTML += '<li><a href="javascript:window.DeleteBot_ListPages();">'+DeleteBot_Text_DeleteAll+'</a></li>';
          $(OngletsCactions).removeClass("emptyPortlet");
     }
}
 
// --------------------------------------------------------------------------------------------
// Lancement
 
if(mw.config.get('wgNamespaceNumber')==14){
     $(DeleteBot_AddLink);
}

// --------------------------------------------------------------------------------------------
// Listage des pages de la catégorie

window.DeleteBot_ListPages = function(CatArray, category, categorycontinue){
     if(!CatArray) CatArray = new Array();
     if(!category) category = mw.config.get('wgPageName');    
     if(!categorycontinue) categorycontinue = '';
     var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml&action=query&rawcontinue=&list=categorymembers'
             + '&cmlimit=4999'
             + '&cmtitle=' + encodeURIComponent(category) 
             + categorycontinue;
 
     DeleteBot_ajax.http({ 
          url: URL,
          cat: category,
          catlist: CatArray,
          onSuccess:DeleteBot_ListPagesDone
     });
}

function DeleteBot_ListPagesDone(Req, data){    
     var CatArray = data.catlist;
     var category = data.cat;
     var ElementTraitement = Req.responseXML; 
     var Pages = ElementTraitement.getElementsByTagName('cm');
     for(a=0;a<Pages.length;a++){
          var TitrePage = Pages.getAttribute('title');
          if(CatArray.indexOf(TitrePage)==-1) CatArray.push(TitrePage);
     }
     var CatContinue = ElementTraitement.getElementsByTagName('query-continue');
     if(CatContinue){
          var AutreRequeteContinue = '&cmcontinue=' + encodeURIComponent(CatContinue.firstChild.getAttribute("cmcontinue"));
          DeleteBot_ListPages(CatArray, category, AutreRequeteContinue);
     }else{
          DeleteBot_CreateMenu(CatArray);
     }
}

// --------------------------------------------------------------------------------------------
// Création du formulaire de suppression

function DeleteBot_CreateMenu(CatArray){
     while(document.body.firstChild){ document.body.removeChild(document.body.firstChild); }
     var div = document.createElement('fieldset');
     div.setAttribute('style', "margin:2em;");
     document.body.appendChild(div);
     var Legend = document.createElement('legend');
     Legend.appendChild(document.createTextNode(DeleteBot_Text_Legend.split("$1").join(mw.config.get('wgTitle'))));
     div.appendChild(Legend);
     var ListFieldset = document.createElement('fieldset');
     div.appendChild(ListFieldset);
     var ListLegend = document.createElement('legend');
     ListLegend.appendChild(document.createTextNode(DeleteBot_Text_ListLegend));
     ListFieldset.appendChild(ListLegend);
     var Form = document.createElement('form');
     Form.id = "DeleteBot_Form";
     ListFieldset.appendChild(Form);
     var UL = document.createElement('ul');
     Form.appendChild(UL);
     UL.setAttribute('style', "-moz-column-count:3;-webkit-column-count:3;column-count:3;");
     for(var a=0,l=CatArray.length;a<l;a++){
          var Page = CatArray;
          var LI = document.createElement('li');
          var Input = document.createElement('input');
          Input.id = "DeleteBot_Input"+a;
          Input.type = "checkbox";
          Input.value = Page;
          Input.checked = "checked"; 
          Input.onclick = DeleteBot_UpdateOKInput;
          var Link = document.createElement('a');
          Link.title = Page;  
          Link.appendChild(document.createTextNode(Page));  
          Link.href = mw.config.get('wgServer') + mw.config.get('wgArticlePath').split("$1").join(Page);
          var Label = document.createElement('label');
          Label.setAttribute('for', "DeleteBot_Input"+a);
          Label.appendChild(Link);          
          LI.appendChild(Input);
          LI.appendChild(document.createTextNode(" "));
          LI.appendChild(Label);
          UL.appendChild(LI);
     }
     var SummaryFieldset = document.createElement('fieldset');
     div.appendChild(SummaryFieldset);
     var SummaryLegend = document.createElement('legend');
     SummaryLegend.appendChild(document.createTextNode(DeleteBot_Text_SummaryLegend));
     SummaryFieldset.appendChild(SummaryLegend);
     var SummarySelect = document.createElement('select');
     SummarySelect.id = "DeleteBot_SummarySelect";
     SummaryFieldset.appendChild(SummarySelect);
     var FirstOption = document.createElement('option');
     FirstOption.value = "";
     FirstOption.appendChild(document.createTextNode(DeleteBot_Text_OtherReason));
     SummarySelect.appendChild(FirstOption); 
     var Textarea = document.createElement('textarea');
     Textarea.id = "DeleteBot_Summary";
     Textarea.value = ""
     Textarea.onchange = DeleteBot_UpdateOKInput;
     SummaryFieldset.appendChild(Textarea);
     var ButtonsFieldset = document.createElement('fieldset');
     div.appendChild(ButtonsFieldset);
     var ButtonsLegend = document.createElement('legend');
     ButtonsLegend.appendChild(document.createTextNode(DeleteBot_Text_ButtonsLegend));
     ButtonsFieldset.appendChild(ButtonsLegend);
     var PButtons = document.createElement('p');
     PButtons.setAttribute('style', "text-align:center;");
     var OKInput = document.createElement('input');
     OKInput.type = "button";
     OKInput.id = "DeleteBot_OKInput";
     OKInput.value = DeleteBot_Text_OKInput;
     OKInput.disabled = "disabled";
     OKInput.onclick = DeleteBot_CheckMenu;
     OKInput.onselect = DeleteBot_CheckMenu;      
     PButtons.appendChild(OKInput);
     var CancelInput = document.createElement('input');
     CancelInput.type = "button";
     CancelInput.value = DeleteBot_Text_CancelInput;
     CancelInput.onclick = function(){ document.location = document.URL; };
     CancelInput.onselect = function(){ document.location = document.URL; };       
     PButtons.appendChild(CancelInput);
     ButtonsFieldset.appendChild(PButtons);
     DeleteBot_UpdateSummarySelect();
}

function DeleteBot_UpdateSummarySelect(){
     var SummarySelect = document.getElementById("DeleteBot_SummarySelect");
     if(!SummarySelect) return;
     var URL = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?format=xml&action=query&meta=allmessages'
             + '&ammessages=deletereason-dropdown';
     DeleteBot_ajax.http({ url: URL,
                  onSuccess: DeleteBot_UpdateSummarySelectProcess
               });
}

function DeleteBot_UpdateSummarySelectProcess(Req, data){
     var api = Req.responseXML;
     if (api.firstChild.nodeName == "error") return;
     var DropDown = "";
     var messages = api.getElementsByTagName('message');
     for(var a=0,l=messages.length;a<l;a++){
          var MessageName = messages.getAttribute('name');
          var MessageValue = (messages.firstChild ? messages.firstChild.nodeValue : "");
          if(MessageName == "deletereason-dropdown") DropDown = MessageValue;
     }
     if(!DropDown) return;
     var SummarySelect = document.getElementById("DeleteBot_SummarySelect");
     if(!SummarySelect) return;
     var Drop = DropDown.split("**");
     var OptGroup = false;
     for(var a=0,l=Drop.length;a<l;a++){
          var ThisReason = Drop;
          if(ThisReason.indexOf("*")!=-1){
               if(ThisReason.split('*')){
                    var Option = document.createElement('option');
                    Option.value = ThisReason.split('*');
                    Option.appendChild(document.createTextNode(ThisReason.split('*')));
                    if(OptGroup) OptGroup.appendChild(Option);
                    else SummarySelect.appendChild(Option);
                    Option.onclick = function(){ DeleteBot_UpdateSummary(this); };
               }
               if(OptGroup) SummarySelect.appendChild(OptGroup); 
               OptGroup = document.createElement('optgroup');
               OptGroup.setAttribute('label', ThisReason.split('*'));
          }else{
               var Option = document.createElement('option');
               Option.value = ThisReason;
               Option.appendChild(document.createTextNode(ThisReason));
               OptGroup.appendChild(Option);
               Option.onclick = function(){ DeleteBot_UpdateSummary(this); };
          }
     }
     if(OptGroup) SummarySelect.appendChild(OptGroup);  
}

function DeleteBot_UpdateSummary(option){
     var Summary = document.getElementById("DeleteBot_Summary");
     if(!Summary || !option) return;
     if(option.value) Summary.value = option.value;
     DeleteBot_UpdateOKInput();
}

function DeleteBot_UpdateOKInput(){
     var Form = document.getElementById("DeleteBot_Form");
     var Summary = document.getElementById("DeleteBot_Summary");
     var OKInput = document.getElementById("DeleteBot_OKInput");
     if(!Form|| !Summary || !OKInput) return;
     var InputChecked = false;
     var CatArray = new Array();
     var Inputs = Form.getElementsByTagName('input');
     for(var a=0,l=Inputs.length;a<l;a++){
          if(InputChecked) continue;
          var Input = Inputs;
          if(Input.checked) InputChecked = true;
     }
     var Value = Summary.value;
     if(!Value || !InputChecked){
          OKInput.disabled = "disabled";
     }else{
          OKInput.disabled = false;
     }
}

// --------------------------------------------------------------------------------------------
// Validation du formulaire de suppression

function DeleteBot_CheckMenu(){
     var Form = document.getElementById("DeleteBot_Form");
     var Summary = document.getElementById("DeleteBot_Summary");
     if(!Summary || !Form) return;
     var CatArray = new Array();
     var Inputs = Form.getElementsByTagName('input');
     for(var a=0,l=Inputs.length;a<l;a++){
          var Input = Inputs;
          if(Input.checked) CatArray.push(Input.value);
     }
     DeleteBot_Text_Summary = Summary.value;
     DeleteBot_DeletePage(CatArray, 0);
}

// --------------------------------------------------------------------------------------------
// Suppression d'une page

function DeleteBot_DeletePage(CatArray, position){
     var Page = CatArray;
     if(!Page){
          document.location = document.URL; 
          return;
     }
     var SurEtCertain = true;
     if(!DeleteBot_Param_NoConfirm) SurEtCertain = confirm(DeleteBot_Text_ConfirmDeleteThisPage.split("$1").join(Page));
     if(!SurEtCertain){
          DeleteBot_DeletePage(CatArray, (position+1));
          return;
     }
     var URL = mw.config.get('wgServer') + mw.config.get('wgScript')
             + '?title=' + encodeURIComponent(Page)
             + '&action=delete'; 
     DeleteBot_ajax.http({ 
          url       : URL,
          catlist   : CatArray,
          pos       : position,
          page      : Page,
          onSuccess : DeleteBot_DeletePageProcess
     });
}

function DeleteBot_DeletePageProcess(Req, data){
     var CatArray = data.catlist;
     var position = data.pos;
     var Page = data.page;
     while(document.body.firstChild){ document.body.removeChild(document.body.firstChild); }
     document.body.innerHTML = Req.responseText;
     var Form = document.getElementById("deleteconfirm");
     if(!Form) Form = document.getElementById("mw-img-deleteconfirm");
     var Summary = document.getElementById("wpReason");
     if(!Form || !Summary){
          DeleteBot_DeletePage(CatArray, (position+1));
          return;
     }
     Summary.value = DeleteBot_Text_Summary;
     var Action = Form.action;
     var Params = DeleteBot_getFormParams(Form);
     var ParamsInURL = new Array();
     for(var P in Params){
         if(Params.hasOwnProperty(P)) ParamsInURL.push(P+"="+encodeURIComponent(Params));
     }
     var headers = new Array();
     headers = 'application/x-www-form-urlencoded';
     DeleteBot_ajax.http({ url: Action,
                           method: "POST",
                           headers: headers,
                           data: ParamsInURL.join("&"),
                           onSuccess:function(){ DeleteBot_DeletePage(CatArray, (position+1)) },
     });     
}

function DeleteBot_getFormParams(Form){
     var Params = new Array();
     var Tags = new Array("textarea", "select", "input");
     for(var a=0,l=Tags.length;a<l;a++){
          var Elements = Form.getElementsByTagName(Tags);
          for(var b=0,m=Elements.length;b<m;b++){
               var Element = Elements;
               var ElName = Element.name;
               if(!ElName) continue;
               var ElValue = Element.value;
               var ElType = Element.type;
               if(Tags.toLowerCase()=='input' && (ElType == "checkbox" || ElType == "radio") && Element.checked){
                    Params = ElValue;
               }else if(Tags.toLowerCase()=='input' && (ElType == "text" || ElType == "hidden") ){
                    Params = ElValue;
               }else if(Tags.toLowerCase()!='input'){
                    Params = ElValue;
               }
          }
     }
     return Params;
}