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
- Watchlist feed
- Wikidata
- Extensions
- Using the API in MediaWiki and extensions
- Miscellaneous
- Implementation
- Client code
- Asserting
| MediaWiki version: | 1.12 |
Token[edit | edit source]
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. Edit tokens can be obtained via action=tokens (MW 1.20+), or by using the following method:
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 | edit source]
Deleted revisions can be restored with action=undelete.
Parameters[edit | edit source]
- 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 (optional).
- timestamps: A pipe-separated list of timestamps of the revisions to restore (optional). By default, all revisions will be restored.
- You can get these timestamps through list=deletedrevs.
Example[edit | edit source]
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 | edit source]
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 |