Gebruiker:Rots61/Gadget-EditCount.js: verschil tussen versies
Naar navigatie springen
Naar zoeken springen
(12 tussenliggende versies door dezelfde gebruiker niet weergegeven) | |||
Regel 3: | Regel 3: | ||
* |
* |
||
* Features: [[WikiKids:EditCount]] |
* Features: [[WikiKids:EditCount]] |
||
+ | * Credits: [[WikiKids:EditCount#Dank]] |
||
* Made by [[User:Rots61]] |
* Made by [[User:Rots61]] |
||
**/ |
**/ |
||
+ | // Create a mw.Api instance to make API requests easier. |
||
− | + | var api = new mw.Api(); |
|
function getEC() { |
function getEC() { |
||
// Request the user's information from the API. |
// Request the user's information from the API. |
||
− | var ECgebruikersnaam = |
+ | var ECgebruikersnaam = mw.util.getParamValue( 'user' ); |
− | if (document.getElementById("user").value.length == 0) { |
||
− | if (document.location.href.indexOf('?user=') != -1) { |
||
− | ECgebruikersnaam = document.location.href.substring(document.location.href.indexOf('?user=')+6, document.location.href.length);} |
||
− | else { ECgebruikersnaam = document.getElementById("user").value; }} |
||
api.get( { |
api.get( { |
||
action: 'query', |
action: 'query', |
||
Regel 24: | Regel 22: | ||
if(!query.query) { return; } // Suggested by Gary King to avoid JS errors --PS 2010-08-25 |
if(!query.query) { return; } // Suggested by Gary King to avoid JS errors --PS 2010-08-25 |
||
query = query.query; |
query = query.query; |
||
− | var user, invalid, missing, editcount, blocked |
+ | var user, invalid, missing, editcount, blocked; |
try { |
try { |
||
user = query.users[0]; |
user = query.users[0]; |
||
Regel 31: | Regel 29: | ||
editcount = (typeof user.editcount == "number") ? user.editcount : null; |
editcount = (typeof user.editcount == "number") ? user.editcount : null; |
||
blocked = typeof user.blockedby != "undefined"; |
blocked = typeof user.blockedby != "undefined"; |
||
− | gender = (typeof user.gender == "string") ? user.gender : null; |
||
} catch(e) { |
} catch(e) { |
||
return; // Not much to do if the server is returning an error (e.g. if the username is malformed). |
return; // Not much to do if the server is returning an error (e.g. if the username is malformed). |
||
Regel 52: | Regel 49: | ||
// Edit count |
// Edit count |
||
if(editcount !== null) { |
if(editcount !== null) { |
||
− | + | if (editcount === 1) { |
|
+ | statusText += " heeft 1 bewerking gedaan."; |
||
+ | } else { |
||
+ | statusText += " heeft " + editcount + " bewerkingen gedaan."; |
||
⚫ | |||
} |
} |
||
document.getElementById("ECoutput").innerHTML = statusText; |
document.getElementById("ECoutput").innerHTML = statusText; |
||
}); |
}); |
||
+ | // Get the number of articles made |
||
⚫ | |||
+ | getNewPageCount( ECgebruikersnaam ).then( function (ECarticlecount) { |
||
+ | var ECarticleoutput; |
||
+ | if (ECarticlecount === 0) { |
||
⚫ | |||
+ | } else if (ECarticlecount === 1) { |
||
+ | ECarticleoutput = ECgebruikersnaam + " heeft een artikel gemaakt."; |
||
+ | } else { |
||
+ | ECarticleoutput = ECgebruikersnaam + " heeft " + ECarticlecount + " artikels gemaakt."; |
||
+ | } |
||
⚫ | |||
+ | } ); |
||
} |
} |
||
− | function getNewPageCount( ECgebruikersnaam ) { |
+ | function getNewPageCount( ECgebruikersnaam, apiContinue ) { |
+ | return api.get( { |
||
− | var apiContinue = {}; |
||
− | + | action: "query", |
|
⚫ | |||
− | // 'apiContinue' ('query.continue') becomes 'undefined' if there is nothing left |
||
⚫ | |||
− | // to query, so we'll check for this condition and stop when that happens. |
||
⚫ | |||
− | while (apiContinue !== undefined) { |
||
⚫ | |||
− | // Check for user contributions |
||
+ | ucnamespace: "0", |
||
− | const query = api.get({ |
||
− | + | ucuser: ECgebruikersnaam, |
|
+ | uccontinue: apiContinue ? apiContinue.uccontinue : undefined |
||
⚫ | |||
+ | } ).then( function (data) { |
||
⚫ | |||
− | + | if ( data.continue ) { |
|
⚫ | |||
⚫ | |||
− | + | .then( function ( addedLength ) { |
|
− | + | return addedLength + data.query.usercontribs.length; |
|
− | + | } ); |
|
− | + | } else { |
|
⚫ | |||
− | // This passes anything we find in 'query.continue' into the next request, |
||
− | // so that we keep requesting *new* data instead of previous data. |
||
⚫ | |||
− | |||
− | // Add the contributions we find into the count. |
||
⚫ | |||
− | // Set 'apiContinue'. This will also set it to 'undefined' if there's nothing left. |
||
− | apiContinue = query.continue; |
||
} |
} |
||
− | + | } ); |
|
+ | } |
||
⚫ | |||
− | } |
||
function Button() { |
function Button() { |
||
var ECgebruikersnaam = document.getElementById('user').value ; |
var ECgebruikersnaam = document.getElementById('user').value ; |
||
− | location.href = "https://wikikids.nl/Speciaal: |
+ | location.href = "https://wikikids.nl/Speciaal:Editcount?user=" + ECgebruikersnaam; |
} |
} |
||
− | function |
+ | function ECtemplate(nr) { |
− | + | if (sjabloonClassEC[nr].getElementsByClassName("Gadget-EditCount-Article")[0].innerHTML === "Edits") { |
|
+ | ECtemplate2(nr); |
||
+ | } else { |
||
+ | ECtemplateArticles(nr); |
||
+ | } |
||
+ | } |
||
+ | |||
+ | function ECtemplateArticles(nr) { |
||
+ | getNewPageCount( ECgebruikersnaam[nr] ).then( function (ECarticlecount) { // The new page count we got will be passed here. |
||
+ | sjabloonClassEC[nr].getElementsByClassName("Gadget-EditCount-Output")[0].innerHTML = ECarticlecount; |
||
+ | } ); |
||
+ | } |
||
+ | |||
+ | function ECtemplate2(nr) { |
||
api.get( { |
api.get( { |
||
action: 'query', |
action: 'query', |
||
list: 'users', |
list: 'users', |
||
usprop: 'editcount', |
usprop: 'editcount', |
||
− | ususers: ECgebruikersnaam, |
+ | ususers: ECgebruikersnaam[nr], |
} ).done( function ( query ) { |
} ).done( function ( query ) { |
||
// When response arrives extract the information we need. |
// When response arrives extract the information we need. |
||
Regel 111: | Regel 128: | ||
editcount = (typeof user.editcount == "number") ? user.editcount : null; |
editcount = (typeof user.editcount == "number") ? user.editcount : null; |
||
var statusText; |
var statusText; |
||
⚫ | |||
// Edit count |
// Edit count |
||
if(editcount !== null) { |
if(editcount !== null) { |
||
− | statusText = editcount |
+ | statusText = editcount; |
} |
} |
||
if (missing||invalid) { |
if (missing||invalid) { |
||
statusText = "ERROR"; |
statusText = "ERROR"; |
||
+ | } |
||
⚫ | |||
+ | sjabloonClassEC[nr].getElementsByClassName("Gadget-EditCount-Output")[0].innerHTML = statusText; |
||
}); |
}); |
||
} |
} |
||
Regel 127: | Regel 144: | ||
document.title = "EditCount - WikiKids"; |
document.title = "EditCount - WikiKids"; |
||
document.getElementById(bodyContent).innerHTML = '<form id="ECform" name="ECform">' |
document.getElementById(bodyContent).innerHTML = '<form id="ECform" name="ECform">' |
||
− | + '<b>Bekijk hier hoeveel bewerkingen iemand heeft gedaan. En hoeveel |
+ | + '<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>' |
+ | + '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>' |
+ '<input type="text" name="user" id="user" size="30"></textarea>' |
||
+ '<button onclick="Button()">Gaan!</button>' |
+ '<button onclick="Button()">Gaan!</button>' |
||
Regel 139: | Regel 156: | ||
) { |
) { |
||
$.when( $.ready, mw.loader.using(['mediawiki.util'])).done( ECpage ); |
$.when( $.ready, mw.loader.using(['mediawiki.util'])).done( ECpage ); |
||
− | } else if (document. |
+ | } else if (document.getElementsByClassName("Gadget-EditCount-Sjabloon").length) { |
+ | var sjabloonClassEC = document.getElementsByClassName("Gadget-EditCount-Sjabloon"); |
||
− | document.getElementById("DisabledEditCount").innerHTML = ""; |
||
+ | var aantalKeerSjabloonEC = sjabloonClassEC.length; |
||
− | ECsjabloon();} |
||
+ | var ECgebruikersnaam = []; |
||
+ | for (var x = 0; x < aantalKeerSjabloonEC; x++) { |
||
+ | sjabloonClassEC[x].getElementsByClassName("Gadget-EditCount-Disabled")[0].style.display = "none"; |
||
+ | ECgebruikersnaam[x] = sjabloonClassEC[x].getElementsByClassName('Gadget-EditCount-User')[0].innerHTML; |
||
+ | ECtemplate(x); |
||
+ | } |
||
+ | } |
Huidige versie van 19 aug 2023 om 19:49
/**
* 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(nr) {
if (sjabloonClassEC[nr].getElementsByClassName("Gadget-EditCount-Article")[0].innerHTML === "Edits") {
ECtemplate2(nr);
} else {
ECtemplateArticles(nr);
}
}
function ECtemplateArticles(nr) {
getNewPageCount( ECgebruikersnaam[nr] ).then( function (ECarticlecount) { // The new page count we got will be passed here.
sjabloonClassEC[nr].getElementsByClassName("Gadget-EditCount-Output")[0].innerHTML = ECarticlecount;
} );
}
function ECtemplate2(nr) {
api.get( {
action: 'query',
list: 'users',
usprop: 'editcount',
ususers: ECgebruikersnaam[nr],
} ).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";
}
sjabloonClassEC[nr].getElementsByClassName("Gadget-EditCount-Output")[0].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.getElementsByClassName("Gadget-EditCount-Sjabloon").length) {
var sjabloonClassEC = document.getElementsByClassName("Gadget-EditCount-Sjabloon");
var aantalKeerSjabloonEC = sjabloonClassEC.length;
var ECgebruikersnaam = [];
for (var x = 0; x < aantalKeerSjabloonEC; x++) {
sjabloonClassEC[x].getElementsByClassName("Gadget-EditCount-Disabled")[0].style.display = "none";
ECgebruikersnaam[x] = sjabloonClassEC[x].getElementsByClassName('Gadget-EditCount-User')[0].innerHTML;
ECtemplate(x);
}
}