API:Block
From MediaWiki.org
![]() |
This page is part of the MediaWiki API documentation. |
Language: | English • Deutsch • 日本語 |
---|
Quick overview:
- Quick start guide
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Search suggestions
- Parsing wikitext and expanding templates
- Purging pages' caches
- Parameter information
- Changing wiki content
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
MediaWiki version: | = 1.12 |
Contents
Token[edit | edit source]
To (un)block a user, a(n) (un)block token is required. This token is equal to the edit token and the same for all blocks, but changes at every login. A(n) (un)block token can be obtained the following ways:
Obtaining a block token
Result |
---|
The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0"?> <api> <query> <pages> <page ns="2" title="User:Bob" missing="" starttimestamp="2008-10-27T12:15:36Z" blocktoken="101089c295402adff96016ca002480c8+\" /> </pages> </query> </api> |
The above content has been placed in a collapsed box for improved usability. |
Obtaining an unblock token
Result |
---|
The following content has been placed in a collapsed box for improved usability. |
<<?xml version="1.0"?> <api> <query> <pages> <page ns="2" title="User:Bob" missing="" starttimestamp="2008-10-27T12:15:36Z" unblocktoken="101089c295402adff96016ca002480c8+\" /> </pages> </query> </api> |
The above content has been placed in a collapsed box for improved usability. |
Blocking users[edit | edit source]
Users can be blocked with action=block.
Parameters[edit | edit source]
user
: The username, IP address or IP range you want to block.token
: The token obtained in the previous request. Take care to urlencode the+
as%2B
.expiry
: Expiry timestamp. Relative expiry times, like5 months
or2 weeks
are also accepted. If set toinfinite
,infinity
,never
, or not set at all, the block will never expire.reason
: The reason for the block (optional).anononly
: If set, only anonymous logins from the user's IP will be blocked, thus forcing the user to log in or create an account in order to be able to edit.nocreate
: If set, block account creation from the user's IP.autoblock
: If set, automatically block the IP address last used by this user, and any subsequent IPs they try to login from.noemail
: If set, prevent the user from sending email through Special:Emailuser.
Example[edit | edit source]
Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=block requires POST requests; GET requests will cause an error. Blocking Bob for 1 day, disabling account creation and email
Result |
---|
The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <block user="Bob" userID="147" expiry="20070906231113" reason="Time out" nocreate="" noemail="" /> </api> |
The above content has been placed in a collapsed box for improved usability. |
Possible errors[edit | edit source]
In addition to the usual stuff:
- code: nouser
- info: The user parameter must be set
- code: notoken
- info: The token parameter must be set
- code: permissiondenied
- info: You don't have permission to block users
- On most wikis, blocking users is restricted to sysops, but other wikis may have stricter rules.
- info: You don't have permission to block users
- code: invalidrange
- info: Invalid IP range
- code: rangedisabled
- info: Blocking IP ranges has been disabled
- code: invalidip
- info: Invalid IP address specified
- code: invalidexpiry
- info: Invalid expiry time
- code: alreadyblocked
- info: The user you tried to block was already blocked
- code: pastexpiry
- info: Expiry time is in the past
- code: cantblock
- info: You don't have permission to block users
- code: canthide
- info: You don't have permission to hide user names from the block log
- This feature has to be enabled explicitly in LocalSettings.php.
- info: You don't have permission to hide user names from the block log
- code: cantblock-email
- info: You don't have permission to block users from sending e-mail through the wiki
Unblocking users[edit | edit source]
Users can be unblocked with action=unblock.
Parameters[edit | edit source]
id
: The ID of the block you want to undo. Block IDs can be obtained through list=blocksuser
: The username, IP address or IP range you want to unblock.token
: The token obtained in the previous request. Take care to urlencode the+
as%2B
.gettoken
: If set, a token will be returned.reason
: The reason for the unblock (optional).
Sample request[edit | edit source]
Unblocking Bob, and apologizing
Result |
---|
The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <unblock id="17" user="Bob" reason="Sorry Bob" /> </api> |
The above content has been placed in a collapsed box for improved usability. |
Possible errors[edit | edit source]
In addition to the usual stuff:
- code: notarget
- info: Either the id or the user parameter must be set
- code: notoken
- info: The token parameter must be set
- code: idanduser
- info: The id and user parameters can't be used together
- code: blockedasrange
- info: IP address ``address'' was blocked as part of range ``range''. You can't unblock the IP invidually, but you can unblock the range as a whole.
- code: cantunblock
- info: The block you specified was not found. It may have been unblocked already
- code: permissiondenied
- info: You don't have permission to unblock users
- On most wikis, unblocking users is restricted to sysops, but other wikis may have stricter rules.
- info: You don't have permission to unblock users