MediaWiki

Gadget-statistics.js

From Dogcraft Wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (โŒ˜-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (โŒ˜-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
$(document).ready(function() {

/*function uecGetEditCount() {
	
	var params2 = {
        action: 'query',
        format: 'json',
        list: 'allusers',
        aulimit: 10,
        auprop: 'editcount'
	},
	uecData = "";
	//var api2 = new mw.Api();
    uecData += "ab";
    
    api.get( params2 ).done( function uecCallAPI ( data ) 
	{
		var users2 = data.query.allusers,
        	u2;
        
    //if (uecMode == "table")
    //{
    	for ( u2 in users2 ) {
        	uecData += '{{!}}-\n{{!}}' + users2[u2].name + '{{!!}}' + users2[u2].editcount + '\n{{!}}-\n';
    	}
    //}
    //else if (uecMode == "single")
    //{
    //	for ( u in users ) {
    //    	uecData += '|users[u].name = users[u].editcount \n';
    //	}
    //}
    //else if (uecMode == "raw")
    //{
    //	for ( u in users ) {
    //    	uecData += 'users[u].name   users[u].editcount\n';
    //	}
    //}
    
	});
	
	return uecData;	
}*/

function testAPIEdit() {
	
	api = new mw.Api();
	
	var params2 = {
        action: 'query',
        format: 'json',
        list: 'allusers',
        aulimit: 100,
        auprop: 'editcount'
	},
	uecTableData = "",
	uecSingleData = "",
	uecRawData = "";
	
	api.get( params2 ).done( function ( uecdata ) 
	{
		var users = uecdata.query.allusers,
        	u;
        	
        for ( u in users ) {
        	uecTableData += '{{!}}-\n{{!}}' + users[u].name + '{{!!}}' + users[u].editcount + '\n{{!}}-\n';
    	}
    	
    	for ( u in users ) {
        	uecSingleData += '|' + users[u].name + ' = ' + users[u].editcount + '\n';
    	}
    	
    	for ( u in users ) {
        	uecRawData += " " + users[u].name + "   " + users[u].editcount + '\n';
    	}
    	
    	var templateNoInclude = '<noinclude>{{Gadget_EditCount_noinclude}}</noinclude>\n',
			templateSection1 = '<includeonly>{{Gadget_EditCount_Section1}}',
			templateSection1data = uecTableData,
			templateSection2 = '{{Gadget_EditCount_Section2}}',
			templateSection2data = uecSingleData,
			templateSection3 = '{{Gadget_EditCount_Section3}}',
			templateSection3data = uecRawData,
			templateSectionEnd = '{{Gadget_EditCount_SectionEnd}}',
			pagecontent = templateNoInclude + templateSection1 + templateSection1data + templateSection2 + templateSection2data + templateSection3 + templateSection3data + templateSectionEnd;
		
		
		var params = {
			action: 'edit',
			format: 'json',
			title: 'Template:EditCountMain',
			text: pagecontent,
			summary: 'Edit added with the API',
			bot : 1,
			
		};
	
		api.postWithToken( 'csrf', params );
        	
	});
	
	
	
	
	
} 

	document.getElementById('gadgetSandboxButton').innerHTML = "<div id='gadgetSandboxButtoninner'><button  type='button' style='background:blue;'>Press this to get editcounts</button></div>";
	document.getElementById('gadgetSandboxButton').onclick = function() {testAPIEdit()};
});
This page was last modified on 18 July 2020, at 21:32. (12 months ago)