mNo edit summary |
m (i give up :( this one is probably broken too) |
||
Line 10: | Line 10: | ||
/* source: [[User:Ultradude25/editcounter.js]] */ |
/* source: [[User:Ultradude25/editcounter.js]] */ |
||
/* Note from Kanegasi: */ |
/* Note from Kanegasi: */ |
||
− | /* THIS VERSION HERE IS |
+ | /* THIS VERSION HERE IS SPECIFIC TO ME. DO NOT USE UNLESS YOU KNOW WHAT TO CHANGE! */ |
/***********************************************************************************/ |
/***********************************************************************************/ |
||
− | $(document).ready(function |
+ | $(document).ready(function() { |
+ | |||
− | // Add "Edit counter" link in Toolbox |
||
+ | // Add a new link after "User contributions" in the toolbox |
||
− | var $editCountLink = $('<a>Edit counter</a>').attr({ id: 't-editcounter', href: '#', title: 'Run edit counter script' }), |
||
− | + | if ($('#t-contributions').length==0) { |
|
+ | alert('Expected element not found. Please see http://strategywiki.org/wiki/User_talk:Najzere to have your wiki added.'); |
||
− | $('#t-editcounter').click(function () { |
||
+ | return; |
||
− | // Change "Edit counter" to "Calculating..." after click |
||
+ | }; |
||
− | $(this).html('Calculating...'); |
||
+ | var $editCountLink = $('<a>Edit counter</a>').attr( { id: 't-editcounter', href: '#', title: 'Run edit counter script' } ); |
||
− | // Set up variables |
||
+ | $('#t-contributions').after($('<li></li>').html($editCountLink)); |
||
− | var brace = '{', |
||
+ | |||
− | edits = [], |
||
+ | $('#t-editcounter').click( function() { |
||
− | edittoken, |
||
+ | |||
− | movelog = [], |
||
+ | // Change edit counter link to let the user know it's thinking |
||
− | namespaces = [], |
||
+ | $(this).html('Calculating...'); |
||
− | nextmove = '', |
||
+ | |||
− | nextprotect = '', |
||
+ | // Set up variables |
||
− | nextuc = '', |
||
+ | var editSummary = 'updated'; |
||
− | protectlog = [], |
||
+ | var tableTop = '[http://strategywiki.org/wiki/User_talk:Najzere/edit_counter.js edit counter.js] [http://strategywiki.org/wiki/User_talk:Najzere/edit_counter.js#Bugs Why don\'t the numbers match the total?]'; |
||
− | succeeded = false, |
||
+ | var edits = []; |
||
− | table = '<div style="text-align: center; margin-bottom: 1em"><span style="font-weight: bold">Edit Count</span>\n{| class="wikitable" style="text-align: center; margin: 0 auto"\n|-\n! ', |
||
+ | var namespaces = []; |
||
− | tableTop = '[http://strategywiki.org/wiki/User_talk:Najzere/edit_counter.js edit counter.js] [http://strategywiki.org/wiki/User_talk:Najzere/edit_counter.js#Bugs Why don\'t the numbers match the total?]'; |
||
+ | var movelog = []; |
||
− | // Initialize namespace, move log, and patrol log arrays |
||
+ | var protectlog = []; |
||
− | $.ajax({ |
||
+ | var next; |
||
− | url: '/api.php?action=query&meta=siteinfo&siprop=namespaces&format=json', |
||
+ | var edittoken; |
||
− | dataType: 'json', |
||
− | + | var succeeded = false; |
|
+ | var brace = '{'; |
||
− | success: function (siResponse) { |
||
+ | var table = '<div style="text-align: center; margin-bottom: 1em"><span style="font-weight: bold">Edit Count</span>\n{| class="wikitable '+tableClass+'" style="text-align: center; margin: 0 auto"\n|-\n! '; |
||
− | for (var ns in siResponse.query.namespaces) { |
||
+ | |||
− | if (siResponse.query.namespaces[ns].id > -1) { |
||
+ | // Initialize namespace, move log and patrol log arrays |
||
− | if (siResponse.query.namespaces[ns].id !== namespaces.length) { |
||
+ | $.ajax({ |
||
− | break; |
||
+ | url: '/api.php?action=query&meta=siteinfo&siprop=namespaces&format=json', |
||
− | } |
||
+ | dataType: 'json', |
||
− | if (siResponse.query.namespaces[ns].id === 0) { |
||
+ | async: false, |
||
− | namespaces[siResponse.query.namespaces[ns].id] = 'Main'; |
||
− | + | success: function(siResponse) { |
|
− | + | for (var ns in siResponse.query.namespaces) { |
|
− | + | if (siResponse.query.namespaces[ns].id > -1) { |
|
− | + | if(siResponse.query.namespaces[ns].id != namespaces.length) |
|
− | + | break; |
|
− | + | if (siResponse.query.namespaces[ns].id == 0) { |
|
+ | namespaces[siResponse.query.namespaces[ns].id] = 'Main'; |
||
− | } |
||
− | + | } else if (siResponse.query.namespaces[ns].id == 4) { |
|
− | + | namespaces[siResponse.query.namespaces[ns].id] = 'Minecraft Wiki'; |
|
− | + | } else if (siResponse.query.namespaces[ns].id == 5) { |
|
+ | namespaces[siResponse.query.namespaces[ns].id] = 'Minecraft Wiki talk'; |
||
− | } |
||
− | + | } else { |
|
+ | namespaces[siResponse.query.namespaces[ns].id] = siResponse.query.namespaces[ns].canonical; |
||
− | }); |
||
+ | }; |
||
− | // Fill move log array |
||
+ | movelog[siResponse.query.namespaces[ns].id] = 0; |
||
− | while (nextmove !== 'stop') { |
||
+ | protectlog[siResponse.query.namespaces[ns].id] = 0; |
||
− | $.ajax({ |
||
+ | }; |
||
− | url: '/api.php?action=query&list=logevents&letype=move&leuser=Kanegasi&lelimit=max&leprop=title&format=json' + nextmove, |
||
+ | }; |
||
− | dataType: 'json', |
||
+ | } |
||
− | async: false, |
||
+ | }); |
||
− | success: function (moveResponse) { |
||
+ | |||
− | for (var event in moveResponse.query.logevents) { |
||
+ | // Fill move log array |
||
− | movelog[moveResponse.query.logevents[event].ns] += 1; |
||
+ | next = ''; |
||
− | } |
||
+ | while (next != 'stop') { |
||
− | if (moveResponse["query-continue"]) { |
||
+ | $.ajax({ |
||
− | nextmove = '&lestart=' + moveResponse["query-continue"].logevents.lestart; |
||
+ | url: '/api.php?action=query&list=logevents&letype=move&leuser=kanegasi&lelimit=max&leprop=title&format=json'+next, |
||
− | } else { |
||
− | + | dataType: 'json', |
|
− | + | async: false, |
|
+ | success: function(moveResponse) { |
||
− | } |
||
− | + | for (var event in moveResponse.query.logevents) { |
|
+ | movelog[moveResponse.query.logevents[event].ns] += 1; |
||
− | } |
||
+ | }; |
||
− | // Fill protect log array |
||
− | + | if (moveResponse["query-continue"]) { |
|
+ | next = '&lestart='+moveResponse["query-continue"].logevents.lestart; |
||
− | $.ajax({ |
||
− | url: '/api.php?action=query&list=logevents&letype=protect&leuser=Kanegasi&lelimit=max&leprop=title&format=json' + nextprotect, |
||
− | dataType: 'json', |
||
− | async: false, |
||
− | success: function (protectResponse) { |
||
− | for (var event in protectResponse.query.logevents) { |
||
− | protectlog[protectResponse.query.logevents[event].ns] += 1; |
||
− | } |
||
− | if (protectResponse["query-continue"]) { |
||
− | nextprotect = '&lestart=' + protectResponse["query-continue"].logevents.lestart; |
||
− | } else { |
||
− | nextprotect = 'stop'; |
||
− | } |
||
− | } |
||
− | }); |
||
− | } |
||
− | // Loop through namespaces counting edits and subtracting page moves and patrols |
||
− | for (var i = 0; i < namespaces.length; i++) { |
||
− | nextuc = ''; |
||
− | while (nextuc !== 'stop') { |
||
− | $.ajax({ |
||
− | url: '/api.php?action=query&list=usercontribs&ucuser=Kanegasi&uclimit=max&ucdir=newer&format=json&ucnamespace=' + i + nextuc, |
||
− | dataType: 'json', |
||
− | async: false, |
||
− | success: function (ucResponse) { |
||
− | edits[i] = ucResponse.query.usercontribs.length - movelog[i] - protectlog[i]; |
||
− | if (ucResponse["query-continue"]) { |
||
− | nextuc = '&ucstart=' + ucResponse["query-continue"].usercontribs.ucstart; |
||
− | } else { |
||
− | nextuc = 'stop'; |
||
− | } |
||
− | } |
||
− | }); |
||
− | } |
||
− | } |
||
− | for (var i = 0; i <= namespaces.length; i++) { |
||
− | if (edits[i] > 0) { |
||
− | table += namespaces[i] + ' !! '; |
||
− | } |
||
− | } |
||
− | table += 'Total\n|-\n| '; |
||
− | for (var i = 0; i < namespaces.length; i++) { |
||
− | if (edits[i] > 0) { |
||
− | table += brace + brace + 'subst:formatnum:' + edits[i] + '}} || '; |
||
− | } |
||
− | } |
||
− | // Get total edit count as seen on Preferences page |
||
− | $.ajax({ |
||
− | url: '/api.php?action=query&meta=userinfo&uiprop=editcount&format=json', |
||
− | dataType: 'json', |
||
− | async: false, |
||
− | success: function (uiResponse) { |
||
− | table += brace + brace + 'subst:formatnum:' + uiResponse.query.userinfo.editcount + '}}\n|}'; |
||
− | } |
||
− | }); |
||
− | table += '<span style="font-size: x-small">Last updated: ' + brace + brace + 'subst:#time:F j, Y}}. Generated with ' + tableTop + '</span>\n</div>'; |
||
− | // Get edit token |
||
− | $.ajax({ |
||
− | url: '/api.php?action=query&prop=info|revisions&intoken=edit&format=json&titles=User:Kanegasi/edit_count', |
||
− | dataType: 'json', |
||
− | async: false, |
||
− | success: function (propResponse) { |
||
− | for (var page in propResponse.query.pages) { |
||
− | edittoken = propResponse.query.pages[page].edittoken.replace(/\+\\$/g, '%2B%5C'); |
||
− | } |
||
− | } |
||
− | }); |
||
− | // Post new count results to page |
||
− | $.ajax({ |
||
− | url: '/api.php?action=edit&title=User:Kanegasi/edit_count&summary=updated&minor=1&recreate=1&bot=1&text=' + escape(table) + '&token=' + edittoken, |
||
− | type: 'POST', |
||
− | async: false, |
||
− | success: function () { |
||
− | succeeded = true; |
||
− | } |
||
− | }); |
||
− | // Change "Calculating..." to reflect status of operation |
||
− | if (succeeded) { |
||
− | $(this).html('Done!'); |
||
} else { |
} else { |
||
− | + | next = 'stop'; |
|
− | } |
+ | }; |
+ | } |
||
}); |
}); |
||
+ | }; |
||
+ | |||
+ | // Fill protect log array |
||
+ | next = ''; |
||
+ | while (next != 'stop') { |
||
+ | $.ajax({ |
||
+ | url: '/api.php?action=query&list=logevents&letype=protect&leuser=kanegasi&lelimit=max&leprop=title&format=json'+next, |
||
+ | dataType: 'json', |
||
+ | async: false, |
||
+ | success: function(protectResponse) { |
||
+ | for (var event in protectResponse.query.logevents) { |
||
+ | protectlog[protectResponse.query.logevents[event].ns] += 1; |
||
+ | }; |
||
+ | if (protectResponse["query-continue"]) { |
||
+ | next = '&lestart='+protectResponse["query-continue"].logevents.lestart; |
||
+ | } else { |
||
+ | next = 'stop'; |
||
+ | }; |
||
+ | } |
||
+ | }); |
||
+ | }; |
||
+ | |||
+ | // Loop through namespaces counting edits and subtracting page moves and patrols |
||
+ | for (var i = 0; i < namespaces.length; i++) { |
||
+ | next = ''; |
||
+ | while (next != 'stop') { |
||
+ | $.ajax({ |
||
+ | url: '/api.php?action=query&list=usercontribs&ucuser=kanegasi&uclimit=max&ucdir=newer&format=json&ucnamespace='+i+next, |
||
+ | dataType: 'json', |
||
+ | async: false, |
||
+ | success: function(ucResponse) { |
||
+ | edits[i] = ucResponse.query.usercontribs.length - movelog[i] - protectlog[i]; |
||
+ | if (ucResponse["query-continue"]) { |
||
+ | next = '&ucstart='+ucResponse["query-continue"].usercontribs.ucstart; |
||
+ | } else { |
||
+ | next = 'stop'; |
||
+ | }; |
||
+ | } |
||
+ | }); |
||
+ | }; |
||
+ | }; |
||
+ | |||
+ | for (var i = 0; i < namespaces.length; i++) { |
||
+ | if (edits[i] > 0) { |
||
+ | table += namespaces[i]+' !! '; |
||
+ | }; |
||
+ | } |
||
+ | table += 'Total\n|-\n| '; |
||
+ | |||
+ | for (var i = 0; i < namespaces.length; i++) { |
||
+ | if (edits[i] > 0) { |
||
+ | table += brace+brace+'subst:formatnum:'+edits[i]+'}} || '; |
||
+ | }; |
||
+ | } |
||
+ | |||
+ | // Get full edit count, as tracked by MW, add it to table |
||
+ | $.ajax({ |
||
+ | url: '/api.php?action=query&meta=userinfo&uiprop=editcount&format=json', |
||
+ | dataType: 'json', |
||
+ | async: false, |
||
+ | success: function(uiResponse) { |
||
+ | table += brace+brace+'subst:formatnum:'+uiResponse.query.userinfo.editcount+'}}\n|}'; |
||
+ | } |
||
+ | }); |
||
+ | |||
+ | table += '<span style="font-size: x-small">Last updated: '+brace+brace+'subst:#time:F j, Y}}. Generated with '+tableTop+'</span>\n</div>'; |
||
+ | |||
+ | // Get edit token |
||
+ | $.ajax({ |
||
+ | url: '/api.php?action=query&prop=info|revisions&intoken=edit&format=json&titles=User:Kanegasi/edit_counter', |
||
+ | dataType: 'json', |
||
+ | async: false, |
||
+ | success: function(propResponse) { |
||
+ | for (var page in propResponse.query.pages) { |
||
+ | edittoken = propResponse.query.pages[page].edittoken.replace(/\+\\$/g,'%2B%5C'); |
||
+ | }; |
||
+ | } |
||
+ | }); |
||
+ | |||
+ | // Edit the target page with the table |
||
+ | $.ajax({ |
||
+ | url: '/api.php?action=edit&title=User:Kanegasi/edit_counter&summary='+editSummary+'&minor=1&recreate=1&bot=1&text='+escape(table)+'&token='+edittoken, |
||
+ | type: 'POST', |
||
+ | async: false, |
||
+ | success: function() { succeeded = true; } |
||
+ | }); |
||
+ | |||
+ | // change edit count link to reflect the status of the page save |
||
+ | if (succeeded) { |
||
+ | $(this).html('Done!'); |
||
+ | } else { |
||
+ | $(this).html('Error!'); |
||
+ | }; |
||
+ | |||
+ | }); |
||
}); |
}); |
Revision as of 01:03, 2 January 2013
/***********************************************************************************/
/* Edit counter script (original) */
/* author: User:Najzere @ strategywiki.org */
/* source: http://strategywiki.org/wiki/User:Najzere/edit_counter.js */
/* documentation: http://strategywiki.org/wiki/User_talk:Najzere/edit_counter.js */
/* contact: http://strategywiki.org/wiki/User_talk:Najzere */
/* license: CC-BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/) */
/* Modified version for this wiki */
/* author: ultradude25 */
/* source: [[User:Ultradude25/editcounter.js]] */
/* Note from Kanegasi: */
/* THIS VERSION HERE IS SPECIFIC TO ME. DO NOT USE UNLESS YOU KNOW WHAT TO CHANGE! */
/***********************************************************************************/
$(document).ready(function() {
// Add a new link after "User contributions" in the toolbox
if ($('#t-contributions').length==0) {
alert('Expected element not found. Please see http://strategywiki.org/wiki/User_talk:Najzere to have your wiki added.');
return;
};
var $editCountLink = $('<a>Edit counter</a>').attr( { id: 't-editcounter', href: '#', title: 'Run edit counter script' } );
$('#t-contributions').after($('<li></li>').html($editCountLink));
$('#t-editcounter').click( function() {
// Change edit counter link to let the user know it's thinking
$(this).html('Calculating...');
// Set up variables
var editSummary = 'updated';
var tableTop = '[http://strategywiki.org/wiki/User_talk:Najzere/edit_counter.js edit counter.js] [http://strategywiki.org/wiki/User_talk:Najzere/edit_counter.js#Bugs Why don\'t the numbers match the total?]';
var edits = [];
var namespaces = [];
var movelog = [];
var protectlog = [];
var next;
var edittoken;
var succeeded = false;
var brace = '{';
var table = '<div style="text-align: center; margin-bottom: 1em"><span style="font-weight: bold">Edit Count</span>\n{| class="wikitable '+tableClass+'" style="text-align: center; margin: 0 auto"\n|-\n! ';
// Initialize namespace, move log and patrol log arrays
$.ajax({
url: '/api.php?action=query&meta=siteinfo&siprop=namespaces&format=json',
dataType: 'json',
async: false,
success: function(siResponse) {
for (var ns in siResponse.query.namespaces) {
if (siResponse.query.namespaces[ns].id > -1) {
if(siResponse.query.namespaces[ns].id != namespaces.length)
break;
if (siResponse.query.namespaces[ns].id == 0) {
namespaces[siResponse.query.namespaces[ns].id] = 'Main';
} else if (siResponse.query.namespaces[ns].id == 4) {
namespaces[siResponse.query.namespaces[ns].id] = 'Minecraft Wiki';
} else if (siResponse.query.namespaces[ns].id == 5) {
namespaces[siResponse.query.namespaces[ns].id] = 'Minecraft Wiki talk';
} else {
namespaces[siResponse.query.namespaces[ns].id] = siResponse.query.namespaces[ns].canonical;
};
movelog[siResponse.query.namespaces[ns].id] = 0;
protectlog[siResponse.query.namespaces[ns].id] = 0;
};
};
}
});
// Fill move log array
next = '';
while (next != 'stop') {
$.ajax({
url: '/api.php?action=query&list=logevents&letype=move&leuser=kanegasi&lelimit=max&leprop=title&format=json'+next,
dataType: 'json',
async: false,
success: function(moveResponse) {
for (var event in moveResponse.query.logevents) {
movelog[moveResponse.query.logevents[event].ns] += 1;
};
if (moveResponse["query-continue"]) {
next = '&lestart='+moveResponse["query-continue"].logevents.lestart;
} else {
next = 'stop';
};
}
});
};
// Fill protect log array
next = '';
while (next != 'stop') {
$.ajax({
url: '/api.php?action=query&list=logevents&letype=protect&leuser=kanegasi&lelimit=max&leprop=title&format=json'+next,
dataType: 'json',
async: false,
success: function(protectResponse) {
for (var event in protectResponse.query.logevents) {
protectlog[protectResponse.query.logevents[event].ns] += 1;
};
if (protectResponse["query-continue"]) {
next = '&lestart='+protectResponse["query-continue"].logevents.lestart;
} else {
next = 'stop';
};
}
});
};
// Loop through namespaces counting edits and subtracting page moves and patrols
for (var i = 0; i < namespaces.length; i++) {
next = '';
while (next != 'stop') {
$.ajax({
url: '/api.php?action=query&list=usercontribs&ucuser=kanegasi&uclimit=max&ucdir=newer&format=json&ucnamespace='+i+next,
dataType: 'json',
async: false,
success: function(ucResponse) {
edits[i] = ucResponse.query.usercontribs.length - movelog[i] - protectlog[i];
if (ucResponse["query-continue"]) {
next = '&ucstart='+ucResponse["query-continue"].usercontribs.ucstart;
} else {
next = 'stop';
};
}
});
};
};
for (var i = 0; i < namespaces.length; i++) {
if (edits[i] > 0) {
table += namespaces[i]+' !! ';
};
}
table += 'Total\n|-\n| ';
for (var i = 0; i < namespaces.length; i++) {
if (edits[i] > 0) {
table += brace+brace+'subst:formatnum:'+edits[i]+'}} || ';
};
}
// Get full edit count, as tracked by MW, add it to table
$.ajax({
url: '/api.php?action=query&meta=userinfo&uiprop=editcount&format=json',
dataType: 'json',
async: false,
success: function(uiResponse) {
table += brace+brace+'subst:formatnum:'+uiResponse.query.userinfo.editcount+'}}\n|}';
}
});
table += '<span style="font-size: x-small">Last updated: '+brace+brace+'subst:#time:F j, Y}}. Generated with '+tableTop+'</span>\n</div>';
// Get edit token
$.ajax({
url: '/api.php?action=query&prop=info|revisions&intoken=edit&format=json&titles=User:Kanegasi/edit_counter',
dataType: 'json',
async: false,
success: function(propResponse) {
for (var page in propResponse.query.pages) {
edittoken = propResponse.query.pages[page].edittoken.replace(/\+\\$/g,'%2B%5C');
};
}
});
// Edit the target page with the table
$.ajax({
url: '/api.php?action=edit&title=User:Kanegasi/edit_counter&summary='+editSummary+'&minor=1&recreate=1&bot=1&text='+escape(table)+'&token='+edittoken,
type: 'POST',
async: false,
success: function() { succeeded = true; }
});
// change edit count link to reflect the status of the page save
if (succeeded) {
$(this).html('Done!');
} else {
$(this).html('Error!');
};
});
});