Implement mediawiki.api method to check if a page is in a certain category
Open, Needs TriagePublic

Description

<Technical_13> Could you please review my idea http://pastebin.com/sHce6E7T and possibly add it to https://phabricator.wikimedia.org/diffusion/MW/change/master/resources/src/mediawiki/api/category.js
<Krinkle> Technical_13: Could you file a task on phabricator and tag with MediaWiki-API, JavaScript, Easy?
..
<Technical_13> So, If I'm on Category:Pages_starting_with_A and I want to see if one of the members in that category is also in Category:Pages_ending_with_Z --- this will do it.
<Krinkle> Technical_13: So you'll call this method once for every member?
<Technical_13> Yes.

Restricted Application added subscribers: Zppix, TerraCodes, Aklapper. · View Herald TranscriptMay 17 2016, 7:14 PM
Krinkle renamed this task from mw.Api.hasCategory() to Implement mediawiki.api method to check if a page is in a certain category.May 17 2016, 7:18 PM
Krinkle removed Krinkle as the assignee of this task.
Krinkle updated the task description. (Show Details)
Krinkle added a subscriber: Krinkle.

It sounds like you want a method to check that a category contains a certain page. (Or rather, that a page is in a certain category).

However for your given use case, what you really want is intersection. Making a query for every page separately isn't a very efficient way to do that. There is probably a better API for this, not sure which one though.

Anomie added a subscriber: Anomie.May 17 2016, 10:11 PM

So, If I'm on Category:Pages_starting_with_A and I want to see if one of the members in that category is also in Category:Pages_ending_with_Z

Using the API directly, you'd use something like action=query&generator=categorymembers&gcmtitle=Category:Pages_starting_with_A&gcmlimit=max&prop=categories&clcategories=Category:Pages_ending_with_Z&cllimit=max

Breaking that down,

  • generator=categorymembers tells it that you're wanting to query pages in a category.
  • gcmtitle=Category:Pages_starting_with_A names the category.
  • gcmlimit=max tells it to give you 500 or 5000 pages at a time, instead of only 10.
  • prop=categories tells it you want to get the list of categories for each page being queried.
  • clcategories=Category:Pages_ending_with_Z tells it you don't care about all categories those pages might be in, just Category:Pages_ending_with_Z
  • cllimit=max tells it to give you 500 or 5000 categories at a time, instead of only 10.

Then you'd look through the results to see which of the pages are in Category:Pages_ending_with_Z.

To do intersection even more efficiently, there might be some CirrusSearch magic you can do with list=search, or you could see if PetScan has an API.

Krinkle removed a subscriber: Krinkle.Mar 6 2017, 7:51 PM