User:Lady Whistler/Gadget-revisionCounter.js

//=========================================================================== // Fügt an den Reiter "Versionen/Autoren" die Anzahl Versionen an und die // Anzahl vom Nutzer erstellter Versionen //===========================================================================

var revisionCounter = { queryUrl           : mw.config.get( 'wgScriptPath' ) + '/api.php?action=query&prop=revisions&pageids=' + mw.config.get('wgArticleId') + '&rvprop=user&rvlimit=max&format=json&callback=revisionCounter.queryResult'+ '&nocache=' + mw.config.get('wgCurRevisionId'), //Break client caching, when page has been edited revisionCount     : 0, revisionCountUser : 0, checkOnlyOnHistory : true,

execute : function {   if ((revisionCounter.checkOnlyOnHistory) && (mw.config.get('wgAction') !== "history")) return; mw.loader.load(revisionCounter.queryUrl); },

queryResult : function(res) {   var pageId = mw.config.get('wgArticleId'); if (!res['query'] || !res['query']['pages'] ||        !res['query']['pages'][pageId] || !res['query']['pages'][pageId]['revisions']) return; var revs = res['query']['pages'][pageId]['revisions']; revisionCounter.revisionCount += revs.length; var username = mw.config.get( 'wgUserName' ); for (var i = 0; i < revs.length; i++) if (revs[i]['user'] === username) revisionCounter.revisionCountUser++; if (res && res['query-continue']) {     mw.loader.load(revisionCounter.queryUrl + '&rvcontinue=' + encodeURIComponent(res['query-continue'].revisions.rvcontinue)); }   else {     if (mw.config.get('skin') === 'vector') {       $("#ca-history a").text(function(index, curText) {          return curText + " (" + revisionCounter.revisionCount + "/" + revisionCounter.revisionCountUser + ")";        }); }     else {       var info = document.createElement("span"); info.appendChild(document.createTextNode(" (" + revisionCounter.revisionCount + "/" + revisionCounter.revisionCountUser + ")")); var infoTitle = document.createAttribute("title"); infoTitle.nodeValue = "Insgesamt " + revisionCounter.revisionCount + " Versionen, davon " + revisionCounter.revisionCountUser + " von mir"; info.setAttributeNode(infoTitle); document.getElementById('ca-history').firstChild.appendChild(info); }   }  } };

if (mw.config.get('wgNamespaceNumber') >= 0) addOnloadHook( revisionCounter.execute );