User:Novem Linguae/Scripts/ReviewStatus.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:Novem Linguae/Scripts/ReviewStatus. |
// <nowiki>
/*
- Displays whether or not a mainspace page is marked as reviewed. This info is placed on the right of the page title.
- Without a script like this, you need to be a new page reviewer or admin and look at the Page Curation toolbar. Or you need to use Special:Log -> Page Curation Log. And there is also some complex logic. For example, the absence of a log entry means the page is marked as reviewed.
*/
$(async function() {
async function isReviewed(pageID) {
let api = new mw.Api();
let response = await api.get( {
action: 'pagetriagelist',
format: 'json',
page_id: pageID,
} );
// no result
if ( response.pagetriagelist.result !== 'success' || response.pagetriagelist.pages.length === 0 ) {
return true;
// 1, 2, or 3
} else if ( parseInt(response.pagetriagelist.pages[0].patrol_status) > 0 ) {
return true;
// 0
} else {
return false;
}
}
function shouldRunOnThisPage(title) {
// don't run when not viewing articles
let action = mw.config.get('wgAction');
if ( action != 'view' ) {
return false;
}
// don't run when viewing diffs
let isDiff = mw.config.get('wgDiffNewId');
if ( isDiff ) {
return false;
}
let isDeletedPage = ( ! mw.config.get('wgCurRevisionId') );
if ( isDeletedPage ) {
return false;
}
// Only run in mainspace
let namespace = mw.config.get('wgNamespaceNumber');
let isMainspaceOrDraftspace = ( [0].includes(namespace) );
if ( ! isMainspaceOrDraftspace ) {
return false;
}
return true;
}
let title = mw.config.get('wgPageName'); // includes namespace, underscores instead of spaces
if ( ! shouldRunOnThisPage(title) ) {
return;
}
let pageID = mw.config.get('wgArticleId');
let boolIsReviewed = await isReviewed(pageID);
if ( boolIsReviewed ) {
$(`#firstHeading`).append(` (Reviewed)`);
} else {
$(`#firstHeading`).append(` (Not Reviewed)`);
}
});
// </nowiki>