Given any category, I need to get the main article for the same if it exists.
Asked
Active
Viewed 82 times
1 Answers
0
You can use Mediawiki action API to get the information about the category like namespace, name, sortkeyprefix. As an example the query for category:Telegraphy produced as on today
{
"batchcomplete": "",
"continue": {
"cmcontinue": "page|2c322a4c304e4032320450324032364c2a4838011701dcbddc0c|21155313",
"continue": "-||"
},
"query": {
"categorymembers": [
{
"pageid": 30010,
"ns": 0,
"title": "Telegraphy",
"sortkey": "04030650324032364c2a48385a011001c4dc0d",
"sortkeyprefix": " ",
"type": "page",
"timestamp": "2018-05-18T16:59:21Z"
},
{
"pageid": 35475502,
"ns": 0,
"title": "Acme Commodity and Phrase Code",
"sortkey": "2a2e4232042e46424246303a505a042a44300448384c2a4e32042e463032012201dcc2dcb9dcc0dc07",
"sortkeyprefix": "",
"type": "page",
"timestamp": "2012-04-12T20:44:45Z"
},
....
}
In the results, the page for which the sortkeyprefix is space ( "sortkeyprefix": " " for the article "Telegraphy") is the main article for category.
In English Wikipedia you may find sometimes the main article for the category by the use of "Template:Cat main" along with brief description. If you need to find such usages also, then you need to get the Wikitext for the category page and look for the usage of that template. (Example)

arjunaraoc
- 129
- 5