Wikipedia:Monobook.js: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
Riga 903:
Per usarlo bisogna usare questo codice copiandolo nel proprio monobook (ma dovrebbe andare anche per vector ecc.) '''nella wiki straniera da cui vogliamo tradurre'''. A quel punto, aprendo una loro voce in modifica, apparirà nella colonna di sinistra (sotto a "Strumenti", "Tools" o come lo chiamano loro) un link chiamato "Traduci i wikilink". Cliccandoci sopra, e con un po' di pazienza, vi verrà proposta una lista simile a questa qui accanto. La prima volta che lo usate il vostro browser potrebbe arrabbiarsi per il tentativo di aprire un popup, in questo caso confermate che è ok. Voci lunghe necessitano, ovviamente, di più tempo. Cliccare continuamente sul link non aiuta, anzi... '''''<span style="font-size:medium;font-family:Comic Sans MS">[[Utente:Jalo|<span style="color:#BB0011">J</span>]][[Discussioni utente:Jalo|<span style="font-size:small;color:#DD2233">alo</span>]]</span>''''' 12:35, 26 lug 2010 (CEST)
==== Ricerca di voci da tradurre ====
{{cassetto|titolo=Codice del tool|testo=
<source lang=javascript>
//Funzioni per fare le query al DB con api.php
var wpajax = {
http: function(bundle) {
// mandatory: bundle.url
// optional: bundle.async
// optional: bundle.method
// optional: bundle.headers
// optional: bundle.data
// optional: bundle.onSuccess (xmlhttprequest, bundle)
// optional: bundle.onFailure (xmlhttprequest, bundle)
// optional: bundle.otherStuff OK too, passed to onSuccess and onFailure
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)
wpajax.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)
xmlhttp.setRequestHeader(field,bundle.headers[field]);
}
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 {
// A activer en debug mode ?
// alert(xmlhttp.statusText);
}
}
};
// Parser
if (document.implementation.createDocument) {
var gml_xmlparser = new DOMParser();
}
function gml_XMLParse(string) {
if (document.implementation.createDocument) {
return gml_xmlparser.parseFromString(string, "text/xml");
} else if (window.ActiveXObject) {
var gml_xmldoc = new ActiveXObject("Microsoft.XMLDOM");
gml_xmldoc.async = "false";
ret = gml_xmldoc.loadXML(string);
if (!ret)
return null;
return gml_xmldoc.documentElement;
}
return null;
}
// HTMLize
String.prototype.htmlize = function() {
var chars = new Array('&','<','>','"');
var entities = new Array('amp','lt','gt','quot');
var regex = new RegExp();
var string = this;
for (var i=0; i<chars.length; i++) {
regex.compile(chars[i], "g");
string = string.replace(regex, '&' + entities[i] + ';');
}
return string;
}
//Alias di document.getElementById
$ = function(id){
return document.getElementById(id);
};
/****** INIZIO TOOL DI TRADUZIONE INTERWIKI ******/
// Elenco dei [[ ]]
var elencoLink = new Array();
function tradToIT()
{
// Recupera l'area di testo
text = $("wpTextbox1").value;
elencoLink.length=0;
result = "";
inseriti = "|";
while (text.indexOf("[[") != -1)
{
text = text.substring(text.indexOf("[[")+2);
to1 = text.indexOf("]]");
if (to1 == -1)
to1 = 10000000;
to2 = text.indexOf("|");
if (to2 == -1)
to2 = 10000000;
to3 = text.indexOf(":");
if (to3 == -1)
to3 = 10000000;
if (to3<to2 && to3<to1) // si tratta di un interwiki o di un link a namespace!=0. Va saltato
{
text = text.substring(2);
continue;
}
link = text.charAt(0).toUpperCase(); // prima lettera maiuscola
link += text.substring(1, (to1<to2)?to1:to2);
if (inseriti.indexOf("|"+link+"|") == -1)
elencoLink[elencoLink.length] = link; // così non mette i doppioni
inseriti += link+"|";
}
// Per ogni [[ ]]
for (x in elencoLink)
{
// Ricava l'elenco degli interwiki della voce in oggetto
wpajax.http({url: wgServer + wgScriptPath + '/api.php?action=query&prop=langlinks&titles='+escape(elencoLink[x])+'&redirects&format=xml&lllimit=500',
onSuccess: addRow, en: elencoLink[x] });
}
}
// Crea la lista dei risultati
var result = "";
var total=0;
function addRow(xmlreq, data) {
var api = xmlreq.responseXML;
var en = data.en;
// Cerca se c'è "it.wiki"
interwikis = api.getElementsByTagName('ll');
trovato = "";
for (i=0; i<interwikis.length; i++)
if (interwikis[i].getAttribute('lang')=="it")
{
trovato = interwikis[i].textContent;
break;
}
// Aggiungi al totale la riga: [[en.wiki]] => [[it.wiki]] / No link
if (trovato != "")
result += "<a href='"+wgServer+"/wiki/"+escape(en)+"'>" + en + "</a> => <a href='http://it.wikipedia.org/wiki/"+escape(trovato)+"'>" + trovato + "</a><br/>";
else
result += "<a href='"+wgServer+"/wiki/"+escape(en)+"'>" + en + "</a> => No link<br/>";
if (++total == elencoLink.length)
{
// splitto su <br/>
list = result.split("<br/>");
// ordina la lista
list.sort();
// ricrea la stringa
result = list.join("<br/>");
result = result.substring(5); // elimino il <br/> iniziale
// Mostra tutta la lista calcolata
total=0;
myRef = window.open('about:blank','mywin', 'left=20,top=20,width=300,height=300,toolbar=yes,resizable=yes');
myRef.document.write("<div style='width: 100%; height: 100%; overflow: auto'> "+result+"</div>");
}
}
addOnloadHook(function () {
if (wgAction=="edit")
{
addPortletLink('p-tb', 'javascript:tradToIT()', 'Traduci i wikilink', 'tradIT');
$('tradIT').firstChild.accessKey = 'T';
$('tradIT').title = 'Traduci i wikilink (Alt-Shift-T)';
}
})
/****** FINE TOOL DI TRADUZIONE INTERWIKI ******/
/****** INIZIO TOOL DI RICERCA VOCI DA TRADURRE ******/
// controlla se l'array "array" contiene il valore "stringa"
function contiene(array, stringa) {
for (var i = 0; i < array.length; i++) {
if (array[i] == stringa) {
return true;
}
}
return false;
}
var vociInglesi = new Array();
var vociDaTrad = new Array();
var interwikisCount = new Array();
var noCategory = new Array();
var countVociDaTrad = 0;
// cicla sull'elenco delle categorie chieste dall'utente
function analisiVoci() {
for (i = 0; i < vociInglesi.length; ++i)
{
// Ricava l'elenco degli interwiki della voce in oggetto
myXmlReq = wpajax.http({url: wgServer + wgScriptPath + '/api.php?action=query&prop=langlinks&titles='+escape(vociInglesi[i])+'&redirects&format=xml&lllimit=500', onSuccess: addToVociDaTrad, en: vociInglesi[i]});
}
}
function addToVociDaTrad(xmlreq, data) {
var api = xmlreq.responseXML;
var en = data.en;
if (api == null)
{
++countVociDaTrad;
return;
}
// Cerca se c'è "it.wiki"
interwikis = api.getElementsByTagName('ll');
trovato = "";
for (j=0; j<interwikis.length; j++)
if (interwikis[j].getAttribute('lang')=="it")
{
trovato = interwikis[j].textContent;
break;
}
// Aggiungi al totale la riga: [[en.wiki]] => [[it.wiki]] / No link
if (trovato == "")
{
vociDaTrad.push(en);
interwikisCount.push(interwikis.length);
}
if (++countVociDaTrad == vociInglesi.length)
{
// ordina la lista
vociDaTrad.sort()
// crea contenuto da salvare
contenuto = "";
for (i = 0; i < vociDaTrad.length; ++i)
{
contenuto += "<li><a href='"+wgServer+"/wiki/"+escape(vociDaTrad[i])+"'>" + vociDaTrad[i] + "</a> (" + interwikisCount[i] + ")</li>";
}
// crea lista categorie inesistenti
nocat = "";
if (noCategory.length > 0)
{
nocat += "Le seguenti categorie non esistono su "+wgContentLanguage+".wiki: ";
for (i = 0; i < noCategory.length; ++i)
{
nocat += noCategory[i] + ", ";
}
nocat = nocat.substr(0, nocat.length-2) + "<br/><br/>";
}
// finito di creare la lista la mostro in una nuova finestra
myRef = window.open('about:blank','mywin', 'left=20,top=20,width=500,height=300,toolbar=yes,resizable=yes');
myRef.document.write("<div style='width: 100%; height: 100%; overflow: auto'> ");
myRef.document.write("<big><big><big>Voci di en.wiki mancanti su it.wiki</big></big></big><br/><br/>");
myRef.document.write("Tra parentesi il numero di interlink presenti su en.wiki<br/><br/>");
myRef.document.write(nocat);
myRef.document.write("<ol>"+contenuto+"</ol>");
myRef.document.write("</div>");
}
}
var totaleCategorie = 0;
var countCategorie = 0;
// cicla sull'elenco delle categorie chieste dall'utente
function scansioneCategorie() {
categorie = $("Lista").value.split("\n");
totaleCategorie = categorie.length;
for (i = 0; i < categorie.length; ++i)
{
myXmlReq = wpajax.http({url: wgServer + wgScriptPath + '/api.php?action=query&list=categorymembers&cmprop=title&cmnamespace=0&cmlimit=500&format=xml&cmtitle=Category:'+categorie[i], onSuccess: addToVociInglesi, cat: categorie[i]});
}
// nascondo la finestra
node=$('categorie');
node.parentNode.removeChild(node);
}
function addToVociInglesi(xmlreq, data) {
var api = xmlreq.responseXML;
var cat = data.cat;
if (api.getElementsByTagName("categorymembers")[0].childNodes.length == 0) // categoria non esistente
noCategory.push(cat);
if (api)
{
cm = api.getElementsByTagName('cm');
var voce="";
for(j=cm.length-1; j >= 0 ; j--) {
voce = cm[j].attributes[1].nodeValue;
if (voce == "") continue;
if (!contiene(vociInglesi, voce)) // se non è già in lista
vociInglesi.push(voce);
}
}
if (++countCategorie == totaleCategorie)
analisiVoci();
}
// mostra finestra in cui si chiede quali categorie tradurre
function categorieDaTradurre() {
var msWndSetup = document.createElement('div');
msWndSetup.id = 'categorie';
msWndSetup.style.position = 'fixed';
msWndSetup.style.zIndex = 1000;
msWndSetup.style.left = '0px';
msWndSetup.style.top = '0px';
msWndSetup.style.backgroundColor = '#FFFFFF';
msWndSetup.style.borderStyle = 'solid';
msWndSetup.style.borderWidth = ' medium';
msWndSetup.style.borderColor = '#000000';
msWndSetup.style.width = '300px';
msWndSetup.align = 'center';
var top = document.createElement('div');
top.id = 'categorieTop';
top.style.textAlign = 'right';
top.style.margin = '8px';
top.style.backgroundColor = '#DDDDDD';
msWndSetup.appendChild(top);
var body = msWndSetup;
var intro = document.createElement('p');
intro.innerHTML = "<span style=\"font-size: medium; font-weight: bold;\">Elenco delle categorie da tradurre<br /><span style=\"font-size: small;\">(una per riga e senza \"Category:\")</span></span><br/><br/>";
body.appendChild(intro);
var Lista = document.createElement('textarea');
Lista.rows = 10;
Lista.width = "90%";
Lista.wrap = 'off';
Lista.name = 'Lista';
Lista.id = 'Lista';
Lista.style.marginLeft = "10px";
Lista.style.marginRight = "10px";
Lista.style.width = "90%";
body.appendChild(Lista);
// crea il bottone "Ok"
var buttonOk = document.createElement('input');
buttonOk.value = 'Ok';
buttonOk.type = 'button';
buttonOk.style.margin = '8px';
buttonOk.setAttribute('onclick', 'scansioneCategorie()');
// crea il bottone "Annulla"
var buttonCancel = document.createElement('input');
buttonCancel.value = 'Annulla';
buttonCancel.type = 'button';
buttonCancel.style.margin = '8px';
buttonCancel.setAttribute('onclick', "javascript:node=$('categorie');node.parentNode.removeChild(node);");
body.innerHTML += "\n";
body.appendChild(buttonOk);
body.appendChild(buttonCancel);
// e lo mostra a video
document.body.appendChild(msWndSetup);
Lista.focus();
}
addOnloadHook(function () {
addPortletLink('p-tb', 'javascript:categorieDaTradurre()', 'Voci da tradurre', 'daTradIT');
$('daTradIT').firstChild.accessKey = 'V';
$('daTradIT').title = 'Voci da tradurre (Alt-Shift-V)';
})
/****** FINE TOOL DI RICERCA VOCI DA TRADURRE ******/
//<source>
}}
Questo tool serve per cercare le voci presenti in una categoria di una wikipedia estera che mancano da noi. Il codice va copiato nel proprio monobook '''della wikipedia straniera''' da cui si vuole tradurre.
Dopo aver pulito la cache apparirà nella colonna di sinistra (sotto a "Strumenti", "Tools" o come lo chiamano loro) un link chiamato "Voci da tradurre". Cliccandoci sopra si aprirà una finestra in cui vanno elencate le categorie da controllare. Vanno inseriti i nomi delle categorie straniere, non quelle italiane, una per riga e senza il "Category:" davanti. Cliccando su ok verranno elencate le voci presenti in quelle categorie che non hanno interwiki verso it.wiki, oltre al numero di interwiki presenti in quelle voci (per capirne l'importanza). Evidenzia anche le categorie non esistenti, per segnalare eventuali errori di battitura.
Se la lista di categorie è lunga, o se le voci contenute sono molte, potrebbe richiedere qualche secondo in più ~~~~
<center><gallery>
File:Monobook - Cerca voci da tradurre - 1.PNG|La finestra in cui inserire le categorie
File:Monobook - Cerca voci da tradurre - 2.PNG|La finestra con il risultato della ricerca
</gallery></center>
==[[FAQ]]==
|