MediaWiki:Gadget-EditCount2.js: verschil tussen versies

Uit Wikikids
Naar navigatie springen Naar zoeken springen
(Kleine fix voor het gebruik van de button)
Regel 6: Regel 6:
 
* But it doesn't really exist though
 
* But it doesn't really exist though
 
* Based on [[c:en:User:PleaseStand/userinfo.js]], [[c:en:User:Frietjes/masspurge.js]] and [[MediaWiki:Gadget-EditCount.js]]
 
* Based on [[c:en:User:PleaseStand/userinfo.js]], [[c:en:User:Frietjes/masspurge.js]] and [[MediaWiki:Gadget-EditCount.js]]
  +
* Thanks to [[c:en:User:Chlod]] for the repeating part.
 
* Made by [[User:Rots61]]
 
* Made by [[User:Rots61]]
 
**/
 
**/
  +
  +
const api = new mw.Api();
   
 
function getEC() {
 
function getEC() {
Regel 16: Regel 19:
 
ECgebruikersnaam = document.location.href.substring(document.location.href.indexOf('?user=')+6, document.location.href.length);}
 
ECgebruikersnaam = document.location.href.substring(document.location.href.indexOf('?user=')+6, document.location.href.length);}
 
else { ECgebruikersnaam = document.getElementById("user").value; }}
 
else { ECgebruikersnaam = document.getElementById("user").value; }}
  +
api.get( {
$.getJSON(mw.config.get("wgScriptPath") + "/api.php?format=json&action=query&list=users&usprop=blockinfo|editcount|gender&ususers=" + ECgebruikersnaam)
 
  +
action: 'query',
.done(function(query) {
 
  +
list: 'users',
  +
usprop: 'blockinfo|editcount|gender',
  +
ususers: ECgebruikersnaam,
 
} ).done( function ( query ) {
 
// When response arrives extract the information we need.
 
// When response arrives extract the information we need.
if(!query.query) { return; }
+
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, gender;
 
var user, invalid, missing, editcount, blocked, gender;
Regel 53: Regel 60:
 
document.getElementById("ECoutput").innerHTML = statusText;
 
document.getElementById("ECoutput").innerHTML = statusText;
 
});
 
});
  +
getNewPageCount( ECgebruikersnaam ).then( (ECarticlecount) => { // The new page count we got will be passed here.
$.getJSON(mw.config.get("wgScriptPath") + "/api.php?action=query&format=json&list=usercontribs&ucprop=timestamp&uclimit=5000&ucshow=new&ucnamespace=0&ucuser=" + ECgebruikersnaam)
 
 
document.getElementById("ECarticleoutput").innerHTML =
.done(function(query) {
 
  +
ECgebruikersnaam + " heeft " + ECarticlecount + " artikels aangemaakt.";
query = query.query;
 
 
} );
var ECarticlecount = query.usercontribs.length;
 
  +
}
document.getElementById("ECarticleoutput").innerHTML = ECgebruikersnaam + " heeft " + ECarticlecount + " artikels aangemaakt.";
 
  +
});
 
  +
function getNewPageCount( ECgebruikersnaam ) {
  +
// Create a promise that resolves with the new page count.
  +
return new Promise( async (res) => {
  +
// Set up persistent variables.
  +
var apiContinue = {};
  +
var ECarticlecount = 0;
  +
// `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
  +
const query = await api.get({
  +
action: "query",
  +
list: "usercontribs",
  +
ucprop: "timestamp",
  +
uclimit: "500",
  +
ucshow: "new",
  +
ucnamespace: "0",
  +
ucuser: ECgebruikersnaam,
  +
// This passes anything we find in `query.continue` into the next request,
  +
// so that we keep requesting *new* data instead of previous data.
  +
...apiContinue
  +
});
  +
  +
// Add the contributions we find into the count.
 
ECarticlecount += query.query.usercontribs.length;
  +
// Set `apiContinue`. This will also set it to `undefined` if there's nothing left.
  +
apiContinue = query.continue;
  +
}
  +
  +
// Give the number of articles made afterwards. You'll get to use this later.
  +
res(ECarticlecount);
  +
} );
 
}
 
}
   
 
function Button() {
 
function Button() {
 
var ECgebruikersnaam = document.getElementById('user').value ;
 
var ECgebruikersnaam = document.getElementById('user').value ;
location.href = "https://wikikids.nl/Speciaal:Editcount?user=" + ECgebruikersnaam;
+
location.href = "https://wikikids.nl/Speciaal:Editcount2?user=" + ECgebruikersnaam;
 
}
 
}
   
Regel 79: Regel 118:
 
}
 
}
   
if(mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgTitle') === "Editcount" || mw.config.get('wgTitle') === "EditCount")
+
if(mw.config.get('wgNamespaceNumber') === -1 && (mw.config.get('wgTitle') === "Editcount2" || mw.config.get('wgTitle') === "EditCount2")
 
) {
 
) {
 
$.when( $.ready, mw.loader.using(['mediawiki.util'])).done( ECpage );
 
$.when( $.ready, mw.loader.using(['mediawiki.util'])).done( ECpage );

Versie van 5 dec 2022 20:46

/**
 * EDITCOUNT.JS
 *
 * Loads the editcount for users
 * 'Adds' special page [[Speciaal:EditCount]]
 * But it doesn't really exist though
 * Based on [[c:en:User:PleaseStand/userinfo.js]], [[c:en:User:Frietjes/masspurge.js]] and [[MediaWiki:Gadget-EditCount.js]]
 * Thanks to [[c:en:User:Chlod]] for the repeating part. 
 * Made by [[User:Rots61]] 
**/

const api = new mw.Api();

function getEC() {
		// Request the user's information from the API.
		var ECgebruikersnaam = "";
		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( {
		    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, gender;
			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";
				gender = (typeof user.gender == "string") ? user.gender : null;
			 } 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&amp;page=" + 
					encodeURIComponent(mw.config.get("wgFormattedNamespaces")[2] + ":" + ECgebruikersnaam) +
					"&amp;type=block\">is geblokkeerd</a> en ";
			}
			// Edit count
			if(editcount !== null) {
				statusText += " heeft " + editcount + " bewerkingen gedaan.";
			}
			document.getElementById("ECoutput").innerHTML = statusText;
		});
		getNewPageCount( ECgebruikersnaam ).then( (ECarticlecount) => { // The new page count we got will be passed here.
		    document.getElementById("ECarticleoutput").innerHTML = 
		        ECgebruikersnaam + " heeft " + ECarticlecount + " artikels aangemaakt.";
		} );
}

function getNewPageCount( ECgebruikersnaam ) {
    // Create a promise that resolves with the new page count.
    return new Promise( async (res) => {
        // Set up persistent variables.
        var apiContinue = {};
        var ECarticlecount = 0;
        // `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
            const query = await api.get({
                action: "query",
                list: "usercontribs",
                ucprop: "timestamp",
                uclimit: "500",
                ucshow: "new",
                ucnamespace: "0",
                ucuser: ECgebruikersnaam,
                // This passes anything we find in `query.continue` into the next request,
                // so that we keep requesting *new* data instead of previous data.
                ...apiContinue
            });
            
            // Add the contributions we find into the count.
            ECarticlecount += query.query.usercontribs.length;
            // Set `apiContinue`. This will also set it to `undefined` if there's nothing left.
            apiContinue = query.continue;
        }
        
        // Give the number of articles made afterwards. You'll get to use this later.
        res(ECarticlecount);
    } );
}

function Button() {
        var ECgebruikersnaam = document.getElementById('user').value ;
        location.href = "https://wikikids.nl/Speciaal:Editcount2?user=" + ECgebruikersnaam;
}

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. Druk op enter, om het aantal bewerkingen op te halen.</b></br>'
	+ 'Vul hier de naam in: '
	+ '<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') === "Editcount2" || mw.config.get('wgTitle') === "EditCount2")
) {
	$.when( $.ready, mw.loader.using(['mediawiki.util'])).done( ECpage );
}
Afkomstig van Wikikids , de interactieve Nederlandstalige Internet-encyclopedie voor en door kinderen. "https://wikikids.nl/index.php?title=MediaWiki:Gadget-EditCount2.js&oldid=751811"