מדיה ויקי:Gadget-IsBlock.js: הבדלים בין גרסאות בדף

ביטול גרסה 20069760 של 1Or (שיחה)
מ 65 גרסאות של הדף wikipedia:he:מדיה_ויקי:Gadget-IsBlock.js יובאו
 
(45 גרסאות ביניים של 5 משתמשים אינן מוצגות)
שורה 1: שורה 1:
function isAnon(m){
$( function() {
new mw.Api().get({
if ($( '.blockRequestUserName ').length === 0) return;
"action": "query",
var list = {};
"format": "json",
 
"list": "blocks",
// collect all {{לחסום}} requests. note that it's an object, keyed by user name.
"bkip": m
// so, if there are multiple requests for same users, we only ask for one, and remember for each
}).done(function(ans) {
// all the spans we want to update for this user.
logs = ans;
$( '.blockRequestUserName ').each( function() {
console.log(logs);
var span = $( this ),
if (logs.query.blocks.length > 0) {b = b.replace(a, "$1$2\" title\=\"מיוחד:חסימה\/$3\"$4/ \($3 חסומ/ה\)"); document.getElementById("bodyContent").innerHTML = b;}
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( function(u) { return !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( function(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( function(block) {
var user = decodeURIComponent( block.user ); // the api returns the user name encoded.
addBlockedMarker( list[user] || [], block.by );
});
}
function addBlockedMarker( spans, by ) {
spans.forEach( function(span) {
span
.text(' | חסומ/ה')
.attr('title', 'נחסמ/ה על ידי '  + by);
});
}
});
});
}
function isUser(m){
new mw.Api().get({
"action": "query",
"format": "json",
"list": "blocks",
"bkusers": m
}).done(function(ans) {
logs = ans;
if (logs.query.blocks.length > 0) {b = b.replace(a, "$1$2\" title\=\"מיוחד:חסימה\/$3\"$4/ \(חסומ/ה\)"); document.getElementById("bodyContent").innerHTML = b;}
});
}
var b = $('#bodyContent')["0"].innerHTML;
var a = /(\/wiki\/%D7%9E%D7%99%D7%95%D7%97%D7%93:%D7%97%D7%A1%D7%99%D7%9E%D7%94\/)(.+?)" title\="מיוחד:חסימה\/(.+?)"(.+?a>)/g;
var m;
var anon;
while(m=a.exec(b)) {
anon = mw.util.isIPv4Address(m[3]) || mw.util.isIPv6Address(m[3]);
anon ? isAnon(m[3]) : isUser(m[3]);
}