User:Sam Sailor/Scripts/ReviewStatus.js

// <nowiki> // Forked from [[User:Novem Linguae/Scripts/ReviewStatus.js]] at [[Special:PermanentLink/1220711120]] // Added id-tracking and guard clause to…

// <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="https://en.wikipedia.org/w/extensions/PageTriage/modules/ext.pageTriage.toolbar/images/pageInfo/icon_reviewed.png" title="Reviewed" />';
        } else {
            htmlToInsert = ' <img id="mw-review-status-icon" src="https://en.wikipedia.org/w/extensions/PageTriage/modules/ext.pageTriage.toolbar/images/pageInfo/icon_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]]

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.