MediaWiki:Gadget-markAdmins.js
Vai alla navigazione
Vai alla ricerca
Nota: Dopo aver salvato le preferenze, perché i cambi abbiano effetto, devi bypassare la cache del tuo browser. Mozilla / Firefox / Safari: tieni premuto Shift mentre clicchi Reload, o premi Ctrl-Shift-R (Cmd-Shift-R per Apple Mac); Google Chrome: premi Ctrl o Shift mentre clicchi F5; IE: premi Ctrl mentre clicchi Refresh, o premi Ctrl-F5; Konqueror:: clicca semplicemente il pulsante di Reload, o premi F5; se usi Opera devi cancellare completamente la chache nel menu Tools→Preferences.
/** * 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; font-size: 0.7em; }' ); $.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.(.+)/; // for each link $content.find( 'a' ).each( function addPerUserGroups () { var $link = $( this ), 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 userLink = userPattern.exec( href )[ 1 ]; if( userLink.indexOf( '/' ) === -1 ) { userName = decodeURIComponent( userLink.replace( /\/.*/, '' ).replace( /_/, ' ' ) ); 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>