MediaWiki:Gadget-MarkAdmins.js
// Ignore buttons
if (a.role === 'button') return;
// Ignore anchors embedded in image
var ch;
if ((ch = a.children[0]) && ch.nodeName === 'IMG') return;
// Ignore section links in edit summary
var pr;
if ((pr = a.parentElement) && pr.classList.contains('autocomment')) return;
// Get href
var href = a.getAttribute('href');
if (!href) {
if (isUserpage && a.classList.contains('mw-selflink')) {
href = '/wiki/' + mw.config.get('wgPageName');
} else {
return;
}
}
/*
* It's quite complicated to deal with index.php links. They are used everywhere for meta links like date links on
* history, undo links, and a lot more. This can be a serious issue for this script because, when we're on an admin's
* usertalk history for instance, almost every link has a "index.php?title=User talk:ADMIN&..." href, which means
* all of these will be marked up. However, we do want to look at index.php links because this script also marks up
* contribs links and they can be preceded by user/usertalk links like "user -> usertalk -> contribs", where we want to
* ONLY mark up the first, and user/usertalk links can be redlinks, which are generated oftentimes by index.php.
* Just looking also at index.php links will over-mark, so let's look only at redlinks for index.php. (This automatically
* means that index.php contribs links cannot be dealt with.)
*/
var m;
var isRedlink = a.classList.contains('new');
if ((m = regex.article.exec(href)) || isRedlink && (m = regex.script.exec(href))) {
href = m[1];
} else {
return;
}
href = decodeURIComponent(href).replace(/_/g, ' ');
// Extract non-prefixed title ( /wiki/User talk:Foo/subpage -> Foo/subpage or /wiki/Special:Contributions/Foo -> Foo )
var nonPrefixedTitle, pagetype;
if ((m = regex.user.exec(href))) {
nonPrefixedTitle = m[1];
pagetype = 'user';
} else if ((m = regex.usertalk.exec(href))) {
nonPrefixedTitle = m[1];
pagetype = 'usertalk';
} else if ((m = regex.contribs.exec(href))) {
nonPrefixedTitle = m[1];
pagetype = 'contribs';
} else {
return;
}
// Extract user and check if this is a link to a subpage
var user = nonPrefixedTitle.replace(/[/#].*/, );
var isSubpage = user !== nonPrefixedTitle;
if (isSubpage && noSubpages) return;
/*
* Don't mark the current anchor if the last anchor was for the same user and of a certain type
* Consective links are basically in the order of "user -> usertalk -> contribs" or "contribs -> usertalk".
* We don't want to mark hierarchically-lower-level consective links.
*/
var prev;
/*
* Check whether this is a consective link that follows a master link, which is the top of the hierarchy.
* "prev" being an empty object always means that the last anchor wasn't marked; hence the current anchor can
* be marked. If "prev" is NOT an empty object, the current anchor can be marked only if it and the last anchor
* are for different users AND the current anchor is not one at a lower level in the hierarchy.
*/
if (!isSubpage && (prev = previousUsers[i - 1]) && !$.isEmptyObject(prev) && prev.username === user) {
if (prev.pagetype === 'user' && pagetype === 'usertalk' ||
prev.pagetype === 'usertalk' && pagetype === 'contribs' ||
prev.pagetype === 'contribs' && pagetype === 'usertalk'
) {
// This anchor won't be marked but the next loop will need this anchor's information
previousUsers[i] = {username: user, pagetype: pagetype}; // Update
return;
}
}
var userM = marker[user];
if (userM === undefined) { // Marker has yet to be created
// User groups of selected user
var usergroups = MarkAdmins.usersData ? MarkAdmins.usersData[user] : null;
if (!usergroups) return;
// Create marker
userM = usergroups
.filter(function(g) {
return typeof enabledGroups[g] !== 'undefined';
})
.map(function(g) {
return enabledGroups[g];
})
.join('/');
if (userM) userM = '(' + userM + ')';
marker[user] = userM;
}
if (!userM) return; // Are there markers at all?
// Check finished, now mark the user
a.dataset.groupmarker = marker[user];
a.classList.add('adminMark');
// Now that the current anchor has been marked, the "prev" object for it should not be empty since it's empty
// only when the anchor isn't marked
previousUsers[i] = {username: user, pagetype: pagetype};
});
}
};
MarkAdmins.init();
// @ts-ignore "Cannot find name 'mediaWiki'."
}(mediaWiki, jQuery));
//