Page

class mwclient.page.Page(site, name, info=None, extra_properties=None)[source]

Represents a page on a MediaWiki wiki represented by a Site object.

Parameters:
  • site (mwclient.client.Site) – The site object this page belongs to.

  • name (Union[str, int, Page]) – The title of the page, the page ID, or another Page object to copy.

  • info (Optional[dict]) – Page info, if already fetched, e.g., when iterating over a list of pages. If not provided, the page info will be fetched from the API.

  • extra_properties (Optional[dict]) – Extra properties to fetch when initializing the page.

Examples

>>> site = mwclient.Site('en.wikipedia.org')
>>> page1 = Page(site, 'Main Page')
>>> page2 = Page(site, 123456)
>>> page3 = Page(site, 'Main Page', extra_properties={
...     'imageinfo': [
...         ('iiprop', 'timestamp|user|comment|url|size|sha1|metadata'),
...     ],
... })
append(text, summary='', minor=False, bot=True, section=None, **kwargs)[source]

Append text to a section or the whole page by performing an edit operation.

Parameters:
  • text (str)

  • summary (str)

  • minor (bool)

  • bot (bool)

  • section (str | None)

  • kwargs (Any)

Return type:

Any

List pages that link to the current page, similar to Special:Whatlinkshere.

API doc: https://www.mediawiki.org/wiki/API:Backlinks

Parameters:
  • namespace (str | int | None)

  • filterredir (str)

  • redirect (bool)

  • limit (int | None)

  • generator (bool)

  • max_items (int | None)

  • api_chunk_size (int | None)

Return type:

List

can(action)[source]

Check if the current user has the right to carry out some action with the current page.

Example

>>> page.can('edit')
True
Parameters:

action (str)

Return type:

bool

categories(generator=True, show=None)[source]

List categories used on the current page.

API doc: https://www.mediawiki.org/wiki/API:Categories

Parameters:
  • generator (bool) – Return generator (Default: True)

  • show (str | None) – Set to ‘hidden’ to only return hidden categories or ‘!hidden’ to only return non-hidden ones.

Returns:

mwclient.listings.PagePropertyGenerator

Return type:

PagePropertyGenerator | PageProperty

delete(reason='', watch=False, unwatch=False, oldimage=None)[source]

Delete page.

If user does not have permission to delete page, an InsufficientPermission exception is raised.

API doc: https://www.mediawiki.org/wiki/API:Delete

Parameters:
  • reason (str)

  • watch (bool)

  • unwatch (bool)

  • oldimage (str | None)

Return type:

Any

edit(text, summary='', minor=False, bot=True, section=None, **kwargs)[source]

Update the text of a section or the whole page by performing an edit operation.

Parameters:
  • text (str)

  • summary (str)

  • minor (bool)

  • bot (bool)

  • section (str | None)

  • kwargs (Any)

Return type:

Any

embeddedin(namespace=None, filterredir='all', limit=None, generator=True, max_items=None, api_chunk_size=None)[source]

List pages that transclude the current page.

API doc: https://www.mediawiki.org/wiki/API:Embeddedin

Parameters:
  • (Default (namespace Restricts search to a given namespace) – None)

  • filterredir (str) – How to filter redirects, either ‘all’ (default), ‘redirects’ or ‘nonredirects’.

  • limit (int | None) – The API request chunk size (deprecated)

  • generator (bool) – Return generator (Default: True)

  • max_items (int | None) – The maximum number of pages to yield

  • api_chunk_size (int | None) – The API request chunk size

  • namespace (str | int | None)

Returns:

Page iterator

Return type:

mwclient.listings.List

List external links from the current page.

API doc: https://www.mediawiki.org/wiki/API:Extlinks

Return type:

PageProperty

images(generator=True)[source]

List files/images embedded in the current page.

API doc: https://www.mediawiki.org/wiki/API:Images

Parameters:

generator (bool)

Return type:

PagePropertyGenerator | PageProperty

List interwiki links from the current page.

API doc: https://www.mediawiki.org/wiki/API:Iwlinks

Return type:

PageProperty

List interlanguage links from the current page.

API doc: https://www.mediawiki.org/wiki/API:Langlinks

Parameters:

kwargs (Any)

Return type:

PageProperty

List links to other pages from the current page.

API doc: https://www.mediawiki.org/wiki/API:Links

Parameters:
  • namespace (str | int | None)

  • generator (bool)

  • redirects (bool)

Return type:

PagePropertyGenerator | PageProperty

move(new_title, reason='', move_talk=True, no_redirect=False, move_subpages=False, ignore_warnings=False)[source]

Move (rename) page to new_title.

If user account is an administrator, specify no_redirect as True to not leave a redirect.

If user does not have permission to move page, an InsufficientPermission exception is raised.

API doc: https://www.mediawiki.org/wiki/API:Move

Parameters:
  • new_title (str)

  • reason (str)

  • move_talk (bool)

  • no_redirect (bool)

  • move_subpages (bool)

  • ignore_warnings (bool)

Return type:

Any

prepend(text, summary='', minor=False, bot=True, section=None, **kwargs)[source]

Prepend text to a section or the whole page by performing an edit operation.

Parameters:
  • text (str)

  • summary (str)

  • minor (bool)

  • bot (bool)

  • section (str | None)

  • kwargs (Any)

Return type:

Any

purge()[source]

Purge server-side cache of page. This will re-render templates and other dynamic content.

API doc: https://www.mediawiki.org/wiki/API:Purge

Return type:

None

redirects_to()[source]

Get the redirect target page, or None if the page is not a redirect.

Return type:

Page | None

resolve_redirect()[source]

Get the redirect target page, or the current page if its not a redirect.

Return type:

Page

revisions(startid=None, endid=None, start=None, end=None, dir='older', user=None, excludeuser=None, limit=None, prop='ids|timestamp|flags|comment|user', expandtemplates=False, section=None, diffto=None, slots=None, uselang=None, max_items=None, api_chunk_size=50)[source]

List revisions of the current page.

API doc: https://www.mediawiki.org/wiki/API:Revisions

Parameters:
  • startid (int | None) – Revision ID to start listing from.

  • endid (int | None) – Revision ID to stop listing at.

  • start (str | None) – Timestamp to start listing from.

  • end (str | None) – Timestamp to end listing at.

  • dir (str) – Direction to list in: ‘older’ (default) or ‘newer’.

  • user (str | None) – Only list revisions made by this user.

  • excludeuser (str | None) – Exclude revisions made by this user.

  • limit (int | None) – The API request chunk size (deprecated).

  • prop (str) – Which properties to get for each revision, default: ‘ids|timestamp|flags|comment|user’

  • expandtemplates (bool) – Expand templates in rvprop=content output

  • section (str | None) – Section number. If rvprop=content is set, only the contents of this section will be retrieved.

  • diffto (int | None) – Revision ID to diff each revision to. Use “prev”, “next” and “cur” for the previous, next and current revision respectively.

  • slots (str | None) – The content slot (Mediawiki >= 1.32) to retrieve content from.

  • uselang (str | None) – Language to use for parsed edit comments and other localized messages.

  • max_items (int | None) – The maximum number of revisions to yield.

  • api_chunk_size (int | None) – The API request chunk size (as a number of revisions).

Returns:

Revision iterator

Return type:

mwclient.listings.List

save(*args, **kwargs)[source]

Alias for edit, for maintaining backwards compatibility.

Parameters:
  • args (Tuple[str, Any])

  • kwargs (Any)

Return type:

Any

templates(namespace=None, generator=True)[source]

List templates used on the current page.

API doc: https://www.mediawiki.org/wiki/API:Templates

Parameters:
  • namespace (str | int | None)

  • generator (bool)

Return type:

PagePropertyGenerator | PageProperty

text(section=None, expandtemplates=False, cache=True, slot='main')[source]

Get the current wikitext of the page, or of a specific section.

If the page does not exist, an empty string is returned. By default, results will be cached and if you call text() again with the same section and expandtemplates the result will come from the cache. The cache is stored on the instance, so it lives as long as the instance does.

Parameters:
  • section (int | str | None) – Section number, to only get text from a single section.

  • expandtemplates (bool) – Expand templates (default: False)

  • cache (bool) – Use in-memory caching (default: True)

  • slot (str)

Return type:

Any

touch()[source]

Perform a “null edit” on the page to update the wiki’s cached data of it. This is useful in contrast to purge when needing to update stored data on a wiki, for example Semantic MediaWiki properties or Cargo table values, since purge only forces update of a page’s displayed values and not its store.

Return type:

None

class mwclient.listing.Category(site, name, info=None, namespace=None)[source]

Represents a category on a MediaWiki wiki represented by a Site object.

Parameters:
  • site (mwclient.client.Site) – The site object this page belongs to.

  • name (Union[str, int, Page]) – The title of the page, the page ID, or another Page object to copy.

  • info (Optional[dict]) – Page info, if already fetched, e.g., when iterating over a list of pages. If not provided, the page info will be fetched from the API.

  • namespace (Union[int, str, None]) – The namespace of the category members to list.