User:Firefly/more-block-info.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
![]() | This user script seems to have a documentation page at User:Firefly/more-block-info. |
function getWarningboxLocked(username, logid, datetime, lockActor, lockComment) {
console.log(logid);
return `<div class="warningbox mw-warning-with-logexcerpt mw-content-ltr" dir="ltr" lang="en" > <p> This account is currently globally locked. The latest <span class="plainlinks" ><a class="external text" href="https://meta.wikimedia.org/wiki/Special:CentralAuth/${username}" >global account change log</a ></span > entry is provided below for reference: </p> <ul class="mw-logevent-loglines"> <li> <a href="https://meta.wikimedia.org/w/index.php?title=Special:Log&logid=${logid}" >${datetime}</a > <a href="https://meta.wikimedia.org/wiki/User:${lockActor}" class="mw-userlink userlink" title="User:${lockActor}" ><bdi>${lockActor}</bdi></a > <span class="mw-usertoollinks mw-changeslist-links" ><span ><a href="https://meta.wikimedia.org/wiki/User_talk:${lockActor}" class="mw-usertoollinks-talk userlink" title="User talk:${lockActor}" >talk</a ></span > <span ><a href="https://meta.wikimedia.org/wiki/Special:Contributions/${lockActor}" class="mw-usertoollinks-contribs userlink" title="Special:Contributions/${lockActor}" >contribs</a ></span ></span > changed status for global account <a href="https://meta.wikimedia.org/wiki/Special:CentralAuth/${username}" class="mw-userlink userlink user-blocked-indef" ><bdi>${username}</bdi></a > <span class="mw-usertoollinks mw-changeslist-links" ><span ><a href="/wiki/User_talk:${username}" class="mw-usertoollinks-talk userlink user-blocked-indef" >talk</a ></span > <span ><a href="/wiki/Special:Contributions/${username}" class="mw-usertoollinks-contribs userlink user-blocked-indef" >contribs</a ></span ></span > : set locked; unset (none) <span class="comment">(${lockComment})</span> </li> </ul> <a href="https://meta.wikimedia.org/wiki/Special:CentralAuth/${username}">View full log</a> </div>`;
}
// Shamelessly nicked from [[User:GeneralNotability/mark-locked.js]]
async function moreBlockDisplay_isLocked(user) {
const api = new mw.Api();
try {
const response = await api.get({
action: "query",
list: "globalallusers",
agulimit: "1",
agufrom: user,
aguto: user,
aguprop: "lockinfo",
});
if (response.query.globalallusers.length === 0) {
// If the length is 0, then we couldn't find the global user
return false;
}
// If the 'locked' field is present, then the user is locked
return "locked" in response.query.globalallusers[0];
} catch (error) {
return false;
}
}
async function moreBlockDisplay_getLockLogEntry(user) {
const api = new mw.Api();
try {
const response = await $.post("https://meta.wikimedia.org/w/api.php", {
action: "query",
list: "logevents",
lelimit: "1",
letitle: `User:${user}@global`,
leaction: "globalauth/setstatus",
origin: "*",
format: "json",
});
let logEvent = response.query.logevents[0];
let retVal = {
logid: logEvent.logid,
lockActor: logEvent.user,
lockComment: logEvent.comment,
};
return retVal;
} catch (error) {
return undefined;
}
}
$.when($.ready, mw.loader.using("mediawiki.util")).then(async function() {
if (mw.config.get("wgPageName").includes("Special:Contributions/")) {
const relevantUserName = mw.config.get("wgRelevantUserName");
const userLocked = await moreBlockDisplay_isLocked(relevantUserName);
if (userLocked) {
const lockLogEntry = await moreBlockDisplay_getLockLogEntry(
relevantUserName
);
const lockedBox = getWarningboxLocked(
relevantUserName,
lockLogEntry.logid,
lockLogEntry.lockActor,
lockLogEntry.lockComment
);
$("a[title='m:Global locks']").parent().remove(); // Remove "this account is globally locked" box
$(".mw-contributions-blocked-notice").after(lockedBox);
}
}
});