Aller au contenu

Utilisateur:Dr Brains/CheckEvalInCat.js

Une page de Wikipédia, l'encyclopédie libre.
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.
var CheckEvalInCat = new Object();
CheckEvalInCat.Textes = new Object();
CheckEvalInCat.Params = new Object();
CheckEvalInCat.Variables = new Object();
CheckEvalInCat.Fonctions = new Object();


////////////////////////////// DEBUT DE LA PARTIE PERSONNALISABLE ////////////////////////////

CheckEvalInCat.Textes.LinkTitle = "Voir les évaluations";
CheckEvalInCat.Textes.LinkText = "Évaluation";
CheckEvalInCat.Textes.PanelLinkTitle = "Voir l’évaluation";
CheckEvalInCat.Textes.PanelLinkText = "éval";
 

CheckEvalInCat.Textes.AllEvalButtonText = "Évaluations";
CheckEvalInCat.Textes.AllEvalButtonTitle = "Voir toutes les évaluations";
CheckEvalInCat.Textes.CloseButtonText = "Fermer";
CheckEvalInCat.Textes.CloseButtonTitle = "Fermer la fenêtre";


/////////////////////////////// FIN DE LA PARTIE PERSONNALISABLE /////////////////////////////
 
CheckEvalInCat.Variables.PageList = new Array();

CheckEvalInCat.Variables.APILimit = ((mw.config.get('wgUserGroups').indexOf("sysop")!=-1||mw.config.get('wgUserGroups').indexOf("bot")!=-1) ? 4999 : 499 );
 
// Ajout d'un lien dans la boîte à outils
 
CheckEvalInCat.Fonctions.Link = function(){
     if(typeof(CheckEvalInCat.Fonctions.LangCustom)=="function") CheckEvalInCat.Fonctions.LangCustom();
     if(typeof(CheckEvalInCat.Fonctions.SiteCustom)=="function") CheckEvalInCat.Fonctions.SiteCustom();
     if(typeof(CheckEvalInCat.Fonctions.UserCustom)=="function") CheckEvalInCat.Fonctions.UserCustom();
     var ToolBoxes = getElementsByClassName(document, "span", "CategoryTools");
     for(var a=0,l=ToolBoxes.length;a<l;a++){
          ToolBoxes[a].innerHTML += '&nbsp;•&nbsp;<a href="javascript:CheckEvalInCat.Fonctions.ListPages();" title="'+CheckEvalInCat.Textes.LinkTitle+'">'+CheckEvalInCat.Textes.LinkText+'</a>';
     }
}
 
CheckEvalInCat.Fonctions.Ajax = 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){ if(xmlhttp.status == 200 || xmlhttp.status == 302){ if(bundle.onSuccess) bundle.onSuccess(xmlhttp,bundle); }else if(bundle.onFailure){ bundle.onFailure(xmlhttp,bundle); }else{ };}}; 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[field]); }catch(err){}}}; xmlhttp.send(bundle.data ? bundle.data : null); }; return xmlhttp;}

CheckEvalInCat.Fonctions.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&list=categorymembers'
             + '&cmlimit=' + CheckEvalInCat.Variables.APILimit
             + '&cmtitle=' + encodeURIComponent(category) 
             + categorycontinue;
 
     CheckEvalInCat.Fonctions.Ajax({ 
          url: URL,
          cat: category,
          catlist: CatArray,
          onSuccess:CheckEvalInCat.Fonctions.ListPagesDone
     });
}

CheckEvalInCat.Fonctions.ListPagesDone = function(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[a].getAttribute('title');
          if(CatArray.indexOf(TitrePage)==-1) CatArray.push(TitrePage);
     }
     var CatContinue = ElementTraitement.getElementsByTagName('query-continue')[0];
     if(CatContinue){
          var AutreRequeteContinue = '&cmcontinue=' + encodeURIComponent(CatContinue.firstChild.getAttribute("cmcontinue"));
          CheckEvalInCat.Fonctions.ListPages(CatArray, category, AutreRequeteContinue);
     }else{
          if(CatArray.length>0) CheckEvalInCat.Fonctions.CreatePanel(CatArray);
          else alert("Pas de page");
     }
}

CheckEvalInCat.Fonctions.ClosePanel = function(){
     var Div = document.createElementById("CheckEvalInCat_Div");
     if(Div) Div.parentNode.removeChild(Div);
}

CheckEvalInCat.Fonctions.CreatePanel = function(CatArray){
     CheckEvalInCat.Variables.PageList = CatArray;
     var Div = document.createElement('div');
     Div.id = "CheckEvalInCat_Div";
     Div.setAttribute("style", "position:fixed;left:0;right:0;width:100%;height:100%;overflow:auto;-moz-column-count:3;-webkit-column-count:3;column-count:3;text-align:left;font-size:13px;");
     document.body.appendChild(Div);
     var Buttons = document.createElement('p');
     Div.appendChild(Buttons);
     ButtonText = ''
     + '<center>'
     + '<input type="button" style="cursor:pointer;" '
     + ' value="'+CheckEvalInCat.Textes.AllEvalButtonText+'" title="'+CheckEvalInCat.Textes.AllEvalButtonTitle+'" '
     + ' onclick="CheckEvalInCat.Fonctions.getEval(0, true);" onselect="CheckEvalInCat.Fonctions.getEval(0, true);"/>'
     + '&nbsp;&nbsp;'
     + '<input type="button" style="cursor:pointer;" '
     + ' value="'+CheckEvalInCat.Textes.CloseButtonText+'" title="'+CheckEvalInCat.Textes.CloseButtonTitle+'" '
     + ' onclick="CheckEvalInCat.Fonctions.ClosePanel();" onselect="CheckEvalInCat.Fonctions.ClosePanel();"/>'
     + '</center>';

     Buttons.innerHTML = ButtonText;
     var Ul = document.createElement('ul');
     Div.appendChild(Ul);
     for(var index=0,l=CatArray.length;index<l;index++){
          var Page = CatArray[index];
          var Li = document.createElement('li');
          Li.id = "CheckEvalInCat_Li_"+index;
          Ul.appendChild(Li);
          var Text = '<a href="'+mw.config.get('wgArticlePath').split("$1").join(encodeURIComponent(Page))+'" title="'+Page+'">'+Page+'</a>&nbsp;<small id="CheckEvalInCat_Small_'+index+'"><a href="javascript:CheckEvalInCat.Fonctions.getEval('+index+')" title="'+CheckEvalInCat.Textes.PanelLinkTitle+'">'+CheckEvalInCat.Textes.PanelLinkText+'</a></small>'
         Li.innerHTML = Text;
     }
}

CheckEvalInCat.Fonctions.getEval = function(position, getAll){



}

if(mw.config.get('wgNamespaceNumber')==14) addOnloadHook(CheckEvalInCat.Fonctions.Link);