User:The Voidwalker/histFilter.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
This user script seems to have a documentation page at User:The Voidwalker/histFilter. |
//<nowiki>
// While viewing the history of a page, one may now elect to only see revisions made by blocked users
if( mw.config.get('wgAction') === 'history' ) {
mw.loader.using('mediawiki.util').then(function() {
var button = document.createElement('input');
button.setAttribute('type', 'button');
button.setAttribute('value', 'Show blocked users only');
button.setAttribute('style', 'margin-left: 4px;');
button.setAttribute('id', 'history-blocked-only');
button.addEventListener('click', generateHistory);
$('.historysubmit.mw-history-compareselectedversions-button').after(button);
$('#history-blocked-only').click(function(){ generateHistory(); });
});
}
function getLimit() {
if( !/&limit=\d+/.test(window.location) ) {
return 50;
}
return /\d+/.exec(/&limit=\d+/.exec(window.location)[0])[0];
}
function generateHistory(c, lim) {
var limit;
if( !c ) {
$('#pagehistory')[0].innerHTML = ''; //Poof, it's gone
$('#pagehistory').append('<span id="temp-while-fetching">Getting relevant revisions</span>');
limit = getLimit();
} else {
limit = lim;
}
var pageID = mw.config.get('wgArticleId');
var query = {
format: 'json',
action: 'query',
pageids: pageID,
prop: 'revisions',
rvprop: 'ids|timestamp|flags|parsedcomment|size|user',
rvlimit: 500
};
if( c ) {
query.continue = c.continue;
query.rvcontinue = c.rvcontinue;
}
$.getJSON( mw.util.wikiScript('api'), query).done(function(data){
var revisions = data.query.pages[pageID].revisions;
var users = [];
for(var i = 0; i < revisions.length; i++) {
var revuser = revisions[i].user;
if(revuser && !users.includes(revuser))
users.push(revuser);
}
var usersfull = [];
var count = 0;
while( users.length !== 0 ) {
usersfull[count] = users.slice(0,50);
users = users.slice(50);
count++;
}
var apireqs = 0;
var blocked = [];
for(i = 0; i < usersfull.length; i++) {
getBlockSet(usersfull[i]);
apireqs++;
}
function getBlockSet(userset) {
$.getJSON( mw.util.wikiScript('api'), {
format: 'json',
action: 'query',
list: 'blocks',
bkusers: userset.join('|'),
bklimit: 50 // Only returns active blocks on bkusers, with max bkusers as 50
}).done(function(data){
var blocks = data.query.blocks;
for(var i = 0; i < blocks.length; i++) {
blocked.push(blocks[i].user);
}
if( --apireqs === 0 ) // Last request
showResults();
});
}
function showResults() {
var appended = 0;
for(var i = 0; i < revisions.length && appended < limit; i++) {
if(blocked.includes(revisions[i].user)) {
appendRev(revisions[i]);
appended++;
}
}
if(appended < limit && data.continue) {
generateHistory(data.continue, limit - appended);
} else {
$("#temp-while-fetching").remove();
}
}
});
function appendRev(revision) {
var text = '<li>(<a href="/w/index.php?diff=' + revision.revid + '">prev</a>) <a href="/w/index.php?oldid=' + revision.revid +
'">' + revision.timestamp + '</a>‎ <a href="/wiki/User:' + revision.user + '">' + revision.user +
'</a> (<a href="/wiki/User_talk:' + revision.user + '">talk</a> | <a href="/wiki/Special:Contribs/' + revision.user +
'">contribs</a>)‎ ' + (revision.minor !== undefined ? '<abbr class="minoredit" title="This is a minor edit">m</abbr>‎ ' : '') +
' . . (' + revision.size + ' bytes)' + (!revision.parsedcomment || revision.parsedcomment.length === 0 ? '' : ' . . <i>(' + revision.parsedcomment + ')</i>' ) + '</li>';
$('#pagehistory').append(text);
}
}
//</nowiki>