API:回退
| This page is part of the MediaWiki PHP action API documentation. |
MediaWiki PHP action API
- 快速开始指导
- 常见问题
- Tutorial
- 格式
- 报告错误
- Restricting usage
- 跨域请求
- 认证
- 请求
- Searching (by title, content, coordinates...)
- Parsing wikitext and expanding templates
- 清除页面缓存
- Parameter information
- Changing wiki content
- Watchlist feed
- 维基数据
- Extensions
- 在MediaWiki与插件中使用API
- 杂项
- 实现
- Client code
- Asserting
| MediaWiki 版本: | 1.12 |
回退
回退指的是撤销一系列由某用户进行的编辑。 换言之,回滚一直撤销版本直到某版本的编辑是由另一人做出的。 本功能与图形界面中提供的[回退]链接效果是一样的。 回退的版本将被标记为“小编辑”。 可选的是,回退与与被回退的编辑均可被标记为机器人操作,可在最近更改中默认不显示。
令牌
回滚页面需要回滚令牌。 如果您的维基使用MediaWiki 1.24及以上版本,您可以使用 action=query&meta=tokens&type=rollback 来获取回滚令牌。
对于MediaWiki 1.23及之前的版本,可以通过如下的步骤:
Unlike most other tokens, rollback tokens aren't universal: they're not only different for every login, but also depend on the title of the page and the name of the user whose edits are to be rolled back. A rollback token can be obtained as follows:
Obtaining a rollback token
| Result |
|---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<query>
<pages>
<page pageid="5" ns="0" title="Main Page" rollbacktoken="094a45ddbbd5e90d55d79d2a23a8c921+\">
<revisions>
<rev revid="20" user="Catrope" timestamp="2007-09-03T20:32:20Z" />
</revisions>
</page>
</pages>
</query>
</api>
|
回退页面
可以通过 action=rollback 来回退页面
参数
title: The page you want to roll back. Cannot be used together with pageid.pageid: Page ID of the page you want to roll back. Cannot be used together with title.token: The token obtained in the previous request. Take care to urlencode the '+' as '%2B'.user: 最后一个版本的编辑者summary: 编辑摘要(可选),如果没有设置将会使用默认的摘要markbot: 如果设置,回退操作与对应回退版本将被标记为机器人编辑watchlist: Unconditionally add or remove the page from your watchlist, use preferences or do not change watch. One value among: watch, unwatch, preferences, nochange.
例子
注意:在本例中,所有的参数通过GET请求传递只是为了便于理解。实际上, action=rollback 需要以POST方式请求,以GET方式请求将报错。
Rollback Username's edits to the Main Page with a default summary, and mark them as bot edits
| Result |
|---|
<?xml version="1.0" encoding="utf-8"?>
<api>
<rollback
title="Main Page"
pageid="5"
summary="Reverted edits by [[Special:Contributions/Username|Username]] ([[User talk:Username|Talk]]); changed back to last version by [[User:PreviousEditor|PreviousEditor]]"
revid="28"
old_revid="27"
last_revid="20" />
</api>
|
返回数据字段
revid: 回退的版本IDold_revid: 首个回退的版本IDlast_revid: 最后一个被回退的版本ID
If rolling back wouldn't change the page, no new revision is made. In this case, revid will be equal to old_revid.
可能的错误
In addition to the usual stuff:
| 代码 | 信息 |
|---|---|
| notitle | title参数必须被设置 |
| nouser | user参数必须被设置 |
| notoken | token参数必须被设置 |
| alreadyrolled | 您尝试回退的页面已近被回退 |
| onlyauthor | 您尝试回退的页面只有一个编辑者 |
| The following documentation is the output of Special:ApiHelp/rollback, generated from rollback's source code. |
action=rollback
- This module requires read rights.
- This module requires write rights.
- This module only accepts POST requests.
- Source: MediaWiki
- License: GPL-2.0+
Undo the last edit to the page.
If the last user who edited the page made multiple edits in a row, they will all be rolled back.
- title
-
Title of the page to roll back. Cannot be used together with pageid.
- pageid
-
Page ID of the page to roll back. Cannot be used together with title.
- Type: integer
- user
-
Name of the user whose edits are to be rolled back.
- This parameter is required.
- summary
-
Custom edit summary. If empty, default summary will be used.
- Default: (empty)
- markbot
-
Mark the reverted edits and the revert as bot edits.
- 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
- token
-
A "rollback" token retrieved from action=query&meta=tokens
For compatibility, the token used in the web UI is also accepted.
- This parameter is required.
- Roll back the last edits to page Main Page by user Example.
- api.php?action=rollback&title=Main%20Page&user=Example&token=123ABC
- Roll back the last edits to page Main Page by IP user 192.0.2.5 with summary Reverting vandalism, and mark those edits and the revert as bot edits.
- api.php?action=rollback&title=Main%20Page&user=192.0.2.5&token=123ABC&summary=Reverting%20vandalism&markbot=1

