Utente:Daimona Eaytoy/markAdmins.js
Questa pagina definisce alcuni parametri di aspetto e comportamento generale di tutte le pagine. Per personalizzarli vedi Aiuto:Stile utente.
Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti (per le pagine globali è comunque necessario attendere qualche minuto). Per Mozilla / Firefox / Safari: fare clic su Ricarica tenendo premuto il tasto delle maiuscole, oppure premere Ctrl-F5 o Ctrl-R (Command-R su Mac); per Chrome: premere Ctrl-Shift-R (Command-Shift-R su un Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menù Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.
/**
* 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 [[Utente:ItwikiBot/AdminList]]
* @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 = [ 'Help', 'User', 'User_talk', 'Project', 'Special' ],
disabledPages = [ 'Prefixindex', 'Allpages' ],
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 }' );
$.getJSON( '/wiki/' + cfgPage + '?action=raw&ctype=application/json', function processList ( response ) {
var userNs = mw.config.get( 'wgFormattedNamespaces' )[ 2 ],
userPath = mw.config.get( 'wgArticlePath' ).replace( '$1', userNs ),
userPattern = /.wiki.(?:Utente|User).(.+)/,
talkNs = mw.config.get( 'wgFormattedNamespaces' )[ 3 ].replace( ' ', '_' ),
talkPath = mw.config.get( 'wgArticlePath' ).replace( '$1', talkNs ),
talkPattern = /.wiki.(?:Discussioni_utente|User_talk).(.+)/,
currUser = null;
// Run for each link in reverse order: this allows to examine the
// talk link first. If the talk link is before the user page link,
// then ask the user to change his signature.
$($content.find( 'a' ).get().reverse()).each( function addPerUserGroups () {
var $link = $( this ),
href = $link.attr( 'href' ),
userLink, talkLink, userName, knownUserGroups, groupShort, groupName, i,
$container, $abbr;
// Scan the talk link first, so that we can maybe skip the user page link.
if ( href && href.indexOf( talkPath ) !== -1 ) {
// no talk subpages
talkLink = talkPattern.exec( href )[ 1 ];
if( talkLink.indexOf( '/' ) === -1 ) {
userName = decodeURIComponent( talkLink.replace( /\/.*/, '' ).replace( /_/, ' ' ) );
currUser = userName;
}
} else if ( href && href.indexOf( userPath ) !== -1 ) {
// no user page subpages
userLink = userPattern.exec( href )[ 1 ];
if( userLink.indexOf( '/' ) === -1 ) {
userName = decodeURIComponent( userLink.replace( /\/.*/, '' ).replace( /_/, ' ' ) );
if ( userName === currUser ) {
// The link was already added after the talk page
currUser = null;
return;
}
}
currUser = null;
} else {
currUser = null;
}
if ( !userName ) {
return;
}
knownUserGroups = response.users[ userName ];
if ( knownUserGroups ) {
$container = $( '<span>' );
for( i in knownUserGroups ) {
groupShort = knownUserGroups[ i ];
groupName = response.legend[ groupShort ];
$abbr = $( '<abbr class="adminMark">' )
.attr( 'title', groupName )
.text( groupShort );
$container.append( $abbr );
}
$link.after( $container );
}
} );
} );
} );
} )( mediaWiki, jQuery );
// </nowiki>