API:Watchlistraw

From MediaWiki.org
Jump to navigation Jump to search
MediaWiki version: 1.14

GET Request to list all the pages on the logged in user's watchlist, regardless of whether they were recently changed or not.

This module can be used as a generator .

API documentation[edit]


list=watchlistraw (wr)

(main | query | watchlistraw)
  • This module requires read rights.
  • This module can be used as a generator.
  • Source: MediaWiki
  • License: GPL-2.0-or-later

Get all pages on the current user's watchlist.

Parameters:
wrcontinue

When more results are available, use this to continue.

wrnamespace

Only list pages in the given namespaces.

Values (separate with | or alternative): 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, 828, 829, 1198, 1199, 2300, 2301, 2302, 2303, 2600, 5500, 5501
To specify all values, use *.
wrlimit

How many total results to return per request.

No more than 500 (5,000 for bots) allowed.
Type: integer or max
Default: 10
wrprop

Which additional properties to get:

changed
Adds timestamp of when the user was last notified about the edit.
Values (separate with | or alternative): changed
wrshow

Only list items that meet these criteria.

Values (separate with | or alternative): changed, !changed
wrowner

Used along with wrtoken to access a different user's watchlist.

Type: user name
wrtoken

A security token (available in the user's preferences) to allow access to another user's watchlist.

wrdir

The direction in which to list.

One of the following values: ascending, descending
Default: ascending
wrfromtitle

Title (with namespace prefix) to begin enumerating from.

wrtotitle

Title (with namespace prefix) to stop enumerating at.

Examples:
List pages on the current user's watchlist.
api.php?action=query&list=watchlistraw [open in sandbox]
Fetch page info for pages on the current user's watchlist.
api.php?action=query&generator=watchlistraw&gwrshow=changed&prop=info [open in sandbox]

Example[edit]

GET Request[edit]

Get three pages on the logged-in user's watchlist from the main namespace.

Response[edit]

{
  "batchcomplete": "",
  "continue": {
    "continue": "-||",
    "wrcontinue": "0|Software"
  },
  "watchlistraw": [
    {
      "ns": 0,
      "title": "Free and open-source software"
    },
    {
      "ns": 0,
      "title": "Free software"
    },
    {
      "ns": 0,
      "title": "Proprietary software"
    }
  ]
}

Sample code[edit]

get_watchlistraw.py

#!/usr/bin/python3

"""
    get_watchlistraw.py

    MediaWiki API Demos
    Demo of `Watchlistraw` module: Get three pages on the logged-in user's
    watchlist from the main namespace.

    MIT License
"""

import requests

S = requests.Session()

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

# Step 1: Retrieve a login token
PARAMS_1 = {
    "action": "query",
    "meta": "tokens",
    "type": "login",
    "format": "json"
}

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

LOGIN_TOKEN = DATA['query']['tokens']['logintoken']

# Step 2: Send a post request to log in. For this login
# method, Obtain bot credentials by visiting
# https://en.wikipedia.org/wiki/Special:BotPasswords/
# See https://www.mediawiki.org/wiki/API:Login for more
# information on log in methods.
PARAMS_2 = {
    "action": "login",
    "lgname": "username",
    "lgpassword": "password",
    "format": "json",
    "lgtoken": LOGIN_TOKEN
}

R = S.post(URL, data=PARAMS_2)

# Step 3: While logged in, get the watchlist
PARAMS_3 = {
    "action": "query",
    "list": "watchlistraw",
    "format": "json",
    "wrnamespace": "0",
    "wrlimit": "3"
}

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

print(DATA)

Possible errors[edit]

Code Info
bad_wlowner Specified user does not exist.
bad_wltoken Incorrect watchlist token provided -- please set a correct token in Special:Preferences.
notloggedin You must be logged-in to have a watchlist.
show Incorrect parameter - mutually exclusive values may not be supplied.

Parameter history[edit]

  • v1.20: Introduced wrdir
  • v1.17: Introduced wrowner, wrtoken

Additional notes[edit]

  • This module should not be confused with API:Watchlist, which returns pages on the current user's watchlist that were changed within the given time period, ordered by time of the last change of the watched page.
  • The results of this query module are returned as part of the api node, not the query node.

See also[edit]

  • API:Watchlist - Get pages on a user's watchlist that were changed within the given time period, ordered by time of the last change of the watched page.
  • API:Watchlist feed - Get the RSS feed of a user's watchlist.