Utilisateur:Dr Brains/ListAllFalsePortals.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./*
__NOTOC__
<center><h2 style="margin-top:-1.5em;background-color:white;"> Mise à jour des listes de portails</h2></center>
<div id="ListAllFalsePortals_Link">[[Image:Crystal Clear action exit.svg|100px|center|Démarrer la mise à jour|link=]]</div>
<div id="ListAllFalsePortals_Results"></div>
{{#ifeq:{{{showdoc|}}}|non||
----
<center><h2> Documentation</h2></center>
<div style="border:2px dashed green;padding:1.5em;">Pour utiliser ce programme :
# ajouter à votre [[Special:Mypage/common.js|common.js]] le code :
#* '''<code>importScript('[[Utilisateur:Dr Brains/ListAllFalsePortals.js]]');</code>'''
# ajouter dans n'importe quelle page de l'[[Aide:espace de noms|espace de noms]] <code>Utilisateur:</code> le code :
#* '''<code><nowiki>{{Utilisateur:Dr Brains/ListAllFalsePortals.js}}</nowiki></code>'''
# Purger le cache de votre navigateur
# Cliquer sur le gros bouton rouge ci-dessus.
</div>}}
{{#ifeq:{{{showscript|}}}|oui|
----
<center><h2>Script</h2></center>
<center><h5>[[Utilisateur:Dr Brains/ListAllFalsePortals.js]] (Licence : [[Domaine public (propriété intellectuelle)|Domaine public]])</h5></center>
<!--
*/
//-->{{Boîte déroulante début|titre=Variables}}<source lang=javascript>//<pre><nowiki>
var ListAllFalsePortals_APILimit = ( ((mw.config.get('wgUserGroups').indexOf("sysop")!=-1)||(mw.config.get('wgUserGroups').indexOf("bot")!=-1)) ? 4999 : 499 );
// API URL
var ListAllFalsePortals_APIURL_AllPortals = '//fr.wikipedia.org/w/api.php?format=xml&action=query&list=allpages&aplimit='+ListAllFalsePortals_APILimit+'&apnamespace=100&apfilterredir=nonredirects';
//</nowiki></pre></source>{{Boîte déroulante fin}}{{Boîte déroulante début|titre=FONCTION : Fonctions Ajax}}<source lang=javascript>//<pre><nowiki>
var ListAllFalsePortals_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);
}
}
}
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;
};
function ListAllFalsePortals_GetPage(URL, NextFunc){
ListAllFalsePortals_Ajax({ url: URL,
onSuccess:NextFunc
});
}
function ListAllFalsePortals_SavePage(NextFunc){
//if(!confirm("OK ?")) return;
var Form = document.getElementById('editform');
var action = Form.action;
var headers = new Array();
headers['Content-Type'] = 'application/x-www-form-urlencoded';
ListAllFalsePortals_Ajax({ url: action,
method: "POST",
headers: headers,
data: ListAllFalsePortals_createURLFromParams(ListAllFalsePortals_getFormParams(Form)),
onSuccess:(NextFunc ? NextFunc : function(){ window.location.reload(); } )
});
}
//</nowiki></pre></source>{{Boîte déroulante fin}}{{Boîte déroulante début|titre=FONCTION : Suppression des caractères HTML}}<source lang=javascript>//<pre><nowiki>
function ListAllFalsePortals_HTMLDecode(text){
var EncodedCharacter = new Array();
var DecodedCharacter = new Array();
var CharacterCount = 0;
EncodedCharacter[CharacterCount] = "&";
DecodedCharacter[CharacterCount] = "&";
CharacterCount++;
EncodedCharacter[CharacterCount] = "'";
DecodedCharacter[CharacterCount] = "'";
CharacterCount++;
EncodedCharacter[CharacterCount] = """;
DecodedCharacter[CharacterCount] = '"';
CharacterCount++;
for(var a=0;a<EncodedCharacter.length;a++){
while(text.indexOf(EncodedCharacter[a])!=-1){
text = text.split(EncodedCharacter[a]).join(DecodedCharacter[a]);
if(text.indexOf(EncodedCharacter[a])==-1) break;
}
}
return text;
}
//</nowiki></pre></source>{{Boîte déroulante fin}}{{Boîte déroulante début|titre=FONCTION : suivi du process}}<source lang=javascript>//<pre><nowiki>
function ListAllFalsePortals_Alert(Text){
if(!Text) Text = '';
var ControlElement = document.getElementById('ListAllFalsePortals_Control');
if(ControlElement) ControlElement.innerHTML = Text;
}
//</nowiki></pre></source>{{Boîte déroulante fin}}{{Boîte déroulante début|titre=Lancement}}<source lang=javascript>//<pre><nowiki>
if(mw.config.get('wgNamespaceNumber')==2) addOnloadHook(ListAllFalsePortals_AddLinks);
//</nowiki></pre></source>{{Boîte déroulante fin}}{{Boîte déroulante début|titre=Ajout du lien de mise à jour}}<source lang=javascript>//<pre><nowiki>
function ListAllFalsePortals_AddLinks(){
var ButtonLink = document.getElementById('ListAllFalsePortals_Link');
if(!ButtonLink) return;
var Link = '<a id="ListAllFalsePortals_A" href="javascript:ListAllFalsePortals_Run();" title="Lancer la mise à jour">' + ButtonLink.innerHTML + '</a>';
ButtonLink.innerHTML = Link;
var Separator = document.createElement('br');
var ControlSpan = document.createElement('span');
ControlSpan.id = 'ListAllFalsePortals_Control';
ButtonLink.parentNode.insertBefore(Separator, ButtonLink);
ButtonLink.parentNode.insertBefore(ControlSpan, Separator);
}
//</nowiki></pre></source>{{Boîte déroulante fin}}{{Boîte déroulante début|titre=Recherche des pages de l'espace de noms Portail: }}<source lang=javascript>//<pre><nowiki>
var ListAllFalsePortals_Array = new Array();
function ListAllFalsePortals_Run(){
if(ListAllFalsePortals_Array.length>0) return;
ListAllFalsePortals_Alert("Listage de tous les portails");
ListAllFalsePortals_GetPage(ListAllFalsePortals_APIURL_AllPortals, ListAllFalsePortals_AllPortals);
}
function ListAllFalsePortals_AllPortals(Req){
var ThesePortals = new Array();
var ObjetXML = Req.responseXML;
var AllPortals = ObjetXML.getElementsByTagName('p');
for(a=0;a<AllPortals.length;a++){
var TitrePage =AllPortals[a].getAttribute('title');
if(ListAllFalsePortals_Array.indexOf(TitrePage)==-1){
var thisBasePageName = Page.split("/")[0];
if(ThesePortals.indexOf(thisBasePageName)==-1) ThesePortals.push(TitrePage);
}
}
ListAllFalsePortals_Array.concat(ThesePortals);
var AutreRequeteNecessaire = ObjetXML.getElementsByTagName('query-continue')[0];
if(AutreRequeteNecessaire){
var ContinueParam = AutreRequeteNecessaire.firstChild.attributes[0];
var AutreRequeteContinue = ContinueParam.value;
ListAllFalsePortals_Alert("Listage de tous les portails : "+AutreRequeteContinue);
ListAllFalsePortals_GetPage(ListAllFalsePortals_APIURL_AllPortals+'&'+ContinueParam.name+'='+encodeURIComponent(AutreRequeteContinue), ListAllFalsePortals_AllPortals);
}else{
ListAllFalsePortals_Alert("Tri des pages");
ListAllFalsePortals_Sort();
}
}
//</nowiki></pre></source>{{Boîte déroulante fin}}{{Boîte déroulante début|titre=Tri alphabétique des pages}}<source lang=javascript>//<pre><nowiki>
var ListAllFalsePortals_SortedArray = new Array();
function ListAllFalsePortals_Sort(){
ListAllFalsePortals_Alert("Tri des portails");
for(var b=0;b<ListAllFalsePortals_Array.length;b++){
var Page = ListAllFalsePortals_Array[b];
if(Page.indexOf("/")==-1) continue
var BasePageName = Page.split("/")[0];
if(ListAllFalsePortals_Array.indexOf(BasePageName)!=-1) continue;
ListAllFalsePortals_SortedArray.push(Page);
}
ListAllFalsePortals_Alert("Création des nouvelles listes");
ListAllFalsePortals_CreateTemplate();
}
//</nowiki></pre></source>{{Boîte déroulante fin}}{{Boîte déroulante début|titre=Création de la liste}}<source lang=javascript>//<pre><nowiki>
function ListAllFalsePortals_CreateTemplate(){
var Text;
var Number = ListAllFalsePortals_SortedArray.length
var ResultDiv = document.getElementById("ListAllFalsePortals_Results");
var TextArea = document.createElement('textarea');
ResultDiv.appendChild(TextArea);
if(Number == 0){
Text = "Pas de faux portail";
}else{
Text = "";
for(var a=0,l=Number;a<l;a++){
var Page = ListAllFalsePortals_SortedArray[a];
Text += '# [['+Page+']]\n';
}
}
TextArea.value = Text;
ListAllFalsePortals_Alert("");
}
//</nowiki></pre></source>{{Boîte déroulante fin}}|}}