User:Mr.Z-man/delLog.js

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 = ''; for (var i=0;i'; jsMsg(delLog_loghtml); }

function addEntry(time, comment, user) { action = ' deleted '; if (comment.search(/\d (file|revision).{0,3} restored/i) != -1) { action = ' restored '; } entry = ""+ time + ' ' + user + action + ''+delLog_title+''; if (comment != '') { entry +=' ('+     comment + ') '; } if (delLog_sysop) { entry += ' (restore)'; } entry += ''; delLog_loghtml += entry; }

function commentlinker(text) { text = text.replace(//g, "&gt;"); var pattern1 = /\[\[(.+?)\|(.+?)\]\]/g; var pattern2 = /\[\[(.+?)\]\]/g; result = text.replace(pattern1, "$2"); result = result.replace(pattern2, "$1"); return result; }

function userlinker(user) { encodeduser = encodeURIComponent(user); userlink = ''+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); }