User:VanesaPerea/Sandbox/API:Deletedrevisions

From mediawiki.org
MediaWiki version:
1.23

API documentation[edit]


list=deletedrevs (dr)

(main | query | deletedrevs)
  • This module is deprecated.
  • This module requires read rights.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

List deleted revisions.

Operates in three modes:

  1. List deleted revisions for the given titles, sorted by timestamp.
  2. List deleted contributions for the given user, sorted by timestamp (no titles specified).
  3. List all deleted revisions in the given namespace, sorted by title and timestamp (no titles specified, druser not set).

Certain parameters only apply to some modes and are ignored in others.

Specific parameters:
Other general parameters are available.
drstart

The timestamp to start enumerating from.

Modes: 1, 2
Type: timestamp (allowed formats)
drend

The timestamp to stop enumerating at.

Modes: 1, 2
Type: timestamp (allowed formats)
drdir

In which direction to enumerate:

newer
List oldest first. Note: drstart has to be before drend.
older
List newest first (default). Note: drstart has to be later than drend.
Modes: 1, 3
One of the following values: newer, older
Default: older
drfrom

Start listing at this title.

Mode: 3
drto

Stop listing at this title.

Mode: 3
drprefix

Search for all page titles that begin with this value.

Mode: 3
drunique

List only one revision for each page.

Mode: 3
Type: boolean (details)
drnamespace

Only list pages in this namespace.

Mode: 3
One of the following values: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 90, 91, 92, 93, 100, 101, 102, 103, 104, 105, 106, 107, 486, 487, 710, 711, 828, 829, 1198, 1199, 2600, 5500, 5501
Default: 0
drtag

Only list revisions tagged with this tag.

druser

Only list revisions by this user.

Type: user, by any of username, IP, Temporary user, interwiki name (e.g. "prefix>ExampleName") and user ID (e.g. "#12345")
drexcludeuser

Don't list revisions by this user.

Type: user, by any of username, IP, Temporary user, interwiki name (e.g. "prefix>ExampleName") and user ID (e.g. "#12345")
drprop

Which properties to get:

revid
Adds the revision ID of the deleted revision.
parentid
Adds the revision ID of the previous revision to the page.
user
Adds the user who made the revision.
userid
Adds the ID of the user who made the revision.
comment
Adds the comment of the revision.
parsedcomment
Adds the parsed comment of the revision.
minor
Tags if the revision is minor.
len
Adds the length (bytes) of the revision.
sha1
Adds the SHA-1 (base 16) of the revision.
content
Adds the content of the revision. For performance reasons, if this option is used, drlimit is enforced to 50.
token
Deprecated. Gives the edit token.
tags
Tags for the revision.
Values (separate with | or alternative): comment, content, len, minor, parentid, parsedcomment, revid, sha1, tags, user, userid, token
Default: user|comment
drlimit

The maximum amount of revisions to list. If drprop=content is used, the limit is 50.

Type: integer or max
The value must be between 1 and 500.
Default: 10
drcontinue

When more results are available, use this to continue. More detailed information on how to continue queries can be found on mediawiki.org.

Examples:
List the last deleted revisions of the pages MediaWiki and Talk:Main Page, with content (mode 1).
api.php?action=query&list=deletedrevs&titles=MediaWiki|Talk%3AMediaWiki&drprop=user|comment|content [open in sandbox]
List the last 50 deleted contributions by Bob (mode 2).
api.php?action=query&list=deletedrevs&druser=Bob&drlimit=50 [open in sandbox]
List the first 50 deleted revisions in the main namespace (mode 3).
api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50 [open in sandbox]
List the first 50 deleted pages in the Talk namespace (mode 3).
api.php?action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=1&drunique= [open in sandbox]

Example[edit]

GET request[edit]

Get a list of deleted revisions for Talk:Main Page.


Response[edit]

{
 "warnings":

{"main":{"

    *":"Unrecognized parameter: drv."}},

 "batchcomplete":"",

"query":

{"pages":

  {"-1":

    {"ns":1,
     "title":"Talk:Main Page",
     "missing":"",
     "deletedrevisions":
      [
{
        "revid":18588,
        "parentid":0,
        "user":"Bugambilia",
        "timestamp":"2018-09-16T12:03:00Z",
        "comment":"Created page with \"Hello everyone.\""},
      {
        "revid":16337,
        "parentid":0,
        "user":"31.31.98.23",
        "anon":"",
        "timestamp":"2017-09-25T22:17:24Z",
        "comment":"\u0416\u0435\u043d\u0430 \u041a\u043e\u0437\u043b\u0435\u0432\u0438\u0447\u0430"},
      {
        "revid":15676,
        "parentid":0,
        "user":"107.178.41.5",
        "anon":"",
        "timestamp":"2017-07-21T18:37:00Z",
        "comment":"Created page with \"<big><big><big>BBBBBBBBBBWWWWWWWWWWWWAAAAAAAAAAAHHHHHHHHHHHHH</big></big></big>\""},
      {
        "revid":15431,
        "parentid":14827,
        "user":"83.24.18.86",
        "anon":"",
        "timestamp":"2017-06-11T18:37:42Z",
        "comment":""},
      {
        "revid":14827,
        "parentid":0,
        "user":"Xauroflaux",
        "timestamp":"2017-04-09T01:43:39Z",
        "comment":"Created blank page"},
      {
        "revid":14816,
        "parentid":0,
        "userhidden":"",
        "user":"Butt cheeks",
        "timestamp":"2017-04-08T19:58:54Z",
        "commenthidden":"",
        "comment":"Created page with \"Butt cheeks Butt cheeks Butt cheeks Butt cheeks Butt cheeks Butt cheeks Butt cheeks Butt cheeks Butt cheeks Butt cheeks Butt cheeks Butt cheeks Butt cheeks Butt cheeks Butt ch...\""}]}}}}

Sample code[edit]

Python[edit]

"""
    get_deleted_revs.py

    MediaWiki Action API Code Samples
    Demo of `Deleted Revisions:Get a list of deleted revision for Talk:Main Page` module
    MIT license
"""

import requests

S = requests.Session()

URL = "https://en.wikipedia.org/w/api.php"

PARAMS = {
    'action':"query",
    'format':"json",
    'titles':"Talk:MainPage",
    'prop':"deletedrevisions",
    'drv':"prop"
}

R = S.get(url=URL, params=PARAMS)
DATA = R.json()

print(DATA)

PHP[edit]

<?php
/*
    get_deleted_revs.php

    MediaWiki API Demos
    Demo of `Deleted revisions:Get a list of deleted revision for Talk:Main Page` module

    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "query",
    "format" => "json",
    "titles" => "Talk:MainPage",
    "prop"   => "deletedrevisions",
    "drv"    => "prop"
];

$url = $endPoint . "?" . http_build_query( $params );

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );

$result = json_decode( $output, true );

echo( $result );

Javascript[edit]

/*
    get_deleted_revs.js

    MediaWiki API Demos
    Demo of `Deleted revisions:Get a list of deleted revision for Talk:Main Page` module

    MIT License
*/

var url = "https://en.wikipedia.org/w/api.php"; 

var params = {
    action: "query",
    format: "json",
    titles: "Talk:MainPage",
    prop:   "deletedrevisions",
    drv:    "prop"
};

url = url + "?origin=*";
Object.keys(params).forEach(function(key){url += "&" + key + "=" + params[key];});

fetch(url)
    .then(function(response){return response.json();})
    .then(function(response) {
        console.log(response);
    })
    .catch(function(error){console.log(error);});


Possible errors[edit]

Code Info
drvdiffto drvdiffto must be set to a non-negative number, "prev", "next" or "cur"
drvnosuchrevid There is no revision with ID ID
drvnosuchsection There is no section section in rID
drvpermissiondenied You don't have permission to view deleted revision information
adrpermissiondenied You don't have permission to view deleted revision content
drvbadparams user and excludeuser cannot be used together

Parameter history[edit]

  • v1.32: Deprecated drvcontentformat
  • v1.30: Deprecated rvdifftotext, rvdifftotextpst, rvdiffto, rvexpandtemplates, rvparse and rvprop=parsetree

Additional notes[edit]

  • This module can be used as a generator.
  • This module lists revisions that have been deleted from a page, as you would see in Special:Undelete. It should not be confused with revisions that have been hidden via the Revision Delete feature.

See also[edit]