API:Categorymembers
From MediaWiki.org
| This page is part of the MediaWiki API documentation. |
| Language: | English |
|---|
Quick overview:
- Quick start guide
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Search suggestions
- Expanding templates and rendering
- Purging pages' caches
- Parameter information
- Changing wiki content
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
| MediaWiki version: | 1.11 |
List of pages that belong to a given category, ordered by page sort title.
Contents |
Parameters [edit]
cmtitle: The category to enumerate (required). Must include Category: prefix. Cannot be used together withcmpageid.cmpageid: Page ID of the category to enumerate. Cannot be used together withcmtitle.cmnamespace: Only list pages in these namespacescmtype: Type of category members to include (page, subcat or file; separate with '|'). Ignored whencmsort=timestampis set. Default:page|subcat|filecmstart: Start listing at this timestamp. Can only be used withcmsort=timestampcmend: End listing at this timestamp. Can only be used withcmsort=timestampcmstartsortkey: Start listing at this hexadecimal sortkey. Can only be used withcmsort=sortkeycmendsortkey: End listing at this hexadecimal sortkey. Can only be used withcmsort=sortkeycmstartsortkeyprefix: Start listing at this sortkey prefix. Can only be used withcmsort=sortkey. Overridescmstartsortkeycmendsortkeyprefix: End listing before (not at) this sortkey prefix (if this value occurs it will not be included). Can only be used withcmsort=sortkey. Overridescmendsortkeycmsort: Property to sort bysortkey: The article's sort key (default)timestamp: The time the article was added to the category (or the categorization, i.e. the sortkey, was changed)
cmdir: Direction to sort inasc: From A to Z or from 2002 to 2013. Note: cmstart has to be before cmenddesc: From Z to A or from 2013 to 2002 Note: cmstart has to be later than cmend
cmlimit: Maximum amount of pages to list (10 by default, "max" provides all members (up to 500 for normal accounts, 5000 for bot accounts))cmprop: Which properties to get (separate with '|'). Default:ids|titleids: page ID (default)title: page title (default)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)type: type that the page has been categorised as (page, subcat or file) MW 1.18+timestamp: time and date the article was added to the category
cmcontinue: Used to continue a previous request. Format of cmcontinue is "type|hexsortkey|pageid". When used to continue query then new cmstartsortkey value is decoded value of hexsortkey.
Example [edit]
Get the 10 articles most recently added to Category:Physics
| Result |
|---|
| The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <query-continue> <categorymembers cmcontinue="Magnetic levitation|" /> </query-continue> <query> <categorymembers> <cm pageid="1653925" ns="100" title="Portal:Physics" /> <cm pageid="22939" ns="0" title="Physics" /> <cm pageid="3445246" ns="0" title="Glossary of classical physics" /> <cm pageid="25856" ns="0" title="Radiation" /> <cm pageid="16212316" ns="14" title="Category:Gravitation" /> <cm pageid="24489" ns="0" title="List of basic physics topics" /> <cm pageid="4412382" ns="0" title="Friability" /> <cm pageid="1111581" ns="0" title="Reaction (physics)" /> <cm pageid="16178400" ns="0" title="Normal (optics)" /> <cm pageid="14476384" ns="0" title="Mass versus weight" /> </categorymembers> </query> </api> |
| The above content has been placed in a collapsed box for improved usability. |
Error Codes [edit]
- code: cmnotitle
- info: The cmtitle parameter is required
- code: cminvalidcategory
- info: The category name you entered is not valid
- code: cmbadcontinue
- info: Invalid continue param. You should pass the original value returned by the previous query
Retrieving via AJAX [edit]
Below is sample code for retrieving the category list via an Ajax request:
function asyncGetCategoryList( categoryName ) { $.ajax({ url: mw.util.wikiScript( 'api' ), data: { // For parameter documentation, visit <http://en.wikipedia.org/w/api.php> and then search for "list=categorymembers" format: 'json', action: 'query', list: 'categorymembers', cmtitle: 'Category:' + categoryName, cmtype: 'subcat', }, dataType: 'json', type: 'GET', success: function( data ) { if ( data && data.query && data.query.categorymembers ) { // ... success ... } else if ( data && data.error ) { // Will this ever happen?? alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info ); } else { alert( 'Error: Unknown result from API.' ); } }, error: function( xhr ) { // ... error ... } }); }