User:Cynical/diffsince.js
// [[User:Quarl/diffsince.js]] - utility functions for doing a "diff since I
// last edited"
// depends: wikipage.js, util.js
// Synopsis:
// url = diffsince.makeUrl(wikiPage);
// href = '<a onclick="javascript:diffsince.diffThis()" href="'+url+'">diff since</a>';
// Or:
// url = diffsince.makeUrl(wp);
// href = '<a onclick="javascript:diffsince.diffPageAsync(wp)" href="'+url+'">diff since</a>';
// Navigating to the value of makeUrl will open a history page, parse it, and
// jump to the appropriate diff.
// The diffPageAsync() function asynchronously downloads the history page and
// then navigates to the diff. It is appropriate as an onClick handler.
// The diffThis() function does the diff directly if already looking at a
// history page, else calls diffPageAsync(wikiPage).
// diffPageAsync and diffThis take status_node and status_text parameters for
// showing progress.
// quarl 2006-01-16 (asynchronous code originally written in show_diff_since.js)
// quarl 2006-02-03 factored as library
// <pre><nowiki>
var diffsince = new Object();
diffsince.historyLimit = [200];
// return a URL that points to a "fakeaction" page for doing a diff.
diffsince.makeUrl = function(wp) {
return wp.qurl + '&fakeaction=diffsince&action=history&limit='+diffsince.historyLimit[0];
}
diffsince._load = function() {
if (WikiPage.queryVars.fakeaction == 'diffsince') {
diffsince._parseHistory(document);
}
}
diffsince.diffPageAsync = function(wp, statusNode, statusText) {
var url = wp.qurl + '&action=history&limit='+diffsince.historyLimit[0];
var req = new XMLHttpRequest();
// change the button to show the user we're doing something and
// prevent another click
buttonShowStatus(statusNode, statusText); // (statusNode, statusText are optional)
asyncDownloadXML(url, diffsince._handleHistoryPage,
{ statusNode: statusNode });
return false;
}
diffsince.diffThis = function(statusNode, statusText) {
if (wikiDoc.historyP) {
// already looking at a history page
diffsince._parseHistory(document);
} else {
// not yet a history page -- asynchronously download it first
diffsince.diffPageAsync(wikiPage, statusNode, statusText);
}
return false;
}
diffsince._handleHistoryPage = function(req) {
// restore button in case this fails, so user can click again
buttonRestoreStatus(req.statusNode);
if (req.status == 200) {
diffsince._parseHistory(req.responseXML);
} else {
alert("Error downloading history page!");
}
}
diffsince._parseHistory = function(doc) {
if (!doc) { alert ("## no doc?!"); return; }
var hists = doc.getElementById("pagehistory").childNodes;
if (!hists) { alert("Couldn't parse history from page"); return; }
for (n=0;n<hists.length;n++) {
// window.username is defined in wikipage.js
if (hists[n].getElementsByTagName &&
hists[n].getElementsByTagName("span")[0].textContent==wikiDoc.username)
{
document.location = hists[n].childNodes[1].href;
return;
}
}
alert("diffsince: Couldn't find your entry in the history page; you haven't edited recently!");
// TODO: retry with a larger limit
}
addOnloadHook(diffsince._load);
// </nowiki></pre>
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.