MediaWiki:Gadget-markAdmins.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m rimosso commento ricorsivo
Minime correzioni stilistiche come da convenzioni MediaWiki: dichiarazioni di variabili in alto, no Yoda conditions; nomi alle funzioni anonime per chiarezza nelle stack trace, +una variabile per maggiore configurabilità
Riga 1:
/**
* 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 thisthe page: [[Utente:ItwikiBot/AdminList]]
*/
 
// <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',
var specialPage = mw.config.get( 'wgCanonicalSpecialPageName' );
 
if ( ! (
allowedNs.indexOf( mw.config.get( 'wgCanonicalNamespace' ) ) !== -1 ||
Riga 19 ⟶ 25:
}
 
// do nothing in these special pages (why? pheraps is useful to have clean copy-paste?)
if( disabledPages.indexOf( specialPage ) !== -1 ) {
var specialPage = mw.config.get( 'wgCanonicalSpecialPageName' );
if( 'Prefixindex' === specialPage || 'Allpages' === specialPage ) {
return;
}
 
mw.hook( 'wikipage.content' ).add( function markAdmins ( $content ) {
mw.util.addCSS( 'abbr.adminMark { font-weight: bold; padding-left: 5px; }' );
$.getJSON( '/wiki/Utente:ItwikiBot/AdminList' + cfgPage + '?action=raw&ctype=application/json', function processList ( response ) {
var specialPageuserNs = mw.config.get( 'wgCanonicalSpecialPageNamewgFormattedNamespaces' );[ 2 ],
var userNs userPath = mw.config.get( 'wgFormattedNamespaceswgArticlePath' )[.replace( 2'$1', ];userNs ),
var userPattern = /.wiki.Utente.(.+)/;
var userPath = mw.config.get( 'wgArticlePath' ).replace( '$1', userNs );
var userPattern = /.wiki.Utente.(.+)/;
 
// for each link
$content.find( 'a' ).each( function addPerUserGroups () {
var $link = $( this );,
var href = $link.attr( 'href' );,
userLink, userName, knownUserGroups, groupShort, groupName, i,
$container, $abbr;
 
// only links to users
Riga 42 ⟶ 48:
 
// 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 )