מדיה ויקי:Gadget-IsBlock.js: הבדלים בין גרסאות בדף
מראה
אין תקציר עריכה |
מ 1Or העביר את הדף משתמש:1Or/99.js לשם מדיה ויקי:סקריפטים/99.js |
(אין הבדלים)
| |
גרסה מ־07:09, 4 בפברואר 2017
if ($( '.blockRequestUserName '))
$(document).ready( () => {
mw.loader.using(['mediawiki.util', 'mediawiki.api']).done( () => {
var list = {};
// collect all {{לחסום}} requests. note that it's an object, keyed by user name.
// so, if there are multiple requests for same users, we only ask for one, and remember for each
// all the spans we want to update for this user.
$( '.blockRequestUserName ').each( function() {
var span = $( this ),
username = span.data( 'username' );
(list[username] = (list[username] || [])).push(span);
});
// filter all anons to one list, and registered to another.
var anons = Object.keys(list).filter( mw.util.isIPAddress );
var registered = Object.keys(list).filter( u => ! mw.util.isIPAddress(u) );
// construct an api object to be used below
var api = new mw.Api();
// start sending api calls. for anons ("bkip" parameter), we can only ask one at a time.
anons.forEach( anon => {
api.get( {
list: 'blocks',
bkip: anon
})
.done( reportBlocks );
});
// for registered, we can ask for up to 50 at a time.
// todo: check list length, use .slice() or .splice() to chuck them in batches of 50.
if (registered.length) {
api.get( {
list: 'blocks',
bkusers: registered.join('|')
})
.done( reportBlocks );
}
// when query returns, see if there are any blocks, and if there are, add the block marker.
// note that list[user] is an array of all the spans in the page requesting to block this user.
// typically this array will be of length 1, but it can be more.
function reportBlocks( data ) {
if (data && data.query && data.query.blocks )
data.query.blocks.forEach( block => {
var user = decodeURIComponent( block.user ); // the api returns the user name encoded.
addBlockedMarker( list[user], block.by );
});
}
function addBlockedMarker( spans, by ) {
spans.forEach( span =>
span
.text(' | חסום ')
.attr('title', 'נחסמ/ה על ידי ' + by)
);
}
});
});