Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mediawiki API: How do I list all pages of a category and for each page show all of it's categories?

I am using the following wikimedia API to list all pages with a certain category: https://www.mediawiki.org/wiki/API:Categorymembers

E.g. https://en.wikipedia.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Physics

This gives me a list of pages with title and id, but I would also like to see all categories for each page. However it seems that there is no cmprop for that.

cmprop: Which properties to get. (Default: ids|title)

    ids: Page ID
    title: Page title
    sortkey: The sortkey used for sorting in the category (hexadecimal string)
    sortkeyprefix: The sortkey prefix used for sorting in the category (human-readable part of the sortkey) 1.17+
    type: Type that the page has been categorised as (page, subcat or file) 1.17+
    timestamp: Time and date the article was added to the category

I have considered to query each page and use prop=categories to get the categories for each page, but that would mean a very large number of queries. Is there any better way of doing this?

like image 405
Rickard Olsson Avatar asked Jan 29 '15 20:01

Rickard Olsson


People also ask

How do I see all categories in Wikipedia?

Categories allow readers to navigate through Wikipedia and find related articles. Categories are not displayed in the mobile version. Mobile users can click "Desktop" at the bottom of a page to see the desktop version with categories. Registered users can enable Advanced mode which includes a "Categories" button.

How do I create a category in MediaWiki?

Creating a category page A category is created by creating a page in the Category: namespace. A category page can be created the same way as other wiki pages (see Help:Starting a new page ); just add " Category: " before the page title. To avoid extra work, try searching within your wiki before creating a new category.

How do you add pages to categories on fandom?

Simply scroll down to the bottom of a page and: Click on the Add category button, and start typing in a category name. You can use an already-established category (suggestions will appear as you type) or add a new one.


1 Answers

You can use categorymembers as a generator. If you do that, you can then apply prop=categories:

https://en.wikipedia.org/w/api.php?action=query&generator=categorymembers&gcmtitle=Category:Physics&prop=categories&cllimit=max&gcmlimit=max

like image 194
svick Avatar answered Sep 22 '22 23:09

svick