Langbahn Team – Weltmeisterschaft

User:Mr.Z-man/delLog.js

Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
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, "&lt;");
  text = text.replace(/>/g, "&gt;");
  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);
}