MediaWiki:Gadget-markAdmins.js

Versione del 9 ott 2018 alle 00:23 di Valerio Bozzolan (discussione | contributi) (rimosso commento ricorsivo)

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.
 *
 * This script needs this page: [[Utente:ItwikiBot/AdminList]]
 */

// <nowiki>
( function ( mw, $ ) {
	// run only if in allowed ns, history, talks, and diffs
	var allowedNs = [ 'Help', 'User', 'User_talk', 'Project', 'Special' ];
	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 (why? pheraps is useful to have clean copy-paste?)
	var specialPage = mw.config.get( 'wgCanonicalSpecialPageName' );
	if( 'Prefixindex' === specialPage || 'Allpages' === specialPage ) {
		return;
	}

	mw.hook( 'wikipage.content' ).add( function ( $content ) {
		mw.util.addCSS( 'abbr.adminMark { font-weight: bold; padding-left: 5px; }' );
		$.getJSON( '/wiki/Utente:ItwikiBot/AdminList?action=raw&ctype=application/json', function ( response ) {
			var specialPage = mw.config.get( 'wgCanonicalSpecialPageName' );
			var userNs      = mw.config.get( 'wgFormattedNamespaces' )[ 2 ];
			var userPath    = mw.config.get( 'wgArticlePath' ).replace( '$1', userNs );
			var userPattern = /.wiki.Utente.(.+)/;

			// for each link
			$content.find( 'a' ).each( function () {
				var $link = $( this );
				var href = $link.attr( 'href' );

				// only links to users
				if ( href && href.indexOf( userPath ) !== -1 ) {

					// no sub pages
					var userLink = userPattern.exec( href )[ 1 ];
					if( userLink.indexOf( '/' ) === -1 ) {
						var userName = decodeURIComponent( userLink.replace( /\/.*/, '' ).replace( /_/, ' ' ) );
						var knownUserGroups = response.users[ userName ];
						if ( knownUserGroups ) {
							$container = $( '<span>' );
							for( var i in knownUserGroups ) {
								var groupShort = knownUserGroups[ i ];
								var groupName = response.legend[ groupShort ];
								$abbr = $( '<abbr class="adminMark">' )
									.attr( 'title', groupName         )
									.text(          groupShort        );
								$container.append( $abbr );
							}
							$link.after( $container );
						}
					}
				}
			} );
		} );
	} );

} )( mediaWiki, jQuery );
// </nowiki>