API:Delete
This page is part of the MediaWiki action API documentation. |
MediaWiki action API
- Introduction and quick start
- FAQ
- Tutorial
- Formats
- Error reporting
- Restricting usage
- Cross-site requests
- Authentication
- Queries
- Searching (by title, content, coordinates...)
- Parsing wikitext and expanding templates
- Purging pages' caches
- Parameter information
- Changing wiki content
- Create and edit pages
- Move pages
- Merge pages
- Rollback
- Delete pages
- Restore deleted revisions
- (Un)protect pages
- (Un)block users
- (Un)watch pages
- Mark revisions of watched pages as visited
- Send email
- Patrol changes
- Import pages
- Change user group membership
- Upload files
- User options
- Tokens
- Page language
- More...
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
- Asserting
Delete | ||
---|---|---|
Delete a page. This module cannot be used as a Generator . |
||
Prefix | none | |
Required rights | delete | |
Post only? | Yes | |
Generated help | Current | |
Version added |
|
Token[edit]
To delete a page, a CSRF token is required. The CSRF token is the same for all pages, but changes at every login. CSRF tokens can be obtained via action=query&meta=tokens
with type=csrf
(MW 1.24+). For older versions, you can use API:Tokens (action) or API:Info to get an edit token.
Deleting pages[edit]
Pages can be deleted with action=delete. In addition to the delete right, other rights may be required, depending on the location and type of page. Deleting a user's .css page, for example, also requires the editusercss right.
Parameters[edit]
One of title
or pageid
must be set.
title
: The page you want to delete.pageid
: The page id of the page you want to delete. 1.14+token
: The CSRF token obtained as per the Tokens section, above. Take care to urlencode the trailing+\
as%2B%5C
.reason
: The reason for the deletion (optional). If not provided, an automatically generated reason will be used.tags
: Change tags to apply to the entry in the deletion log. 1.27+watch
: Add the page to your watchlist. 1.13+ (Deprecated in 1.17)unwatch
: Remove the page from your watchlist. 1.13+ (Deprecated in 1.17)watchlist
: Add the page to your watchlist. Possible values:watch
,unwatch
,preferences
,nochange
. (Default:preferences
)oldimage
: The name of the old image to delete as provided byaction=query&prop=imageinfo&iiprop=archivename
. 1.13+
Example[edit]
Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=delete
requires POST requests; GET requests will cause an error.
Deleting the Main Page with an auto-generated reason
Result |
---|
{
"delete": {
"title": "Main Page",
"reason": "content was: 'content goes here' and the only contributor was Username",
"logid": 1234567
}
}
|
Possible errors[edit]
In addition to the usual stuff:
Code | Info |
---|---|
notitle | The title parameter must be set |
notoken | The token parameter must be set |
permissiondenied | You don't have permission to delete pages Note: On most wikis, deleting pages is restricted to sysops, but other wikis may have stricter rules. |
cantdelete | Couldn't delete "title". Maybe it was deleted already by someone else |
The following documentation is the output of Special:ApiHelp/delete, automatically generated by the pre-release version of MediaWiki that is running on this site (MediaWiki.org). |
action=delete
- This module requires read rights.
- This module requires write rights.
- This module only accepts POST requests.
- Source: MediaWiki
- License: GPL-2.0+
Delete a page.
- title
-
Title of the page to delete. Cannot be used together with pageid.
- pageid
-
Page ID of the page to delete. Cannot be used together with title.
- Type: integer
- reason
-
Reason for the deletion. If not set, an automatically generated reason will be used.
- tags
-
Change tags to apply to the entry in the deletion log.
- Values (separate with | or alternative):
- watch
- Deprecated.
-
Add the page to the current user's watchlist.
- Type: boolean (details)
- watchlist
-
Unconditionally add or remove the page from the current user's watchlist, use preferences or do not change watch.
- One of the following values: watch, unwatch, preferences, nochange
- Default: preferences
- unwatch
- Deprecated.
-
Remove the page from the current user's watchlist.
- Type: boolean (details)
- oldimage
-
The name of the old image to delete as provided by action=query&prop=imageinfo&iiprop=archivename.
- token
-
A "csrf" token retrieved from action=query&meta=tokens
- This parameter is required.
- Delete Main Page.
- api.php?action=delete&title=Main%20Page&token=123ABC [open in sandbox]
- Delete Main Page with the reason Preparing for move.
- api.php?action=delete&title=Main%20Page&token=123ABC&reason=Preparing%20for%20move [open in sandbox]