MediaWiki Database

This module provides a set of convenience function for detecting revert status via a mwdb database connection.

mwreverts.db.check(schema, rev_id, page_id=None, radius=15, before=None, window=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 mwdb
>>> import mwreverts.api
>>>
>>> schema = mwdb.Schema("mysql+pymysql://enwiki.labsdb/enwiki_p" +
                         "?read_default_file=~/replica.my.cnf")
>>>
>>> def print_revert(revert):
...     if revert is None:
...         print(None)
...     else:
...         print(revert.reverting['rev_id'],
...               [r['rev_id'] for r in revert.reverteds],
...               revert.reverted_to['rev_id'])
...
>>> reverting, reverted, reverted_to = \
...     mwreverts.db.check(schema, 679778587)
>>> print_revert(reverting)
None
>>> print_revert(reverted)
679778743 [679778587] 679742862
>>> print_revert(reverted_to)
None
mwreverts.db.check_archive(schema, rev_id, namespace=None, title=None, timestamp=None, radius=15, before=None, window=None)[source]

Checks the revert status of an archived revision (from a deleted page). 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

namespace
: int

the namespace ID of the page the revision exists in

title
: str

the title of the page the revision exists in

timestamp
: mwtypes.Timestamp

the timestamp that the revision for rev_id was saved

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

  • 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