/**
* This script highlights the users in special groups thanks to a JSON that is
* populated with these data by a bot (in this case, using APIs).
*
* This script needs the page ]
* @FixMe Find a better place to insert abbrs. The huge fantasy of wikipedians
* may produce weird results, e.g. breaking the username when half of it links
* to the user page, and the other half to the talk page. This should also avoid
* cases where the abbr inherits some CSS from the signature (currently handled
* with font-style: initial).
*/
// <nowiki>
( function ( mw, $ ) {
'use strict';
// run only if in allowed ns, history, talks, and diffs
var allowedNs = ,
disabledPages = ,
cfgPage = 'Utente:ItwikiBot/AdminList',
specialPage = mw.config.get( 'wgCanonicalSpecialPageName' );
if ( ! (
allowedNs.indexOf( mw.config.get( 'wgCanonicalNamespace' ) ) !== -1 ||
mw.config.get( 'wgAction' ) === 'history' ||
mw.config.get( 'wgNamespaceNumber' ) % 2 === 1 ||
mw.util.getParamValue( 'diff' ) !== null
) ) {
return;
}
// do nothing in these special pages (to have clean copy-paste)
if( disabledPages.indexOf( specialPage ) !== -1 ) {
return;
}
mw.hook( 'wikipage.content' ).add( function markAdmins ( $content ) {
mw.util.addCSS( 'abbr.adminMark { font-style: initial; font-weight: bold; padding-left: 5px; font-size: 0.7em; }' );
$.getJSON( 'https://wiki95.com/it/' + cfgPage + '?action=raw&ctype=application/json', function processList ( response ) {
var userNs = mw.config.get( 'wgFormattedNamespaces' ),
userPath = mw.config.get( 'wgArticlePath' ).replace( '$1', userNs ),
userPattern = /.wiki.Utente.(.+)/;
// for each link
$content.find( 'a' ).each( function addPerUserGroups () {
var $link = $( this ), userPatternMatch,
href = $link.attr( 'href' ),
userLink, userName, knownUserGroups, groupShort, groupName, i,
$container, $abbr;
// only links to users
if ( href && href.indexOf( userPath ) !== -1 ) {
// no sub pages
userPatternMatch = userPattern.exec( href );
userLink = userPatternMatch ? userPatternMatch : null;
if( userLink && userLink.indexOf( '/' ) === -1 ) {
userName = decodeURIComponent( userLink.replace( /\/.*/, '' ).replace( /_/g, ' ' ) );
knownUserGroups = response.users;
if ( knownUserGroups ) {
$container = $( '<span>' );
for( i in knownUserGroups ) {
groupShort = knownUserGroups;
groupName = response.legend;
$abbr = $( '<abbr class="adminMark">' )
.attr( 'title', groupName )
.text( groupShort );
$container.append( $abbr );
}
$link.after( $container );
}
}
}
} );
} );
} );
} )( mediaWiki, jQuery );
// </nowiki>