MediaWiki:Gadget-markblocked.js: Difference between revisions
no edit summary
Johnrdorazio (talk | contribs) m (1 revision imported) |
Johnrdorazio (talk | contribs) 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; | ||
// Collect all the links in the page's content | // Collect all the links in the page's content | ||
var contentLinks = $( container ).find( 'a' ); | |||
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; | ||
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 | ||
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; | ||
default: // 'view', 'history', 'purge', ... | |||
if ( mw. | var maybeAutostart = $.Deferred(); | ||
if ( window.mbNoAutoStart ) { | |||
var portletLink = mw.util.addPortletLink( 'p-cactions', '', 'XX', 'ca-showblocks' ); | |||
$( portletLink ).click( function ( e ) { | |||
e.preventDefault(); | |||
maybeAutostart.resolve(); | |||
} ); | |||
} else { | |||
maybeAutostart.resolve(); | |||
} | } | ||
$.when( $.ready, mw.loader.using( 'mediawiki.util' ), maybeAutostart ).then( function() { | |||
$.when( $.ready, mw.loader.using( 'mediawiki.util' ) ).then( function() { | var firstTime = true; | ||
mw.hook( 'wikipage.content' ).add( function ( container ) { | |||
// On the first call after initial page load, container is mw.util.$content | |||
// Used to limit mainspace activity to just the diff definitions | |||
if ( mw.config.get( 'wgAction' ) === 'view' && mw.config.get( 'wgNamespaceNumber' ) === 0 ) { | |||
container = container.find( '.diff-title' ); | |||
} | |||
} | |||
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 ); | |||
} ); | |||
} ); | |||
} | } |