Page MenuHomePhabricator

Concise API call to figure out the reviewed status of a page
Closed, ResolvedPublicFeature

Description

Feature summary
For a wiki using PageTriage, it is complicated to figure out if a page is reviewed. The algorithm is basically to SQL query the pagetriage_page table, see if your page_id is in there, then read the ptrp_status field, which can have a value of 0, 1, 2, or 3. Your page not being in the table and getting no result at all is also a frequent occurrence. So 1, 2, 3, or missing is basically "reviewed", and 0 is "unreviewed".

This logic should be moved to an API call, so our developers don't need to implement this logic themselves.

Benefits (why should this be implemented?):

  • Less cognitive load on programmers
  • More concise code for programmers

Acceptance criteria

  • Should take title (namespace:title) or pageid, like the query API does
  • Should return isReviewed: true/false, or throw a "page does not exist" type error, or a "not a namespace pagetriage patrols" error

After code review, instead of making a new API, may be best to add this to query->prop.

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald Transcript

(only now noticed you wrote most of that @Novem_Linguae 😅)

I saw this and thought "great idea!", but a vague memory was telling me this already exists — and it does! 😄

Call api.php?action=pagetriagelist&format=json&page_id=70233586 for example and get:

{
    "pagetriagelist": {
        "result": "success",
        "pages_missing_metadata": [],
        "pages": [
            {
                "pageid": 70233586,
                "linkcount": "6",
                "creation_date": "20220305110659",
                "patrol_status": "0",
                "is_redirect": "0",
                "ptrp_last_reviewed_by": "0",
                "ptrp_reviewed_updated": "20220305110659",
                "reviewer": null,
                "title": "Moscow Automobile and Road Construction State Technical University",
                "category_count": "15",
                "csd_status": "0",
                "prod_status": "0",
                "blp_prod_status": "0",
                "afd_status": "0",
                "rev_count": "13",
                "page_len": "4945",
                "snippet": "Moscow Automobile and Road Construction State Technical University () is a public university located in Moscow, Russia. It was founded in 1930. History The Moscow State Automobile and Road Technical University (MADI) was established by a decree of the...",
                "user_name": "GronGronsky",
                "user_editcount": "506",
                "user_creation_date": "20210125150823",
                "user_autoconfirmed": "1",
                "user_bot": "0",
                "user_block_status": "0",
                "user_id": "41067402",
                "reference": "1",
                "user_experience": "experienced",
                "afc_state": "1",
                "copyvio": "",
                "recreated": "",
                "creation_date_utc": "20220305110659",
                "creator_user_page": "User:GronGronsky",
                "creator_user_page_url": "//en.wikipedia.org/wiki/User:GronGronsky",
                "creator_user_page_exist": true,
                "creator_user_talk_page": "User talk:GronGronsky",
                "creator_user_talk_page_url": "//en.wikipedia.org/wiki/User_talk:GronGronsky",
                "creator_user_talk_page_exist": true,
                "creator_contribution_page": "Special:Contributions/GronGronsky",
                "creator_contribution_page_url": "//en.wikipedia.org/wiki/Special:Contributions/GronGronsky",
                "talk_page_title": "Talk:Moscow Automobile and Road Construction State Technical University",
                "talkpage_feedback_count": 0,
                "talk_page_url": "https://en.wikipedia.org/wiki/Talk:Moscow_Automobile_and_Road_Construction_State_Technical_University",
                "ores_articlequality": "Start",
                "ores_draftquality": ""
            }
        ]
    }
}

I was thinking of implementing it as a new PageTriage API that just takes a page_id and outputs isReviewed true/false. Or maybe a hook into some other API that fetches pages, if that kind of API hooking capability exists. One problem with using pagetriagelist is that it will often return no rows, and then the end user is left confused about whether the page is reviewed or not (counter-intuitively, no rows = reviewed).

Here is how I currently do it in JavaScript. Having help on the API side would let us get rid of all the conditional logic at the bottom there.

	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;
		}
	}

For what it's worth, you can trim that down to

// no result
if ( response.pagetriagelist.result !== 'success' || response.pagetriagelist.pages.length === 0 ) {
    return true;
} else {
    // Convert the patrol_status to a boolean — 0 is falsy and >0 truthy
    return Boolean( parseInt( response.pagetriagelist.pages[0].patrol_status ) );
}

Change 860984 had a related patch set uploaded (by Novem Linguae; author: Novem Linguae):

[mediawiki/extensions/PageTriage@master] Concise API call to figure out the reviewed status of a page

https://gerrit.wikimedia.org/r/860984

Change 860984 abandoned by Novem Linguae:

[mediawiki/extensions/PageTriage@master] Concise API call to figure out the reviewed status of a page

Reason:

Sounds like this should be in API:Query+prop instead of its own API. See code review comment.

https://gerrit.wikimedia.org/r/860984

Change 942386 had a related patch set uploaded (by Novem Linguae; author: Novem Linguae):

[mediawiki/extensions/PageTriage@master] [WIP] add ?action=query&prop=isreviewed to API

https://gerrit.wikimedia.org/r/942386

Test wiki created on Patch demo by TheresNoTime using patch(es) linked to this task:
https://patchdemo.wmflabs.org/wikis/c6a18892b9/w

Test wiki on Patch demo by TheresNoTime using patch(es) linked to this task was deleted:

https://patchdemo.wmflabs.org/wikis/c6a18892b9/w/

Change 942386 merged by jenkins-bot:

[mediawiki/extensions/PageTriage@master] add ?action=query&prop=isreviewed to API

https://gerrit.wikimedia.org/r/942386

Change 943613 had a related patch set uploaded (by Novem Linguae; author: Novem Linguae):

[mediawiki/extensions/PageTriage@master] refactor ApiIsReviewed to use injection

https://gerrit.wikimedia.org/r/943613

Change 943613 merged by jenkins-bot:

[mediawiki/extensions/PageTriage@master] Refactor ApiIsReviewed to use injection

https://gerrit.wikimedia.org/r/943613