|
|
(44 intermediate revisions by the same user not shown) |
Line 1: |
Line 1: |
| /*
| | |
| Adds a banner to the top of pages of blocked users.
| |
| */
| |
|
| |
| function check_blocked(){
| |
|
| |
| var username;
| |
| //Is this a user/user_talk page (fails for subpages)
| |
| if( wgCanonicalNamespace == 'User' || wgCanonicalNamespace == 'User_talk' ){
| |
| username = wgTitle;
| |
|
| |
| }else{ //Assume Special:Contributions
| |
| var inputs = document.getElementsByTagName('input');
| |
| for(var i=0;i<inputs.length;i++ ){
| |
| if( inputs[i].name == 'target'){
| |
| username = inputs[i].value;
| |
| }
| |
| }
| |
| }
| |
|
| |
| if(!username) return false;
| |
| var ajaxer = sajax_init_object();
| |
|
| |
| if(! ajaxer) return false;
| |
|
| |
| ajaxer.onreadystatechange = function(){
| |
| if( ajaxer.readyState == 4 ){
| |
| if( ajaxer.status == 200 ){
| |
| var resp = ajaxer.responseText;
| |
| if( resp.indexOf('[expiry]') > 0 ){
| |
| is_blocked(resp, username);
| |
| }else{
| |
| not_blocked(resp);
| |
| }
| |
| }
| |
| }
| |
| }
| |
|
| |
| ajaxer.open("GET", wgScriptPath+ '/api.php?format=txt&action=query&list=blocks&bkprop=expiry&bkusers='+encodeURIComponent(username) );
| |
| ajaxer.send('');
| |
|
| |
| }
| |
| function is_blocked(resp, username){
| |
| var ip = document.getElementById('contentSub');
| |
| if(!ip) return; //happens on classic skin
| |
|
| |
| var sp = resp.indexOf('[expiry] => ')+12;
| |
| var ep = resp.indexOf("\n",sp);
| |
| var exp = resp.substr(sp,ep-sp);
| |
| var blockNode;
| |
| if(exp == 'infinity')
| |
| blockNode = newNode('b',"indefinitely");
| |
| else
| |
| blockNode = newNode('span',"until "+exp);
| |
| var blockLogNode = newNode('a', 'log', {href: '/w/index.php?title=Special:Log&type=block&page=User:' + username})
| |
|
| |
| ip.parentNode.insertBefore(
| |
| newNode('div',{'style':"border: 1px dashed #884444;background-color: #FFE7DD; text-align: center"},
| |
| newNode('p','This user is blocked from editing ', blockNode, ' (', blockLogNode, ')')
| |
| )
| |
| ,ip.nextSibling);
| |
|
| |
| }
| |
| function not_blocked(){ /* Do Nothing */}
| |
|
| |
| if( wgCanonicalNamespace == 'User' || wgCanonicalNamespace == 'User_talk' || wgCanonicalSpecialPageName == 'Contributions' || wgCanonicalSpecialPageName == 'DeletedContributions'){
| |
| addOnloadHook(check_blocked);
| |
| }
| |