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

Contenuto cancellato Contenuto aggiunto
da MediaWiki:Gadget-markAdmins2.js del 4 ott 2018 alle 09:13; nuova versione basata sulle informazioni presenti nella pagina Utente:ItwikiBot/AdminList e aggiornate automaticamente; vedi WP:Officina del 4 ott 2018 alle 09:27
fix regex: sostituisci tutti gli underscore nei nomi utente, non solo il primo
 
(6 versioni intermedie di 3 utenti non mostrate)
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]]
* @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
* @see [[MediaWiki:Gadget-markAdmins.js]]
* 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',
var specialPage = mw.config.get( 'wgCanonicalSpecialPageName' );
 
if ( ! (
allowedNs.indexOf( mw.config.get( 'wgCanonicalNamespace' ) ) !== -1 ||
Riga 21 ⟶ 30:
}
 
// 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-style: initial; font-weight: bold; padding-left: 5px; font-size: 0.7em; }' );
$.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 );, userPatternMatch,
var href = $link.attr( 'href' );,
userLink, userName, knownUserGroups, groupShort, groupName, i,
$container, $abbr;
 
// only links to users
Riga 44 ⟶ 53:
 
// no sub pages
var userLinkuserPatternMatch = userPattern.exec( href )[ 1 ];
if( userLink.indexOf( '/'= )userPatternMatch ===? userPatternMatch[ -1 )] : {null;
varif( userLink && userLink.indexOf( '/' ) === -1 ) {
userName = decodeURIComponent( userLink.replace( /\/.*/, '' ).replace( /_/g, ' ' ) );
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 )