API:Categorymembers

From MediaWiki.org
Jump to: navigation, search
Tools clipart.png This page is part of the MediaWiki API documentation.
MediaWiki API

Quick overview:

v · d · e


MediaWiki version: 1.11

List of pages that belong to a given category, ordered by page sort title.

Parameters[edit | edit source]

  • cmtitle: The category to enumerate (required unless cmpageid is used). Must include "Category:" prefix. Cannot be used together with cmpageid.
  • cmpageid: Page ID of the category to enumerate. Cannot be used together with cmtitle.
  • cmnamespace: Only list pages in these namespaces
  • cmtype: Type of category members to include. Ignored when cmsort=timestamp is set. Possible values: page, subcat, file. (Default: page|subcat|file) 1.12+
  • cmstart: Start listing at this timestamp. Can only be used with cmsort=timestamp 1.12+
  • cmend: End listing at this timestamp. Can only be used with cmsort=timestamp 1.12+
  • cmstarthexsortkey: Start listing at this hexadecimal sortkey. Can only be used with cmsort=sortkey. 1.24+
  • cmendhexsortkey: End listing at this hexadecimal sortkey. Can only be used with cmsort=sortkey. 1.24+
  • cmstartsortkeyprefix: Start listing at this sortkey prefix. Can only be used with cmsort=sortkey. Overrides cmstarthexsortkey. 1.18+
  • cmendsortkeyprefix: End listing before (not at) this sortkey prefix (if this value occurs it will not be included). Can only be used with cmsort=sortkey. Overrides cmendhexsortkey. 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 2014. As of MW 1.20, ascending and newer are synonymous with asc. Note: cmstart has to be before cmend.
    • desc: From Z to A or from 2014 to 2002. As of MW 1.20, descending and older are synonymous with desc. Note: cmstart has to be later than cmend.
  • 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 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
  • cmcontinue: Used to continue a previous request.
  • cmstartsortkey: Like cmstarthexsortkey, but the value is passed as a binary string rather than the hex-encoded value returned from cmprop=sortkey. 1.14+ (deprecated in 1.24)
  • cmendsortkey: Like cmendhexsortkey, but the value is passed as a binary string rather than the hex-encoded value returned from cmprop=sortkey. 1.14+ (deprecated in 1.24)

Example[edit | edit source]

Standard syntax: list 10 pages in a category (e.g. Category:Physics)

List 20 items in the Category:Physics, it will list its 11 pages, and 9 subcategories

Get the 10 articles most recently added to Category:Physics

Get the 10 subcategories of Category:Wikipedia

Continue the next subcategories (if there's more than 10) in Category:Wikipedia (the "cmcontinue" parameter is from the result above)

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.

Error Codes[edit | edit source]

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