API:Categorymembers
From MediaWiki.org
| This page is part of the MediaWiki action API documentation. |
MediaWiki action API
- Introduction and quick start
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Searching (by title, content, coordinates...)
- Parsing wikitext and expanding templates
- Purging pages' caches
- Parameter information
- Changing wiki content
- Create and edit pages
- Move pages
- Merge pages
- Rollback
- Delete pages
- Restore deleted revisions
- (Un)protect pages
- (Un)block users
- (Un)watch pages
- Mark revisions of watched pages as visited
- Send email
- Patrol changes
- Import pages
- Change user group membership
- Upload files
- User options
- Tokens
- Page language
- More...
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
- Asserting
| Categorymembers | ||
|---|---|---|
This module can be used as a Generator. |
||
| Prefix | cm | |
| Required rights | none | |
| Post only? | No | |
| Generated help | Current | |
| Version added |
|
|
List of pages that belong to a given category, ordered by page sort title.
If you're using "cmcontinue" parameter for pages, the "cmtype=page" parameter is optional, but for subcategories (or files), the "cmtype=subcat" (or "cmtype=file") is necessary.
Parameters[edit]
cmtitle: The category to enumerate (required unlesscmpageidis used). 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. Ignored whencmsort=timestampis set. Possible values:page,subcat,file. (Default:page|subcat|file) 1.12+cmstart: Start listing at this timestamp. Can only be used withcmsort=timestamp1.12+cmend: End listing at this timestamp. Can only be used withcmsort=timestamp1.12+cmstarthexsortkey: Start listing at this hexadecimal sortkey. Can only be used withcmsort=sortkey. 1.24+cmendhexsortkey: End listing at this hexadecimal sortkey. Can only be used withcmsort=sortkey. 1.24+cmstartsortkeyprefix: Start listing at this sortkey prefix. Can only be used withcmsort=sortkey. Overridescmstarthexsortkey. 1.18+cmendsortkeyprefix: End listing before (not at) this sortkey prefix (if this value occurs it will not be included). Can only be used withcmsort=sortkey. Overridescmendhexsortkey. 1.18+cmsort: Property to sort by (Default:sortkey)sortkey: The article's sort key. The sort key might contain "unprintable" characters such as newlines, NULs, ASCII control characters, and so on. When returned from the API using cmprop=sortkey, the whole sortkey is encoded by converting the UTF-8 to a string of hex digits.timestamp: The time the article was added to the category (or the categorization, i.e. the sortkey, was changed)
cmdir: Direction to sort in. (Default:asc) 1.12+asc: From A to Z or from 2002 to 2017. As of MW 1.20,ascendingandnewerare synonymous withasc. Note:cmstarthas to be beforecmend.desc: From Z to A or from 2017 to 2002. As of MW 1.20,descendingandolderare synonymous withdesc. Note:cmstarthas to be later thancmend.
cmlimit: Maximum number of pages to list No more than 500 (5000 for bots) allowed. (Default: 10)cmprop: Which properties to get. (Default:ids|title)ids: Page IDtitle: Page titlesortkey: 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
cmcontinue: Used to continue a previous request.cmstartsortkey: Likecmstarthexsortkey, but the value is passed as a binary string rather than the hex-encoded value returned fromcmprop=sortkey. 1.14+ (Deprecated in 1.24)cmendsortkey: Likecmendhexsortkey, but the value is passed as a binary string rather than the hex-encoded value returned fromcmprop=sortkey. 1.14+ (Deprecated in 1.24)
Example[edit]
Standard syntax: list 10 pages in a category (e.g. Category:Physics)
| Result |
|---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<query-continue>
<categorymembers cmcontinue="page|5355524641434520534349454e4345|68513" />
</query-continue>
<query>
<categorymembers>
<cm pageid="22688097" ns="0" title="Branches of physics" />
<cm pageid="3445246" ns="0" title="Glossary of classical physics" />
<cm pageid="24489" ns="0" title="Outline of physics" />
<cm pageid="22939" ns="0" title="Physics" />
<cm pageid="1653925" ns="100" title="Portal:Physics" />
<cm pageid="151066" ns="0" title="Classical physics" />
<cm pageid="685311" ns="0" title="Experimental physics" />
<cm pageid="23581364" ns="0" title="Microphysics" />
<cm pageid="844186" ns="0" title="Modern physics" />
<cm pageid="28481" ns="0" title="Statistical mechanics" />
</categorymembers>
</query>
</api>
|
List 20 items in the Category:Physics
| Result |
|---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<query-continue>
<categorymembers cmcontinue="subcat|44594e414d494353|10998823" />
</query-continue>
<query>
<categorymembers>
<cm pageid="22688097" ns="0" title="Branches of physics" />
<cm pageid="3445246" ns="0" title="Glossary of classical physics" />
<cm pageid="24489" ns="0" title="Outline of physics" />
<cm pageid="22939" ns="0" title="Physics" />
<cm pageid="1653925" ns="100" title="Portal:Physics" />
<cm pageid="151066" ns="0" title="Classical physics" />
<cm pageid="685311" ns="0" title="Experimental physics" />
<cm pageid="23581364" ns="0" title="Microphysics" />
<cm pageid="844186" ns="0" title="Modern physics" />
<cm pageid="28481" ns="0" title="Statistical mechanics" />
<cm pageid="68513" ns="0" title="Surface science" />
<cm pageid="36477012" ns="14" title="Category:Concepts in physics" />
<cm pageid="694942" ns="14" title="Category:Physicists" />
<cm pageid="1913676" ns="14" title="Category:Applied and interdisciplinary physics" />
<cm pageid="2865233" ns="14" title="Category:Atomic, molecular, and optical physics" />
<cm pageid="5625591" ns="14" title="Category:Physics awards" />
<cm pageid="735875" ns="14" title="Category:Classical mechanics" />
<cm pageid="42703540" ns="14" title="Category:Physics competitions" />
<cm pageid="792595" ns="14" title="Category:Computational physics" />
<cm pageid="692176" ns="14" title="Category:Condensed matter physics" />
</categorymembers>
</query>
</api>
|
Get the 10 articles most recently added to Category:Physics
api.php? action=query& list=categorymembers& cmtitle=Category:Physics& cmsort=timestamp& cmdir=desc [try in ApiSandbox]
| Result |
|---|
<?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>
|
Get the 10 subcategories of Category:Wikipedia
api.php? action=query& list=categorymembers& cmtitle=Category:Wikipedia& cmtype=subcat [try in ApiSandbox]
| Result |
|---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<query-continue>
<categorymembers cmcontinue="subcat|57494b4950454449412050454f504c45|41491664" />
</query-continue>
<query>
<categorymembers>
<cm pageid="1458692" ns="14" title="Category:Wikipedias by language" />
<cm pageid="22918730" ns="14" title="Category:Books about Wikipedia" />
<cm pageid="16957584" ns="14" title="Category:Critics of Wikipedia" />
<cm pageid="29605819" ns="14" title="Category:Films about Wikipedia" />
<cm pageid="3646304" ns="14" title="Category:History of Wikipedia" />
<cm pageid="42635523" ns="14" title="Category:Wikipedia-related lists" />
<cm pageid="34012839" ns="14" title="Category:Organisations using QRpedia" />
<cm pageid="22773532" ns="14" title="Category:Parodies of Wikipedia" />
<cm pageid="3102055" ns="14" title="Category:Websites which use Wikipedia" />
<cm pageid="42600182" ns="14" title="Category:Wikipedia controversies" />
</categorymembers>
</query>
</api>
|
Continue the next subcategories (if there's more than 10) in Category:Wikipedia (the "cmcontinue" parameter is from the result above)
api.php? action=query& list=categorymembers& cmtitle=Category:Wikipedia& cmtype=subcat& cmcontinue=subcat|57494b4950454449412050454f504c45|41491664 [try in ApiSandbox]
| Result |
|---|
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0"?>
<api>
<query>
<categorymembers>
<cm pageid="41491664" ns="14" title="Category:Wikipedia people" />
<cm pageid="31645152" ns="14" title="Category:Wikipedia reliability" />
<cm pageid="38144992" ns="14" title="Category:Wikipedia terminology" />
</categorymembers>
</query>
</api>
|
Error Codes[edit]
| Code | Info |
|---|---|
| cmnotitle | The cmtitle parameter is required |
| cminvalidcategory | The category name you entered is not valid |
| cmbadcontinue | Invalid continue param. You should pass the original value returned by the previous query |