User:Novem Linguae/Scripts/ReviewStatus.js: Difference between revisions

Content deleted Content added
create
 
fix linter errors
 
(18 intermediate revisions by the same user not shown)
Line 2:
 
/*
- Displays whether or not a mainspace page is marked as reviewed. This info is placed on the right of the page title using a small icon.
- 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.
*/
 
// TODO: display whether the page is indexed or not. can do this by using JS to look for "noindex", or can do this by checking the first revision date.
$(async function() {
// TODO: display in all namespaces
async function isReviewed(pageID) {
// TODO: do I need to use different code to check if marked as patrolled? I think that uses recentchanges table... maybe?
let api = new mw.Api();
 
let response = await api.get( {
class ReviewStatus {
action: 'pagetriagelist',
async execute() {
format: 'json',
if ( ! this.shouldRunOnThisPage(title) ) {
page_id: pageID,
} ) return;
}
 
const pageID = mw.config.get( 'wgArticleId' );
let const boolIsReviewed = await this.isReviewed(title pageID );
let htmlToInsert = '';
 
// modules/ext.pageTriage.views.toolbar/images/icons/
 
if ( boolIsReviewed ) {
// no result
htmlToInsert = ' <img src="https://en.wikipedia.org/w/extensions/PageTriage/modules/ext.pageTriage.toolbar/images/pageInfo/icon_reviewed.png" title="Reviewed" />';
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 {
htmlToInsert = ' <img src="https://en.wikipedia.org/w/extensions/PageTriage/modules/ext.pageTriage.toolbar/images/pageInfo/icon_not_reviewed.png" title="Not reviewed" />';
return false;
}
 
if ( this.pageHasSections() ) {
$( '#firstHeading .mw-editsection' ).before( htmlToInsert );
} else {
$(` '#firstHeading`' ).append(` (Reviewed)`htmlToInsert );
}
}
 
/**
function shouldRunOnThisPage(title) {
* @param {number} pageID The page ID number. A positive number with no commas.
*/
async function isReviewed( pageID ) {
letconst api = new mw.Api();
letconst response = await api.get( {
action: 'pagetriagelistquery',
format: 'json',
formatversion: '2',
prop: 'isreviewed',
page_idpageids: pageID,
//} 0);
return response.query.pages[ 0 ].isreviewed;
}
 
function shouldRunOnThisPage(title) {
// don't run when not viewing articles
letconst action = mw.config.get( 'wgAction' );
if ( action !== 'view' ) {
return false;
}
 
// don't run when viewing diffs
letconst isDiff = mw.config.get( 'wgDiffNewId' );
if ( isDiff ) {
return false;
}
 
letconst isDeletedPage = ( ! mw.config.get( 'wgCurRevisionId' ) );
if ( isDeletedPage ) {
return false;
}
 
// Only run in mainspace
letconst namespace = mw.config.get( 'wgNamespaceNumber' );
letconst isMainspaceOrDraftspace = ( [ 0 ].includes( namespace ) );
if ( ! isMainspaceOrDraftspace ) {
return false;
}
Line 55 ⟶ 78:
}
 
pageHasSections() {
let title = mw.config.get('wgPageName'); // includes namespace, underscores instead of spaces
return $( '#firstHeading .mw-editsection' ).length;
if ( ! shouldRunOnThisPage(title) ) {
return;
}
}
 
$( async function () {
let boolIsReviewed = await isReviewed(title);
await mw.loader.using( [ 'mediawiki.api' ], async function () {
if ( boolIsReviewed ) {
await ( new ReviewStatus() ).execute();
$(`#firstHeading`).append(` (Reviewed)`);
} else {);
} );
$(`#firstHeading`).append(` (Not Reviewed)`);
}
});
 
// </nowiki>