API:Edit - Protect

From MediaWiki.org

Jump to: navigation, search
This page is part of the MediaWiki API documentation.
MediaWiki API


MediaWiki version: 1.12

Contents

[edit] Token

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

api.php ? action=query & prop=info & intoken=protect & titles=Main%20Page

<?xml version="1.0" encoding="utf-8"?>
<api>
  <query>
    <pages>
      <page
        pageid="1"
      counter="20"
        length="470"
        protecttoken="58b54e0bab4a1d3fd3f7653af38e75cb+\" 
      />
    </pages>
  </query>
</api>

[edit] Protecting pages

Pages can be protected with action=protect.

[edit] Parameters

  • 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 as action=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.
  • expiry: Expiry timestamp in GNU timestamp format. If set to 'infinite', 'indefinite, 'never', or not set at all, the protection will never expire. Timestamps like 'next Monday 16:04:57' or '9:28 PM tomorrow' are also allowed.
  • 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.
    • This 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.

[edit] Examples

Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=edit requires POST requests; GET requests will cause an error.

Protecting the Main Page edit=autoconfirmed, move=sysop, expiring October 24, 2007 at 16:07:54 and with cascading protection enabled.

api.php ? action=protect & title=Main%20Page & protections=edit=autoconfirmed|move=sysop & expiry=20071024160754 & cascade & token=58b54e0bab4a1d3fd3f7653af38e75cb%2B\

<?xml version="1.0" encoding="utf-8"?>
<api>
  <protect title="Main Page" reason="" expiry="24-10-2007T16:07:54Z" cascade="">
      <protections edit="autoconfirmed" move="sysop" />
  </protect>
</api>
Protecting "Deletion log" create=sysop, expiring a 2 months from now

api.php ? action=protect & title=Deletion%20log & protections=create=sysop & expiry=2%20months & reason=Don't%20create%20this%20for%20now & token=58b54e0bab4a1d3fd3f7653af38e75cb%2B\

<?xml version="1.0" encoding="utf-8"?>
<api>
  <protect title="Deletion log" reason="Don't create this for now" expiry="2008-03-08T16:34:30Z">
    <protections create="sysop" />
  </protect>
</api>

[edit] Possible errors

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
      • This means the expiry timestamp was invalidly formatted, or is nonexistent (like November 31 or 24:05).
  • code: pastexpiry
    • info: Expiry time is in the past
  • 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'
Personal tools