User:Mr.Z-man/delLog.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:Mr.Z-man/delLog. |
var delLog_logapi;
var delLog_loghtml;
var delLog_sysop = false;
var delLog_title = mw.config.get('wgPageName').replace(/_/g, ' ');
var delLog_timeformat;
function getLog() {
var url = mw.config.get('wgScriptPath') + '/api.php?action=query&list=logevents&letype=delete&letitle='+delLog_title+'&leprop=user|timestamp|comment&format=json&callback=delLog';
var scriptElem = document.createElement('script');
scriptElem.setAttribute('src',url);
scriptElem.setAttribute('type','text/javascript');
document.getElementsByTagName('head')[0].appendChild(scriptElem);
}
function delLog(obj) {
if(!obj['query'] || obj['query']['logevents'].length < 1) return
delLog_logapi = obj['query']['logevents'];
addPortletLink('p-cactions', 'javascript:showDelLog()', "Deletion log", "ca-dellog", "Show the deletion log for this page");
}
function showDelLog() {
if (mw.config.get('wgUserGroups').indexOf('sysop') != -1) {
delLog_sysop = true;
}
delLog_loghtml = '<ul>';
for (var i=0;i<delLog_logapi.length;i++) {
time = timestampPref(delLog_logapi[i].timestamp);
comment = '';
if (typeof(delLog_logapi[i].comment) != "undefined") {
comment = commentlinker(delLog_logapi[i].comment);
}
user = userlinker(delLog_logapi[i].user);
addEntry(time, comment, user);
}
delLog_loghtml += '</ul>';
jsMsg(delLog_loghtml);
}
function addEntry(time, comment, user) {
action = ' deleted ';
if (comment.search(/\d (file|revision).{0,3} restored/i) != -1) {
action = ' restored ';
}
entry = "<li>"+
time + ' ' + user + action +
'<a href="/wiki/'+encodeURIComponent(delLog_title)+'" title="'+delLog_title+'">'+delLog_title+'</a>';
if (comment != '') {
entry +=' <span class="comment">('+
comment + ')</span>';
}
if (delLog_sysop) {
entry += ' (<a href="/w/index.php?title=Special:Undelete&target='+encodeURIComponent(delLog_title)+'" title="Special:Undelete">restore</a>)';
}
entry += '</li>';
delLog_loghtml += entry;
}
function commentlinker(text) {
text = text.replace(/</g, "<");
text = text.replace(/>/g, ">");
var pattern1 = /\[\[(.+?)\|(.+?)\]\]/g;
var pattern2 = /\[\[(.+?)\]\]/g;
result = text.replace(pattern1, "<a href=\"/wiki/$1\" title=\"$1\">$2</a>");
result = result.replace(pattern2, "<a href=\"/wiki/$1\" title=\"$1\">$1</a>");
return result;
}
function userlinker(user) {
encodeduser = encodeURIComponent(user);
userlink = '<a href="/wiki/User:'+encodeduser+'" title="User:'+user+'">'+user+'</a> (<a href="/wiki/User_talk:'+encodeduser+'" title="User talk:'+user+'">Talk</a> | <a href="/wiki/Special:Contributions/'+encodeduser+'" title="Special:Contributions/'+user+'">contribs</a>';
if (delLog_sysop) {
userlink+= ' | <a href="/wiki/Special:BlockIP/'+encodeduser+'" title="Special:BlockIP/'+user+'">block</a>';
}
userlink+= ')';
return userlink;
}
function timestampPref(time) {
var patt = /(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d):(\d\d)Z/
var month = time.replace(patt, "$2")
switch (month) {
case "01":
month = "January";
break;
case "02":
month = "February";
break;
case "03":
month = "March";
break;
case "04":
month = "April";
break;
case "05":
month = "May";
break;
case "06":
month = "June";
break;
case "07":
month = "July";
break;
case "08":
month = "August";
break;
case "09":
month = "September";
break;
case "10":
month = "October";
break;
case "11":
month = "November";
break;
case "12":
month = "December";
break;
default:
month = "Error";
}
if (!delLog_timeformat) {
delLog_timeformat = 1; }
switch (delLog_timeformat) {
case 1:
time = time.replace(patt, "$4:$5, " + month + " $3, $1");
break;
case 2:
time = time.replace(patt, "$4:$5, $3 " + month + " $1");
break;
case 3:
time = time.replace(patt, "$4:$5, $1 " + month + " $3");
break;
case 4:
time = time.replace(patt, "$1-$2-$3T$4:$5:$6");
break;
default:
time = time;
}
return time;
}
if (mw.config.get('wgNamespaceNumber') == 0) {
addOnloadHook(getLog);
}