MediaWiki API

This module provides a set of convenience function for detecting revert status via a MediaWiki API.

mwreverts.api.check(session, rev_id, page_id=None, radius=15, before=None, window=None, rvprop=None)[source]

Checks the revert status of a revision. With this method, you can determine whether an edit is a ‘reverting’ edit, was ‘reverted’ by another edit and/or was ‘reverted_to’ by another edit.

Parameters:
session
: mwapi.Session

An API session to make use of

rev_id
: int

the ID of the revision to check

page_id
: int

the ID of the page the revision occupies (slower if not provided)

radius
: int

a positive integer indicating the maximum number of revisions that can be reverted

before
: mwtypes.Timestamp

if set, limits the search for reverting revisions to those which were saved before this timestamp

window
: int

if set, limits the search for reverting revisions to those which were saved within window seconds after the reverted edit

rvprop
: set( str )

a set of properties to include in revisions

Returns:

A triple mwreverts.Revert | None

  • reverting – If this edit reverted other edit(s)
  • reverted – If this edit was reverted by another edit
  • reverted_to – If this edit was reverted to by another edit
Example:
>>> import mwapi
>>> import mwreverts.api
>>>
>>> session = mwapi.Session("https://en.wikipedia.org")
>>>
>>> def print_revert(revert):
...     if revert is None:
...         print(None)
...     else:
...         print(revert.reverting['revid'],
...               [r['revid'] for r in revert.reverteds],
...               revert.reverted_to['revid'])
...
>>> reverting, reverted, reverted_to =         ...     mwreverts.api.check(session, 679778587)
>>> print_revert(reverting)
None
>>> print_revert(reverted)
679778743 [679778587] 679742862
>>> print_revert(reverted_to)
None
mwreverts.api.check_deleted(session, rev_id, title=None, timestamp=None, radius=15, before=None, window=None, rvprop=None)[source]

Checks the revert status of a deleted revision. With this method, you can determine whether an edit is a ‘reverting’ edit, was ‘reverted’ by another edit and/or was ‘reverted_to’ by another edit.

Parameters:
session
: mwapi.Session

An API session to make use of

rev_id
: int

the ID of the revision to check

title
: str

the title of the page the revision occupies (slower if not provided) Note that the MediaWiki API expects the title to include the namespace prefix (e.g. “User_talk:EpochFail”)

radius
: int

a positive integer indicating the maximum number of revisions that can be reverted

before
: mwtypes.Timestamp

if set, limits the search for reverting revisions to those which were saved before this timestamp

window
: int

if set, limits the search for reverting revisions to those which were saved within window seconds after the reverted edit

rvprop
: set( str )

a set of properties to include in revisions

Returns:

A triple mwreverts.Revert | None

  • reverting – If this edit reverted other edit(s)
  • reverted – If this edit was reverted by another edit
  • reverted_to – If this edit was reverted to by another edit