API:Edit/zh

编辑一个页面时会进行POST 请求.

示例
此示例中的示例代码使用Python. 有关示例请见，响应请参阅.

POST请求
编辑，以及任何POST请求实际上都是一个多步骤的过程.


 * 1. 使用中描述的方法之一登录. 请注意，虽然此操作需要将其正确地归为编辑者的贡献，但许多Wiki确实允许用户无需注册或登录帐户即可进行编辑.


 * 2. 获取：


 * 3. 发送带有CSRF令牌的POST请求以在页面上执行操作：

下方的“回应”段落显示了最终的POST请求，以在页面上执行操作. 请参阅和的页面，以获取对先前步骤的中间JSON响应.

另请注意，此页面上查询中的令牌（tokens）是示例值. 实际的令牌对于每个登录会话和跨站请求都是唯一的. 示例中包括它们只是为了演示如何正确格式化查询.

编辑冲突
“Python示例”是一个对于注册用户编辑请求的简单实现. 在实际情况下，应注意防止编辑冲突. 当两个或多个用户试图同时编辑同一页面时，可能会发生这种情况.

当我们请求CSRF令牌时，可以通过检索最后的时间戳来避免冲突. 在第3步的CSRF令牌请求中加入 可以获取最新版本的时间戳. 当我们发出编辑请求时，此时间戳将用作.

此外还需要开始编辑的准确时间. 同样可以通过在CSRF请求中添加 来检索此内容. 该值将作为.

最后，在实际的编辑请求中，将 和 参数设定为类似如下内容：

大编辑
包含了大量的文本内容（超过8000个字符）的POST请求应该在请求头中加入. Because  does not need to add HTML escape characters (i.e., percent encoding) for spaces and punctuation, the amount of data passed will subsequently be much smaller than the percent-encoded equivalent.

However, there is still some overhead added by  -- roughly, 160 bytes per parameter. For short messages that don't require adding many escape characters, this amount of overhead can be inefficient, and percent-encoding is preferred.

Note that in our Python sample code, the request is percent-encoded by default.

See the MDN web docs for a more technical discussion of content-type and POST requests. See the Python Requests documentation for how to pass  using syntax similar to our Python sample code.

验证码
If the wiki you are targeting uses, your request may return an error containing an id number and a simple test, such as a question, a math problem, or an URL to an image. In order to complete your edit, you must complete the test, then retry your request with the id and the correct answer(s) appended to the original query string, like so:

Other CAPTCHA systems and extensions may use different parameters for similar use. In general, use the field names for the id and test questions as the parameters in your second request.

参数历史

 * v1.25: 启用
 * v1.21: 启用 ,
 * v1.20: 启用
 * v1.19: 启用
 * v1.18: 弃用 ,
 * v1.17: 启用
 * v1.16: 弃用 ,
 * v1.16: 启用
 * v1.15: 启用 ,
 * v1.14: 启用

更多注释

 * Log in is not strictly required by the API, but it is needed to correctly attribute the edit to its author. A successful edit from a user who is not logged in will be attributed to their IP address.
 * Bots that are not logged in may face restrictions on editing and other write requests; see for more details.
 * Users who are not logged in will always be given the empty CSRF token,.
 * The process for requesting a token has changed several times across versions. 参见以获取更多信息.
 * provides a way to access edit tokens when running code within a wiki page.
 * You can use the same login token for all edit operations across the same wiki, during a single login session.
 * It is a good practice to pass any tokens in your request at the end of the query string, or at least after the text parameter. That way, if the connection is interrupted, the token will not be passed and the edit will fail. If you are using the object to make requests, this is done automatically.
 * Although  and   have, technically, been removed from API:Edit since v1.18,  extends API:Edit to work with CAPTCHAs. Thus, with ConfirmEdit installed, these parameters are still available. ConfirmEdit comes packaged with the MediaWiki software, v1.18+.

参见

 * - 包含对编辑页面有用的链接
 * - describes how to log in using a simplified interface when accessing wikis via a script or application, rather than the GUI.
 * - 更多有关使用机器人自动编辑页面的详细信息.
 * - provides a way to access edit tokens when running JavaScript within a MediaWiki page.
 * - has more details on using tokens to log in or make POST requests.
 * - a deprecated API, distinct from, for requesting tokens in earlier versions of MediaWiki.
 * - 允许您查看页面的两个修订版本之间的差异.
 * - 修改一个页面的标签
 * - 回退一系列编辑.
 * - 将文件回退到其较早的状态.
 * - 删除并恢复页面的修订版本.