API:Undelete
From MediaWiki.org
Language: | English • Deutsch • 日本語 • 한국어 |
---|
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
Undelete | ||
---|---|---|
Undelete a page or revision. This module cannot be used as a Generator . |
||
Prefix | none | |
Required rights | undelete | |
Post only? | Yes | |
Generated help | Current | |
Version added |
|
Token[edit]
You need to obtain an undelete token through list=deletedrevs before you can restore any revisions. This token is equal to the edit token and the same for all pages, but changes at every login. The preferred method to obtain an undelete token depends on the MediaWiki version:
- Versions 1.24 and later: action=query&meta=tokens
- Versions 1.20-1.23: action=tokens
- Versions 1.19 and earlier:
Get an undelete token
api.php? action=query& list=deletedrevs& drstart=20070904235959& drend=20070904000000& drprop=revid|user|minor|len|token& drlimit=8 [try in ApiSandbox]
Result |
---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<query-continue>
<deletedrevs drstart="20070904142729" />
</query-continue>
<query>
<deletedrevs>
<page title="Main Page" ns="0" token="e4c475f13be7824135b4edbebf4140ff+\">
<revisions>
<rev timestamp="20070904200804" revid="31" user="Catrope" minor="" len="" />
<rev timestamp="20070904200753" revid="30" user="Catrope" minor="" len="" />
<rev timestamp="20070904193501" revid="29" user="Catrope" minor="" len="568" />
<rev timestamp="20070904193213" revid="28" user="Catrope" minor="" len="470" />
<rev timestamp="20070904193103" revid="27" user="192.168.1.3" len="568" />
<rev timestamp="20070904193048" revid="26" user="192.168.1.3" len="480" />
</revisions>
</page>
<page title="User:Catrope" ns="2" token="e4c475f13be7824135b4edbebf4140ff+\">
<revisions>
<rev timestamp="20070904143938" revid="24" user="Catrope" len="52" />
<rev timestamp="20070904142758" revid="23" user="Catrope" len="37" />
</revisions>
</page>
</deletedrevs>
</query>
</api>
|
Restoring deleted revisions[edit]
Deleted revisions can be restored with action=undelete.
Parameters[edit]
title
: The page you want to undelete.token
: The token obtained in the previous request. Take care to urlencode the '+' as '%2B'.reason
: The reason for the undeletion.tags
: Tags to apply to the entry in the deletion log. 1.25+timestamps
: A pipe-separated list of timestamps of the revisions to restore. If both timestamps and fileids are empty, all will be restored. Maximum number of values is 50 (500 for bots).- You can get these timestamps through list=deletedrevs.
fileids
: A pipe-separated list of IDs of the file revisions to restore. If both timestamps and fileids are empty, all will be restored. Maximum number of values is 50 (500 for bots). 1.24+watchlist
: Specify how the watchlist is affected by this edit, set to one of "watch", "unwatch", "preferences", "nochange": (Default:preferences
) 1.16+
Example[edit]
Note: In this example, all parameters are passed in a GET request just for the sake of simplicity. However, action=undelete requires POST requests; GET requests will cause an error.
Restore the last 5 revisions of the Main Page
api.php? action=undelete& title=Main%20Page& reason=Deleted%20by%20accident& timestamps=20070904200804|20070904200753|20070904193501|20070904193213|20070904193103& token=e4c475f13be7824135b4edbebf4140ff%2B\ [try in ApiSandbox]
Result |
---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<undelete
title="Main Page"
revisions="5"
fileversions="0"
reason="5 revision(s) restored: Deleted by accident"
/>
</api>
|
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 restore deleted revisions Note: On most wikis, restoring deleted revisions is restricted to sysops, but other wikis may have stricter rules. |
cantundelete | Couldn't undelete: the requested revisions may not exist, or may have been undeleted already |