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 code will be executed when previewing this page.
Documentation for this user script can be added at User:Sam Sailor/Scripts/ReviewStatus.
// <nowiki>
// Forked from [[User:Novem Linguae/Scripts/ReviewStatus.js]] at [[Special:PermanentLink/1220711120]]
// Added id-tracking and guard clause to prevent double injection of icon.
class ReviewStatus {
async execute() {
if (!this.shouldRunOnThisPage()) {
return;
}
// Check if the icon already exists
if ($('#mw-review-status-icon').length) {
return;
}
const pageID = mw.config.get('wgArticleId');
const boolIsReviewed = await this.isReviewed(pageID);
let htmlToInsert = '';
// Add an ID to the image tag so we can track it
if (boolIsReviewed) {
htmlToInsert = ' <img id="mw-review-status-icon" src="http://wiki.nitrosworld.org/proxy-img/http%3A%2F%2Fen.wikipedia.org%2Fw%2Fextensions%2FPageTriage%2Fmodules%2Fext.pageTriage.toolbar%2Fimages%2FpageInfo%2Ficon_reviewed.png" title="Reviewed" />';
} else {
htmlToInsert = ' <img id="mw-review-status-icon" src="http://wiki.nitrosworld.org/proxy-img/http%3A%2F%2Fen.wikipedia.org%2Fw%2Fextensions%2FPageTriage%2Fmodules%2Fext.pageTriage.toolbar%2Fimages%2FpageInfo%2Ficon_not_reviewed.png" title="Not reviewed" />';
}
if (this.pageHasSections()) {
$('#firstHeading .mw-editsection').first().before(htmlToInsert);
} else {
$('#firstHeading').append(htmlToInsert);
}
}
/**
* @param {number} pageID The page ID number. A positive number with no commas.
*/
async isReviewed(pageID) {
const api = new mw.Api();
const response = await api.get({
action: 'query',
format: 'json',
formatversion: '2',
prop: 'isreviewed',
pageids: pageID
});
return response.query.pages[0].isreviewed;
}
shouldRunOnThisPage() {
// Don't run when not viewing articles
const action = mw.config.get('wgAction');
if (action !== 'view') {
return false;
}
// Don't run when viewing diffs
const isDiff = mw.config.get('wgDiffNewId');
if (isDiff) {
return false;
}
const isDeletedPage = (!mw.config.get('wgCurRevisionId'));
if (isDeletedPage) {
return false;
}
// Only run in mainspace
const namespace = mw.config.get('wgNamespaceNumber');
const isMainspaceOrDraftspace = ([0].includes(namespace));
if (!isMainspaceOrDraftspace) {
return false;
}
return true;
}
pageHasSections() {
return $('#firstHeading .mw-editsection').length;
}
}
$(async function() {
await mw.loader.using(['mediawiki.api'], async function() {
await (new ReviewStatus()).execute();
});
});
// </nowiki>
// [[Category:Wikipedia scripts|ReviewStatus]]