Gebruiker:Rots61/Gadget-EditCount.js: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
Regel 161: | Regel 161: | ||
var ECgebruikersnaam = document.getElementById("Gadget-EditCount-User").innerHTML; | var ECgebruikersnaam = document.getElementById("Gadget-EditCount-User").innerHTML; | ||
ECtemplate();} | ECtemplate();} | ||
+ | |||
+ | r61AddToSpecial('EditCount', 'WikiKids:Editcount', ["EditCount"]); |
Versie van 24 jan 2023 13:57
/**
* EDITCOUNT2.JS
*
* Features: [[WikiKids:EditCount]]
* Credits: [[WikiKids:EditCount#Dank]]
* Made by [[User:Rots61]]
**/
// Create a mw.Api instance to make API requests easier.
var api = new mw.Api();
function getEC() {
// Request the user's information from the API.
var ECgebruikersnaam = mw.util.getParamValue( 'user' );
api.get( {
action: 'query',
list: 'users',
usprop: 'blockinfo|editcount|gender',
ususers: ECgebruikersnaam,
} ).done( function ( query ) {
// When response arrives extract the information we need.
if(!query.query) { return; } // Suggested by Gary King to avoid JS errors --PS 2010-08-25
query = query.query;
var user, invalid, missing, editcount, blocked;
try {
user = query.users[0];
invalid = typeof user.invalid != "undefined";
missing = typeof user.missing != "undefined";
editcount = (typeof user.editcount == "number") ? user.editcount : null;
blocked = typeof user.blockedby != "undefined";
} catch(e) {
return; // Not much to do if the server is returning an error (e.g. if the username is malformed).
}
// Format the information for on-screen display
var statusText = "";
if (missing||invalid) {
statusText += "<i>" + ECgebruikersnaam + "</i> bestaat niet.";
} else {
statusText = "<a href=\"" + mw.config.get("wgScriptPath") + encodeURIComponent(mw.config.get("wgFormattedNamespaces")[2] + ":" + ECgebruikersnaam) + "\">" + ECgebruikersnaam + "</a> ";
}
if(blocked) {
statusText += "<a href=\"" + mw.config.get("wgScriptPath") +
"/index.php?title=Special:Log&page=" +
encodeURIComponent(mw.config.get("wgFormattedNamespaces")[2] + ":" + ECgebruikersnaam) +
"&type=block\">is geblokkeerd</a> en ";
}
// Edit count
if(editcount !== null) {
if (editcount === 1) {
statusText += " heeft 1 bewerking gedaan.";
} else {
statusText += " heeft " + editcount + " bewerkingen gedaan.";
}
}
document.getElementById("ECoutput").innerHTML = statusText;
});
// Get the number of articles made
getNewPageCount( ECgebruikersnaam ).then( function (ECarticlecount) {
var ECarticleoutput;
if (ECarticlecount === 0) {
ECarticleoutput = ECgebruikersnaam + " heeft 0 artikels gemaakt.";
} else if (ECarticlecount === 1) {
ECarticleoutput = ECgebruikersnaam + " heeft een artikel gemaakt.";
} else {
ECarticleoutput = ECgebruikersnaam + " heeft " + ECarticlecount + " artikels gemaakt.";
}
document.getElementById("ECarticleoutput").innerHTML = ECarticleoutput;
} );
}
function getNewPageCount( ECgebruikersnaam, apiContinue ) {
return api.get( {
action: "query",
list: "usercontribs",
ucprop: "timestamp",
uclimit: "500",
ucshow: "new",
ucnamespace: "0",
ucuser: ECgebruikersnaam,
uccontinue: apiContinue ? apiContinue.uccontinue : undefined
} ).then( function (data) {
if ( data.continue ) {
return getNewPageCount( ECgebruikersnaam, data.continue )
.then( function ( addedLength ) {
return addedLength + data.query.usercontribs.length;
} );
} else {
return data.query.usercontribs.length;
}
} );
}
function Button() {
var ECgebruikersnaam = document.getElementById('user').value ;
location.href = "https://wikikids.nl/Speciaal:Editcount?user=" + ECgebruikersnaam;
}
function ECtemplate() {
if (document.getElementById("Gadget-EditCount-Article").innerHTML === "Edits") {
ECtemplate2();
} else {
ECtemplateArticles();
}
}
function ECtemplateArticles() {
getNewPageCount( ECgebruikersnaam ).then( function (ECarticlecount) { // The new page count we got will be passed here.
document.getElementById("Gadget-EditCount-Output").innerHTML = ECarticlecount;
} );
}
function ECtemplate2() {
api.get( {
action: 'query',
list: 'users',
usprop: 'editcount',
ususers: ECgebruikersnaam,
} ).done( function ( query ) {
// When response arrives extract the information we need.
if(!query.query) { return; } // Suggested by Gary King to avoid JS errors --PS 2010-08-25
query = query.query;
var user, invalid, missing, editcount;
user = query.users[0];
invalid = typeof user.invalid != "undefined";
missing = typeof user.missing != "undefined";
editcount = (typeof user.editcount == "number") ? user.editcount : null;
var statusText;
// Edit count
if(editcount !== null) {
statusText = editcount ;
}
if (missing||invalid) {
statusText = "ERROR";
}
document.getElementById("Gadget-EditCount-Output").innerHTML = statusText;
});
}
function ECpage() {
var bodyContent = 'bodyContent';
document.getElementsByTagName("h1")[0].textContent = "EditCount";
document.title = "EditCount - WikiKids";
document.getElementById(bodyContent).innerHTML = '<form id="ECform" name="ECform">'
+ '<b>Bekijk hier hoeveel bewerkingen iemand heeft gedaan. En hoeveel artikels hij heeft gemaakt. <br>'
+ 'Druk op enter, om het aantal bewerkingen op te halen. Dit kan een paar seconden duren. </b></br>'
+ 'Gebruiker: '
+ '<input type="text" name="user" id="user" size="30"></textarea>'
+ '<button onclick="Button()">Gaan!</button>'
+ '</form><br><div id="ECoutput"></div><div id="ECarticleoutput"></div>';
if (document.location.href.indexOf('?user=') != -1) { getEC(); }
}
if(mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgTitle') === "Editcount" || mw.config.get('wgTitle') === "EditCount")
) {
$.when( $.ready, mw.loader.using(['mediawiki.util'])).done( ECpage );
} else if (document.getElementById("Gadget-EditCount-Disabled")) {
document.getElementById("Gadget-EditCount-Disabled").innerHTML = "";
var ECgebruikersnaam = document.getElementById("Gadget-EditCount-User").innerHTML;
ECtemplate();}
r61AddToSpecial('EditCount', 'WikiKids:Editcount', ["EditCount"]);