importScriptURI("//www.wikidata.org/w/index.php?title=User:Yair rand/WikidataInfo.js&action=raw&ctype=text/javascript")
//</pre>
/*<pre><nowiki>*/
//=== inizio: CATEGORY WATCH ===
var cwwpajax;
// From [[WP:US]] mainpage (wpajax renamed to cwwpajax)
cwwpajax={
download:function(bundle) {
// mandatory: bundle.url
// optional: bundle.onSuccess (xmlhttprequest, bundle)
// optional: bundle.onFailure (xmlhttprequest, bundle)
// optional: bundle.otherStuff OK too, passed to onSuccess and onFailure
var x = window.XMLHttpRequest ? new XMLHttpRequest()
: window.ActiveXObject ? new ActiveXObject("Microsoft.XMLHTTP")
: false;
if (x) {
x.onreadystatechange=function() {
x.readyState==4 && cwwpajax.downloadComplete(x,bundle);
};
x.open("GET",bundle.url,true);
x.send(null);
}
return x;
},
downloadComplete:function(x,bundle) {
x.status==200 && ( bundle.onSuccess && bundle.onSuccess(x,bundle) || true )
|| ( bundle.onFailure && bundle.onFailure(x,bundle) || alert(x.statusText));
}
};
//Aggiunge le catwatch alla watchlist
//xmlreq=risultato della query (es:http://it.wikipedia.org/w/query.php?what=category&cptitle=Guerre%20Stellari&cplimit=100&cpextended&format=xml)
//data=nome della categoria
function cwOntoWatchlist(xmlreq, data)
{
var a=xmlreq.responseText;
var c=data.catname;
var i;
if(a.indexOf("<error>")!=-1) //cat e' vuota, niente da fare qui
{
var inoltre;
if (c.indexOf("Categoria:")!=-1)
inoltre="Ti ricordo che non va inserita la parte \"Categoria:\"";
else
inoltre="";
if (showWarning.indexOf("disabilita")==-1)
alert("La categoria \""+c+"\" sembra vuota.\nControlla se il nome e' scritto giusto.\n"+inoltre);
return;
}
if(a.indexOf("<category next=")!=-1) //cat ha piu' di 100 elementi, i risultati verranno eliminati
{
if (showWarning.indexOf("disabilita")==-1)
alert("La categoria \""+c+"\" ha piu' di 100 elementi e non puo' essere monitorata.\n"+
"Considera la possibilita' di dividerla in sottocategorie");
return;
}
a=a.split("<timestamp>");
var latesttime=0;
var latestpage="";
var listaPagine=new Array();
var listaTime=new Array();
var temp, temp2;
var counter=0;
for(i in a)
{
temp=a[i].indexOf("</timestamp>");
if(temp!=-1)
{
temp=new Number(a[i].substr(0,temp));
if(temp>latesttime)
{
listaTime[counter]=temp;
a[i]=a[i].substr(a[i].indexOf("<title>")+7);
listaPagine[counter]=a[i].substr(0,a[i].indexOf("</title>"));
counter++;
}
}
}
var dates=document.getElementsByTagName("h4"); //recupera le date dalla pagina della watchlist
var monthname=new Array();
monthname['01']="gen";
monthname['02']="feb";
monthname['03']="mar";
monthname['04']="apr";
monthname['05']="mag";
monthname['06']="giu";
monthname['07']="lug";
monthname['08']="ago";
monthname['09']="set";
monthname['10']="ott";
monthname['11']="nov";
monthname['12']="dic";
i=dates.length;
var totcycle=listaPagine.length; // numero delle pagine della Categoria corrente
while(i--) // Per ogni giorno della lista
{
for (var loopTimes=0;loopTimes<totcycle;loopTimes++) // Per ogni pagina della lista
{
latestpage=listaPagine[loopTimes];
latesttime=listaTime[loopTimes];
latesttime=new String(latesttime);
// es: temp=2006 dic 25
temp=""+new Number(latesttime.substr(6,2))+" "+monthname[latesttime.substr(4,2)]+" "+latesttime.substr(0,4);
// se la data che stiamo esaminando corrisponde alla data della pagina
if(dates[i].firstChild.nodeValue==temp)
{
temp=dates[i].nextSibling.firstChild;
// Questo while dovrebbe inserire la modifica in ordine cronologico
// tra le altre modifiche. Funzionava solo nella versione inglese e l'ho
// lasciata qui perche', qualche anima pia, potrebbe in futuro correggerla
while(temp!=null)
{
if(temp.tagName!=null)
if(temp.tagName.toLowerCase()=="li")
{
temp2=temp.innerHTML.match(/; ([0-9][0-9]):([0-9][0-9]) \. \./);
temp2=new Number(temp2[1])*100+new Number(temp2[2]);
if(temp2<new Number(latesttime.substr(8,4))) {temp2=temp; break;}
}
temp2=temp; temp=temp.nextSibling;
if(temp==null) break;
}
// l'elemento che andra' inserito
temp3=document.createElement("li");
// se l'ordinamento aveva funzionato (ovvero mai)
if (temp2!=null)
{
dates[i].nextSibling.insertBefore(temp3,temp2);
}
else
{
dates[i].appendChild(temp3);
}
// riempi l'item con i dati necessari
temp3.innerHTML="<font size=-1>Modifiche in <a href='http://it.wikipedia.org/wiki/Categoria:"+encodeURI(c)+
"'>Categoria:"+c+"</a>; "+latesttime.substr(8,2)+":"+latesttime.substr(10,2)+" . . (+ "+
"<a href='http://it.wikipedia.org/wiki/"+encodeURI(latestpage)+"'>"+latestpage+"</a> "+
"(<a href='http://it.wikipedia.org/w/index.php?title="+encodeURI(latestpage)+
"&diff=last'>diff</a>) (<a href='http://it.wikipedia.org/w/index.php?title="+
encodeURI(latestpage)+"&action=history'>cron</a>))</font>";
}
}
}
}
var CategorieOsservate; //evita errori se ancora non esiste una cat-watchlist
var showWarning; //evita errori se ancora non esiste una cat-watchlist
//Un esempio di query per il controllo di una categoria potrebbe essere
//http://it.wikipedia.org/w/query.php?what=category&cptitle=Guerre%20Stellari&cplimit=100&cpextended&format=xml
addOnloadHook(function(){
// se siamo nella watchlist
if(wgPageName=="Speciale:Watchlist")
{
if(CategorieOsservate==undefined) // se non e' mai stata creata la lista personale delle Categorie
{
if(confirm("Ancora non hai una lista di categorie da controllare. Vuoi crearne una?"))
___location.href='http://it.wikipedia.org/w/index.php?title=Utente:'+wgUserName+
'/CategorieOsservate.js&action=edit&preload=Utente:Jalo/CategorieOsservateTemplate.js';
}
else // la lista gia' esiste
{
var i;
for(i in CategorieOsservate) // Per ogni cateoria lancia il controllo
{
var a=CategorieOsservate[i];
cwwpajax.download({url:'http://it.wikipedia.org/w/query.php?what=category&cptitle='+encodeURI(a)+
'&cplimit=100&cpextended&format=xml', onSuccess:cwOntoWatchlist, catname:a});
}
}
}
});
// aggiungi la watchlist delle categorie dell'utente
document.write('<script type="text/javascript" src="http://it.wikipedia.org'
+ '/w/index.php?title=Utente:'+wgUserName+'/CategorieOsservate.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
//=== fine: CATEGORY WATCH ===
/* </nowiki></pre> */
|