Skip to content
alexz-enwp edited this page Dec 30, 2014 · 1 revision

Category objects are a subclass of Page objects, with a few extra functions specific to categories.

Constructor

The constructor for Category is identical to Page, minus the namespace option. If no "Category:" prefix is in the title, it will be added automatically.

Methods

Most of the methods of the Category class are the same as in Page, with a few additional ones.

getCategoryInfo

getCategoryInfo(force=False)

Returns a dict with some basic information about the category: the total number of items in the category, the number of ordinary pages, the number of files, and the number of subcategories. After retrieving, it will be cached in the object. To override and get it from the server again, set force to True.

getAllMembers

getAllMembers(titleonly=False, namespaces=None)

Gets all of the items in the category in a list. By default it will return Page objects. If you only want the titles, set titleonly to True. Can be limited to namespaces by passing an array of Namespaces or integer namespace numbers.

getAllMembersGen

getAllMembersGen(titleonly=False, namespaces=None)

Has the same options as getAllMembers, except it works as a generator function, retrieving a few results at a time and yielding individual Pages or titles.

Private methods

  • __getMembersInternal() - Does the API queries for getAllMembers/getAllMembersGen

Instance variables

Public

Category has the same instance variables as Page, with one additional variable.

Examples

Get information about a category and get the members

from wikitools import wiki, category
site = wiki.Wiki("https://www.mediawiki.org/w/api.php")
c = category.Category(site, "Category:Wiki markup")
print(str( c.getCategoryInfo() ))
for p in c.getAllMembersGen():
    print(p.title)

will output

{'subcats': 0, 'pages': 6, 'files': 0, 'size': 6}
Manual:CSS
Manual:MediaWiki Developer's Guide
Manual:ISBN
Manual:Parser functions
Manual:RFC
UNC links
Clone this wiki locally