Langbahn Team – Weltmeisterschaft

User:Wurgl/WikiHistory.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.
// <nowiki>
var authors = {
  queryPageProps : {
    action: 'query',
    prop: 'pageprops',
    ppprop: 'newsectionlink',
    pageids: mw.config.get('wgArticleId'),
  },
  api : 0,
  loadinganimation : 0,

  execute : function() {
    var ns = mw.config.get('wgNamespaceNumber');
    if(ns % 2 != 0 || ns == 2 || ns == 710)
      return;
    authors.api = new mw.Api();
    authors.queryNewSectionLink(authors.api, authors.compute, authors.queryPageProps);
  },
  queryNewSectionLink : function(api, callback, queryParams) {
    api.get($.extend({}, queryParams, { 'continue': '' })).then(function(data) {
      callback(data);
    }).fail(function(code, data) {
      var extraText;
      if(code === 'http' && data) {
        extraText = (data.xhr && data.xhr.status ? '[' + data.xhr.status + ']' : '') +
                    (data.textStatus ? '' + data.textStatus + (data.exception ? ': ' : '') : '') +
                    (data.exception ? '' + data.exception : '');
      }
      else {
        extraText = code + (data && data.error && data.error.info ? ': ' + data.error.info : '');
      }
      mw.notify('WikiHistory: error reading page properties (' + extraText + ')', {tag: 'WikiHistory-error'});
    });
  },
  compute : function(data) {
    var pages = data.query.pages;
    for(var p in pages) {
      if(pages[p].pageprops && pages[p].pageprops.newsectionlink == '')
        return;
    }
    if(mw.config.get('wgArticleId') == 0)
      return; // no deleted articles
    if(mw.config.get('wgRevisionId') != 0 && mw.config.get('wgCurRevisionId') != mw.config.get('wgRevisionId'))
      return; // only current revision
    $("<div id='authors' style='font-size:84%; line-height:1.2em; margin:0 0 0 1em; width:auto;'>authors are <span id='authorsresult'></span><span id='authorsloading'>...</span></div>").insertBefore(document.getElementById("contentSub") || document.getElementById("mw-content-text"));
    loadinganimation = window.setInterval( function() { if ($("#authorsloading").html() == ".&nbsp;&nbsp;") $("#authorsloading").html("&nbsp;.&nbsp;"); else if ($("#authorsloading").html() == "&nbsp;.&nbsp;") $("#authorsloading").html("&nbsp;&nbsp;."); else $("#authorsloading").html(".&nbsp;&nbsp;"); }, 300);
    mw.loader.load("//wikihistory.toolforge.org/wiki/getauthors.php?wiki=" + window.location.hostname.split(".", 1)[0] + "wiki&page_id=" +  mw.config.get('wgArticleId'));
  },
  resultloaded : function(res, old) {
    $("#authorsresult").html(res);
    if(old == 1)
      mw.loader.load("//wikihistory.toolforge.org/wiki/getauthors.php?wiki=" + window.location.hostname.split(".", 1)[0] + "wiki&page_id=" +  mw.config.get('wgArticleId') + '&onlynew=1');
  },
  stoploading : function() {
    clearInterval(loadinganimation);
    $('#authorsloading').remove();
  }
};
if((typeof WikiHistory === 'undefined' || WikiHistory == "all" || WikiHistory == "view") && mw.config.get('wgAction') == "view" ||
   (typeof WikiHistory !== 'undefined' && (WikiHistory == "all" || WikiHistory == "info")) && mw.config.get('wgAction') == "info")
  $(authors.execute);
// </nowiki>