Utente:Ppong/vector.js: differenze tra le versioni
Vai alla navigazione
Vai alla ricerca
Contenuto cancellato Contenuto aggiunto
mNessun oggetto della modifica |
add rawcontinue URL parameter to make this work with the recent API change - see https://lists.wikimedia.org/pipermail/wikitech-l/2015-June/081931.html |
||
Riga 184: | Riga 184: | ||
function loadXMLDoc() |
function loadXMLDoc() |
||
{ |
{ |
||
var url = "/w/api.php?action=query&prop=revisions&format=xml"; |
var url = "/w/api.php?action=query&rawcontinue=&prop=revisions&format=xml"; |
||
url += "&titles=" + wgPageName + "&rvprop=ids|timestamp|user|comment"; |
url += "&titles=" + wgPageName + "&rvprop=ids|timestamp|user|comment"; |
||
url += "&rvlimit=" + revCount; |
url += "&rvlimit=" + revCount; |
Versione attuale delle 06:50, 9 lug 2015
/*
preso da: http://it.wikipedia.org/w/index.php?title=Wikipedia:Monobook.js/MostraModifiche.js&oldid=54473197
autore: nl:User:JePe
*/
function removeDiff()
{
var diffFrame = document.getElementById("revisionsBoxDiff");
if (diffFrame) diffFrame.parentNode.removeChild(diffFrame);
}
function makeCloseButton(position)
{
var closeButton = document.createElement("img");
with (closeButton) {
style.cssFloat = position;
style.styleFloat = position;
style.verticalAlign = "auto";
title = closeButtonTitle;
src = "//upload.wikimedia.org/wikipedia/commons/thumb/8/8d/No-Symbol.svg/9px-No-Symbol.svg.png";
height = "9";
width = "9"; }
return closeButton;
}
function processDiff()
{
if (diffReq.readyState != 4) return;
if (diffReq.status != 200) return;
var bodyContent = document.getElementById("bodyContent");
var diffFrame = document.createElement("div");
diffFrame.id = "revisionsBoxDiff";
diffFrame.innerHTML = diffReq.responseText;
diffTable = diffFrame.getElementsByTagName("table")[0];
if (!diffTable) return;
if ( $( diffTable ).hasClass( 'diff' ) == false ) return;
diffTable.style.border = "1px solid #ccc";
diffTable.style.width = "100%";
diffTable.style.paddingBottom = ".5em";
diffTable.style.marginBottom = "1em";
diffTable.style.marginTop = ".5em";
var closeButton = makeCloseButton("left");
closeButton.onclick = removeDiff;
var otitle = diffTable.getElementsByTagName("td");
for (i=0; i < otitle.length; i++) {
if (otitle[i].className == "diff-otitle") {
otitle[i].insertBefore(closeButton, otitle[i].firstChild); }
}
var diffFrameOld = document.getElementById("revisionsBoxDiff");
if (diffFrameOld) diffFrameOld.parentNode.removeChild(diffFrameOld);
bodyContent.parentNode.insertBefore(diffFrame,bodyContent);
window.location.hash = "revisionsBoxDiff";
var prevLink = document.getElementById("differences-prevlink");
if (prevLink) {
var oldid = prevLink.href.replace(/[\s\S]+&oldid=(\d+)[\s\S]*/,"$1");
prevLink.href = "javascript:mostraModificheLoadDiff("+oldid+",'prev')"; }
var nextLink = document.getElementById("differences-nextlink");
if (nextLink) {
var oldid = nextLink.href.replace(/[\s\S]+&oldid=(\d+)[\s\S]*/,"$1");
nextLink.href = "javascript:mostraModificheLoadDiff("+oldid+",'next')"; }
}
function mostraModificheLoadDiff(oldid,diffDir)
{
var url = "/w/index.php?title=" + wgPageName;
url += "&diff=" + diffDir;
url += "&oldid=" + oldid;
url += "&diffonly=1&action=render";
if (window.XMLHttpRequest) { // native XMLHttpRequest
diffReq = new XMLHttpRequest();
diffReq.onreadystatechange = processDiff;
diffReq.open("GET", url, true);
diffReq.send(null);
} else if (window.ActiveXObject) { // activeX version
diffReq = new ActiveXObject("Microsoft.XMLHTTP");
if (diffReq) {
diffReq.onreadystatechange = processDiff;
diffReq.open("GET", url, true);
diffReq.send("");
}
}
}
function nextRevisions()
{
var revContent = document.getElementById("recRevContent");
var divNode = revContent.appendChild(document.createElement("div"));
divNode.id = "nextButton";
divNode.style.textAlign = "center";
var button = divNode.appendChild(document.createElement("button"));
button.innerHTML = buttonNextText;
button.title = buttonNextTitle;
button.onclick = loadXMLDoc;
button.style.fontSize = "90%";
button.style.marginTop = ".3em";
button.style.padding = "0";
}
function writeResults(rev)
{
var showButton = document.getElementById('showButton');
var nextButton = document.getElementById('nextButton');
var revContent = document.getElementById("recRevContent");
if (showButton) {
showButton.parentNode.removeChild(showButton);
var closeButton = makeCloseButton("right");
closeButton.onclick = recentRevisions;
closeButton.style.marginTop = ".3em";
revContent.appendChild(closeButton); }
if (nextButton) nextButton.parentNode.removeChild(nextButton);
var date = new Date();
var dateNow = (date.getFullYear()*10000) + ((date.getMonth()+1)*100) + date.getDate();
for (i = 0; i < rev.length; i++) {
var time = rev[i].getAttribute("timestamp");
var year = time.replace(/^(\d\d\d\d)[\s\S]+/,"$1");
var month = time.replace(/^\d\d\d\d-(\d\d)[\s\S]+/,"$1");
var day = time.replace(/^\d\d\d\d-\d\d-(\d\d)[\s\S]+/,"$1");
var hours = time.replace(/[\s\S]+T(\d\d)[\s\S]+/,"$1");
var minutes = time.replace(/[\s\S]+T\d\d:(\d\d)[\s\S]+/,"$1");
date.setUTCFullYear(year,month-1,day);
date.setUTCHours(hours,minutes);
var dateRevision = (date.getFullYear()*10000) + ((date.getMonth()+1)*100) + date.getDate();
if (dateRevision < dateControl) {
var divNodeDate = revContent.appendChild(document.createElement("div"));
divNodeDate.style.fontSize = "95%";
divNodeDate.style.marginTop = ".3em";
divNodeDate.style.fontWeight = "bold";
divNodeDate.style.paddingLeft = ".5em";
divNodeDate.innerHTML = date.getDate() + " " + monthName[date.getMonth()];
if (dateNow - dateRevision > 10000) divNodeDate.innerHTML += " " + date.getFullYear();
dateControl = dateRevision;
}
var divNode = revContent.appendChild(document.createElement("div"));
divNode.style.marginLeft = "1em";
divNode.style.textIndent = "-1em";
divNode.style.fontSize = "95%";
divNode.style.marginTop = ".3em";
var aNodeTime = divNode.appendChild(document.createElement("a"));
aNodeTime.innerHTML = (date.getHours() < 10) ? "0" + date.getHours() : date.getHours();
aNodeTime.innerHTML += ":";
aNodeTime.innerHTML += (date.getMinutes() < 10) ? "0" + date.getMinutes() : date.getMinutes();
aNodeTime.style.fontSize = "90%";
var revid = rev[i].getAttribute("revid");
aNodeTime.href = "javascript:mostraModificheLoadDiff("+revid+",'prev')";
aNodeTime.title = timeTitle;
divNode.appendChild(document.createTextNode(" "));
var aNodeUser = divNode.appendChild(document.createElement("a"));
aNodeUser.innerHTML = rev[i].getAttribute("user");
var anchorURL = rev[i].getAttribute("comment");
if (anchorURL == null) anchorURL = "";
aNodeUser.title = anchorURL;
// convert comment into a usable anchor link
if (anchorURL.search(/\/\*\s([\s\S]+)\s\*\/[\s\S]*/) != -1) {
var reg = [ [/\/\*\s([\s\S]+)\s\*\/[\s\S]*/,"$1"], [/\[\[[\s\S]*\|([\s\S]+)\]\]/g,"$1"],
[/\[\[\:?([\s\S]+)\]\]/g,"$1"], [/\s/g,"_"] ];
for (x = 0; x < reg.length; x++) {
anchorURL = anchorURL.replace(reg[x][0],reg[x][1]); }
anchorURL = encodeURIComponent(anchorURL);
var reg = [ [/%/g,"."], [/\(/g,".28"], [/\)/g,".29"], [/\!/g,".21"],
[/\'/g,".27"], [/\*/g,".2A"], [/.3A/g,":"] ];
for (x = 0; x < reg.length; x++) {
anchorURL = anchorURL.replace(reg[x][0],reg[x][1]); }
} else {
anchorURL = ""; }
aNodeUser.href = document.location.href + "#" + anchorURL;
aNodeUser.href = aNodeUser.href.replace(/##/,"#");
}
}
function processReq()
{
if (apiReq.readyState != 4) return;
if (apiReq.status != 200) return;
var xmlFile = apiReq.responseXML.documentElement;
var rev = xmlFile.getElementsByTagName("rev");
if (rev.length > 0) writeResults(rev);
queryContinue = xmlFile.getElementsByTagName("query-continue")[0];
if (queryContinue) {
rvStartId = queryContinue.getElementsByTagName("revisions")[0].getAttribute("rvstartid");
nextRevisions();
}
}
function loadXMLDoc()
{
var url = "/w/api.php?action=query&rawcontinue=&prop=revisions&format=xml";
url += "&titles=" + wgPageName + "&rvprop=ids|timestamp|user|comment";
url += "&rvlimit=" + revCount;
if (rvStartId != 0) url += "&rvstartid=" + rvStartId;
if (window.XMLHttpRequest) { // native XMLHttpRequest
apiReq = new XMLHttpRequest();
apiReq.onreadystatechange = processReq;
apiReq.open("GET", url, true);
apiReq.send(null);
} else if (window.ActiveXObject) { // activeX version
apiReq = new ActiveXObject("Microsoft.XMLHTTP");
if (apiReq) {
apiReq.onreadystatechange = processReq;
apiReq.open("GET", url, true);
apiReq.send("");
}
}
}
function recentRevisions()
{
var revContent = document.getElementById("recRevContent");
if (revContent) { // when pressed the close button
revContent.innerHTML = "";
rvStartId = 0;
dateControl = 99999999;
} else {
var navigationBox = document.getElementById('p-navigation');
var revBox = document.createElement("div");
var revBox = navigationBox.parentNode.insertBefore(document.createElement("div"),navigationBox);
revBox.id = "p-rev";
revBox.className = "portlet";
var h3Node = revBox.appendChild(document.createElement("h3"));
h3Node.innerHTML = revBoxTitle;
revContent = revBox.appendChild(document.createElement("div"));
revContent.id = "recRevContent";
revContent.className = "pBody";
revContent.style.padding = "0 .3em .3em .3em";
revContent.style.lineHeight = "1.2em";
revContent.style.fontFamily = "Verdana, sans-serif";
}
var divNode = revContent.appendChild(document.createElement("div"));
divNode.id = "showButton";
divNode.style.textAlign = "center";
var button = divNode.appendChild(document.createElement("button"));
button.innerHTML = buttonBeginText;
button.onclick = loadXMLDoc;
button.style.fontSize = "90%";
button.style.marginTop = ".3em";
button.style.padding = "0";
}
var diffReq;
var apiReq;
var rvStartId = 0;
var revCount = 20; // max 50, higher numbers not possible, they give an error
var dateControl = 99999999; // must only be higher than today (yyyymmdd)
var timeTitle = "Modifiche rispetto alla versione precedente";
var closeButtonTitle = "Chiudi";
var revBoxTitle = "";
var buttonBeginText = "modifiche recenti";
var buttonNextText = "Successive " + revCount;
var buttonNextTitle = "Mostra le successive "+revCount+" revisioni";
var monthName = ["gennaio", "febbraio", "marzo", "aprile", "maggio", "giugno", "luglio",
"agosto", "settembre", "ottobre", "novembre", "dicembre"];
mw.util.addCSS('table.diff td {vertical-align:top;}');
mw.loader.load('mediawiki.action.history.diff');
if (wgNamespaceNumber != -1)
addOnloadHook(recentRevisions);
//