Jump to content

MediaWiki:Gadget-markblocked.js: Difference between revisions

no edit summary
m (1 revision imported)
No edit summary
 
Line 8: Line 8:
function markBlocked( container ) {
function markBlocked( container ) {
var ipv6Regex = /^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i;
var ipv6Regex = /^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i;
var contentLinks;


// Collect all the links in the page's content
// Collect all the links in the page's content
if ( container ) {
var contentLinks = $( container ).find( 'a' );
contentLinks = $( container ).find( 'a' );
} else if ( mw.util.$content ) {
contentLinks = mw.util.$content.find( 'a' ).add( '#ca-nstab-user a' );
} else {
contentLinks = $();
}


mw.util.addCSS('\
a.user-blocked-temp {'  + ( window.mbTempStyle || 'opacity: 0.7; text-decoration: line-through' ) + '}\
a.user-blocked-indef {'  + ( window.mbIndefStyle || 'opacity: 0.4; font-style: italic; text-decoration: line-through' ) + '}\
a.user-blocked-partial {'  + ( window.mbPartialStyle || 'text-decoration: underline; text-decoration-style: dotted' ) + '}\
.user-blocked-tipbox {' + ( window.mbTipBoxStyle || 'font-size:smaller; background:#FFFFF0; border:1px solid #FEA; padding:0 0.3em; color:#AAA' ) + '}\
');
var mbTooltip =  window.mbTooltip || '; blocked ($1) by $2: $3 ($4 ago)';
var mbTooltip =  window.mbTooltip || '; blocked ($1) by $2: $3 ($4 ago)';


Line 31: Line 18:
for ( var ns in mw.config.get( 'wgNamespaceIds' ) ) {
for ( var ns in mw.config.get( 'wgNamespaceIds' ) ) {
if ( mw.config.get( 'wgNamespaceIds' )[ns] == 2 || mw.config.get( 'wgNamespaceIds' )[ns] == 3 ) {
if ( mw.config.get( 'wgNamespaceIds' )[ns] == 2 || mw.config.get( 'wgNamespaceIds' )[ns] == 3 ) {
userNS.push( ns.replace( /_/g, ' ' ) + ':' );
userNS.push( mw.util.escapeRegExp(ns.replace( /_/g, ' ' )) + ':' );
}
}
}
}
Line 94: Line 81:
// API request
// API request
var serverTime, apiRequests = 0;
var serverTime, apiRequests = 0;
var waitingCSS = mw.util.addCSS( 'a.userlink {opacity:' + ( window.mbLoadingOpacity || 0.85 ) + '}' );
container.addClass( 'markblocked-loading' );
while ( users.length > 0 ) {
while ( users.length > 0 ) {
apiRequests++;
apiRequests++;
Line 153: Line 140:


if ( --apiRequests === 0 ) { // last response
if ( --apiRequests === 0 ) { // last response
waitingCSS.disabled = true;
container.removeClass( 'markblocked-loading' );
$( '#ca-showblocks' ).parent().remove(); // remove added portlet link
$( '#ca-showblocks' ).parent().remove(); // remove added portlet link
}
}
Line 190: Line 177:
}
}
}// -- end of main function
}// -- end of main function


// Start on some pages
// Start on some pages
Line 197: Line 183:
case 'submit':
case 'submit':
break;
break;
case 'view':
default: // 'view', 'history', 'purge', ...
if ( mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
var maybeAutostart = $.Deferred();
break;
if ( window.mbNoAutoStart ) {
var portletLink = mw.util.addPortletLink( 'p-cactions', '', 'XX', 'ca-showblocks' );
$( portletLink ).click( function ( e ) {
e.preventDefault();
maybeAutostart.resolve();
} );
} else {
maybeAutostart.resolve();
}
}
// Otherwise continue with default
 
default: // 'history', 'purge'
$.when( $.ready, mw.loader.using( 'mediawiki.util' ), maybeAutostart ).then( function() {
$.when( $.ready, mw.loader.using( 'mediawiki.util' ) ).then( function() {
var firstTime = true;
if ( window.mbNoAutoStart ) {
 
var portletLink = mw.util.addPortletLink( 'p-cactions', '', 'XX', 'ca-showblocks' );
mw.hook( 'wikipage.content' ).add( function ( container ) {
$( portletLink ).click( function ( e ) {
// On the first call after initial page load, container is mw.util.$content
e.preventDefault();
 
markBlocked();
// Used to limit mainspace activity to just the diff definitions
} );
if ( mw.config.get( 'wgAction' ) === 'view' && mw.config.get( 'wgNamespaceNumber' ) === 0 ) {
} else {
container = container.find( '.diff-title' );
mw.hook( 'wikipage.content' ).add( markBlocked );
}
}
 
  } );
if ( firstTime ) {
firstTime = false;
 
// On page load, also update the namespace tab
container = container.add( '#ca-nstab-user' );
 
mw.util.addCSS('\
.markblocked-loading a.userlink {opacity:' + ( window.mbLoadingOpacity || 0.85 ) + '}\
a.user-blocked-temp {'  + ( window.mbTempStyle || 'opacity: 0.7; text-decoration: line-through' ) + '}\
a.user-blocked-indef {'  + ( window.mbIndefStyle || 'opacity: 0.4; font-style: italic; text-decoration: line-through' ) + '}\
a.user-blocked-partial {'  + ( window.mbPartialStyle || 'text-decoration: underline; text-decoration-style: dotted' ) + '}\
.user-blocked-tipbox {' + ( window.mbTipBoxStyle || 'font-size:smaller; background:#FFFFF0; border:1px solid #FEA; padding:0 0.3em; color:#AAA' ) + '}\
');
}
 
markBlocked( container );
} );
} );
}
}