API:Protect
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 |
Token[edit | edit source]
To change a page's protection level, a protect token is required. This token is equal to the edit token and the same for all pages, but changes at every login. A protect token can be obtained as follows: Obtaining a protect token
Result |
---|
The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <query> <pages> <page pageid="1" counter="20" length="470" protecttoken="58b54e0bab4a1d3fd3f7653af38e75cb+\" /> </pages> </query> </api> |
The above content has been placed in a collapsed box for improved usability. |
Protecting pages[edit | edit source]
Pages can be protected with action=protect.
Parameters[edit | edit source]
title
: The page you want to protect.token
: The token obtained in the previous request. Take care to urlencode the+
as%2B
.protections
: A pipe-separated list of protections, formatted asaction=group
, e.g.edit=autoconfirmed|move=sysop
- If you want to remove a protection, use
all
as group, e.g.edit=all|move=sysop
- If you leave out an action, the associated value won't be changed, i.e.
edit=sysop
leaves the move protection untouched.
- If you want to remove a protection, use
expiry
: Pipe-separated list of expiry timestamps in GNU timestamp format. The first timestamp applies to the first protection inprotections
, the second to the second, etc. The timestampsinfinite
,indefinite
andnever
result in a protection that will never expire. Timestamps likenext Monday 16:04:57
or9:28 PM tomorrow
are also allowed, see the GNU web site for details.- The number of expiry timestamps must equal the number of protections, or you'll get an error message
- An exception to this rule is made for backwards compatibility: if you specify exactly one expiry timestamp, it'll apply to all protections
- Not setting this parameter is equivalent to setting it to
infinite
- The number of expiry timestamps must equal the number of protections, or you'll get an error message
reason
: The reason for the (un)protection (optional).cascade
: If set, pages transcluded in the protected page will also be protected. If the required user level to edit is lower than the required user level to protect (e.g. edit=autoconfirmed), cascading can't be enabled, and this parameter will be silently ignored.- The latter is to prevent people who shouldn't be able to protect pages from protecting them anyway by transcluding them in a page with cascading protection.
Examples[edit | edit source]
Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=protect requires POST requests; GET requests will cause an error. Protecting the Main Page edit=autoconfirmed, move=sysop, the first expiring October 24, 2007 at 16:07:54, the second never, with cascading protection enabled.
Result |
---|
The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <protect title="Main Page" reason="" cascade=""> <protections> <protection edit="autoconfirmed" expiry="24-10-2007T16:07:54Z" /> <protection move="sysop" expiry="infinite" /> </protections> </protect> </api> |
The above content has been placed in a collapsed box for improved usability. |
Protecting "Deletion log" create=sysop, expiring a 2 months from now
Result |
---|
The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <protect title="Deletion log" reason="Don't create this for now"> <protections> <protection create="sysop" expiry="2008-03-08T16:34:30Z" /> </protections> </protect> </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: notitle
- info: The title parameter must be set
- code: notoken
- info: The token parameter must be set
- code: noprotections
- info: The protections parameter must be set
- code: invalidexpiry
- info: Invalid expiry time ``expiry''
- This means the expiry timestamp was invalidly formatted, or is nonexistent (like November 31 or 24:05).
- info: Invalid expiry time ``expiry''
- code: pastexpiry
- info: Expiry time ``expiry'' is in the past
- code: toofewexpiries
- info: number expiry timestamps were provided where number were needed
- Note that this error is misnamed: it's also thrown when you specify too many expiry times
- info: number expiry timestamps were provided where number were needed
- code: cantedit
- info: You can't protect this page because you can't edit it
- code: create-titleexists
- info: Existing titles can't be protected with 'create'
- code: missingtitle-createonly
- info: Missing titles can only be protected with 'create'
- code: protect-invalidaction
- info: Invalid protection type ``type''
- code: protect-invalidlevel
- info: Invalid protection level ``level''