This page is a translated version of the page API:Blocks and the translation is 100% complete.

GET请求 列出当前被封禁的用户,和Special:BlockList排序的方式相同

MediaWiki版本:
1.12

API文档

list=blocks (bk)

(main | query | blocks)

List all blocked users and IP addresses.

Specific parameters:
Other general parameters are available.
bkstart

The timestamp to start enumerating from.

Type: timestamp (allowed formats)
bkend

The timestamp to stop enumerating at.

Type: timestamp (allowed formats)
bkdir

In which direction to enumerate:

newer
List oldest first. Note: bkstart has to be before bkend.
older
List newest first (default). Note: bkstart has to be later than bkend.
One of the following values: newer, older
Default: older
bkids

List of block IDs to list (optional).

Type: list of integers
Separate values with | or alternative.
Maximum number of values is 50 (500 for clients that are allowed higher limits).
bkusers

List of users to search for (optional).

Type: list of users, by any of username, IP, Temporary user and IP range
Separate values with | or alternative.
Maximum number of values is 50 (500 for clients that are allowed higher limits).
bkip

Get all blocks applying to this IP address or CIDR range, including range blocks.

Cannot be used together with bkusers. CIDR ranges broader than IPv4/16 or IPv6/19 are not accepted.

bklimit

The maximum number of blocks to list.

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

Which properties to get:

id
Adds the ID of the block.
user
Adds the username of the blocked user.
userid
Adds the user ID of the blocked user.
by
Adds the username of the blocking user.
byid
Adds the user ID of the blocking user.
timestamp
Adds the timestamp of when the block was given.
expiry
Adds the timestamp of when the block expires.
reason
Adds the reason given for the block.
range
Adds the range of IP addresses affected by the block.
flags
Tags the ban with (autoblock, anononly, etc.).
restrictions
Adds the partial block restrictions if the block is not sitewide.
Values (separate with | or alternative): by, byid, expiry, flags, id, range, reason, restrictions, timestamp, user, userid
Default: id|user|by|timestamp|expiry|reason|flags
bkshow

Show only items that meet these criteria.

For example, to see only indefinite blocks on IP addresses, set bkshow=ip|!temp.

Values (separate with | or alternative): !account, !ip, !range, !temp, account, ip, range, temp
bkcontinue

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

示例

列出最近的3笔封禁

GET请求

响应

{
    "batchcomplete": "",
    "continue": {
        "bkcontinue": "20190226192632|8865878",
        "continue": "-||"
    },
    "query": {
        "blocks": [
            {
                "id": 8865881,
                "user": "168.11.166.47",
                "by": "Gilliam",
                "timestamp": "2019-02-26T19:28:56Z",
                "expiry": "2020-02-26T19:28:56Z",
                "reason": "{{school block}}",
                "rangestart": "168.11.166.47",
                "rangeend": "168.11.166.47",
                "anononly": "",
                "nocreate": "",
                "allowusertalk": ""
            },
            {
                "id": 8865880,
                "user": "64.125.67.43",
                "by": "Gilliam",
                "timestamp": "2019-02-26T19:27:44Z",
                "expiry": "2019-03-01T19:27:44Z",
                "reason": "part of mass attack",
                "rangestart": "64.125.67.43",
                "rangeend": "64.125.67.43",
                "anononly": "",
                "nocreate": "",
                "allowusertalk": ""
            }
            ...
        ]
    }
}

示例代码

Python

#!/usr/bin/python3

"""
    get_blocked_users.py

    MediaWiki API Demos
    Demo of `Blocks` module: GET request to list recent blocked users

    MIT License
"""

import requests

S = requests.Session()

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

PARAMS = {
    "action": "query",
    "bklimit": "3",
    "list": "blocks",
    "bkprop": "id|user|by|timestamp|expiry|reason|range|flags",
    "format": "json"
}

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

print(DATA['query']['blocks'])

PHP

<?php
/*
    get_blocked_users.php

    MediaWiki API Demos
    Demo of `Blocks` module: GET request to list recent blocked users.

    MIT License
*/

$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
    "action" => "query",
    "format" => "json",
    "list" => "blocks",
    "bklimit" => "3",
    "bkprop" => "id|user|by|timestamp|expiry|reason|range|flags"
];

$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 );
var_dump( $result["query"]["blocks"] );

JavaScript

/*
    get_blocked_users.js

    MediaWiki API Demos
    Demo of `Blocks` module: GET request to list recent blocked users.

    MIT License
*/

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

var params = {
    action: "query",
    list: "blocks",
    bklimit: "3",
    bkprop: "id|user|by|timestamp|expiry|reason|range|flags",
    format: "json"
};

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.query.blocks);})
    .catch(function(error){console.log(error);});

MediaWiki JS

/*
	get_blocked_users.js

	MediaWiki API Demos
	Demo of `Blocks` module: GET request to list recent blocked users.

	MIT License
*/

var params = {
		action: 'query',
		list: 'blocks',
		bklimit: '3',
		bkprop: 'id|user|by|timestamp|expiry|reason|range|flags',
		format: 'json'
	},
	api = new mw.Api();

api.get( params ).done( function ( data ) {
	console.log( data.query.blocks );
} );

附加说明

参数历史

  • v1.19: 引入bkshow
  • v1.18: 引入userid

参见