بەکارھێنەر:Sakura emad/Gadget-markAdmins2.js
ڕواڵەت
بەڵگەنامەی ئەم سکریپتی بەکارھێنەرە دەتوانرێت لە بەکارھێنەر:Sakura emad/Gadget-markAdmins2 زیاد بکرێت. |
/**
* 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 [[بەکارھێنەر:Sakura emad/lists.json]]
* @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 = 'بەکارھێنەر:Sakura emad/lists.json',
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 = decodeURI(mw.config.get( 'wgArticlePath' ).replace( '$1', userNs )),
userPattern = /.wiki.بەکارھێنەر.(.+)/;
// for each link
$content.find( 'a' ).each( function addPerUserGroups () {
var $link = $( this ), userPatternMatch,
href = decodeURI($link.attr( 'href' )),
userLink, userName, knownUserGroups, groupShort, groupName, i,
$container, $abbr;
// only links to users
if ( href && href.indexOf( userPath ) !== -1 ) {
// no sub pages
userPatternMatch = userPattern.exec( href );
userLink = userPatternMatch ? userPatternMatch[ 1 ] : null;
if( userLink && 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>