API:Edit/zh

需要以下MediaWiki选项设置为 :   and. See Manual:DefaultSettings.php.

令牌
要编辑一个页面,需要一个编辑令牌.这个令牌在所有页面中都一样, 但是每次登录都会不同. If you want to protect against edit conflicts (which is wise), 你也需要得到最近版本的时间戳. You can obtain these as follows:

当使用Edit API时, always pass the token 参数 last, or at least, after the text 参数.

编辑页面
页面可以创建并编辑,只要设置.

参数

 * Some of these 参数 seem to be revised in v1.20; for the current list, see ApiEditPage::getAllowedParams. To see the 参数 list currently in use at Wikipedia, see: 


 * : 要编辑的页面. 不能和 共用.
 * : 要编辑页面的ID. 不能和 共用.
 * : 修改哪一章节. 0是导言. 章节可能是嵌套的，如section=1包含了section=2的部分. section=new表示追加一个新章节. 如果为空，则表示修改全文. 可以用api.php?action=parse&prop=sections 获取所有章节标题.
 * : 创建新话题的标题. If not specified,  将会替代
 * : 新页面(或者话题)的 content
 * : Edit token. 特别是您没有使用 参数, the token should be sent as the last 参数, or at least, after the text 参数, to prevent a bad edit from getting committed if transmission of the body is interrupted for some reason.
 * : 编辑摘要
 * : 如果设置为true,标记为小编辑
 * : 如果设置为true,不标记为小编辑, 在您启用了 "Mark all my edits minor by default" 后适用
 * : 如果设置,将编辑标记为机器人的编辑; 即使您作为机器人登陆,也必须设置本项才能将编辑标记为机器人编辑
 * : 最后版本的时间戳, used to detect edit conflicts. Leave unset to ignore conflicts
 * : Timestamp when you obtained the edit token. Used to detect edit conflicts. Leave unset and use  to ignore conflicts
 * : 如果设置, suppress errors about the page having been deleted in the meantime and recreate it
 * : 如果设置, throw an error if the page already exists
 * : 如果设置, throw a  error if the page doesn't exist
 * : Specify how the watchlist is affected by this edit, set to one of "监视", "不监视", "缺省设置", "不改变":
 * : 在监视列表添加此页
 * : 从监视列表中移除此页
 * : 使用 (缺省)设置
 * : 不要改变监视列表
 * : MD5 hash (hex) of the  参数. If this 参数 is set and the hashes don't match, the edit is rejected. This can be used to guard against data corruption
 * : CAPTCHA ID from the previous request
 * : 验证码的答案
 * : Revision ID to undo. Overrides,   and
 * : Undo all revisions from  up to but not including this one. If not set, just undo one revision

头 of your request to. The token that you received is terminated with, this needs to be 进行URL编码 (将以 结尾) 在passback之前.

验证码和拓展错误
如果一次编辑请求需要验证码, 你将会得到类似下面的: 在很多情况下, you won't get a math CAPTCHA, but a URL to an image (in the  field). When you've solved the CAPTCHA, 重试请求 (in this case with ).

Other extensions that use the APIEditBeforeSave hook may return errors using either the format described above or the usual error format.

可能的错误
In addition to the usual stuff:
 * code: notitle
 * info: The title 参数 must be set
 * code: notext
 * info: One of the text, appendtext, prependtext and undo 参数 must be set
 * code: notoken
 * info: The token 参数 must be set
 * code: invalidsection
 * info: The section 参数 must be set to an integer or 'new'
 * code: protectedtitle
 * info: This title has been protected from creation
 * code: cantcreate
 * info: You don't have permission to create new pages
 * code: cantcreate-anon
 * info: Anonymous users can't create new pages
 * code: articleexists
 * info: The article you tried to create has been created already
 * code: noimageredirect-anon
 * info: Anonymous users can't create image redirects
 * code: noimageredirect
 * info: You don't have permission to create image redirects
 * code: spamdetected
 * info: Your edit was refused because it contained a spam fragment: ``wikitext ''
 * code: filtered
 * info: The filter callback function refused your edit
 * code: contenttoobig
 * info: The content you supplied exceeds the article size limit of bytes bytes
 * code: noedit-anon
 * info: Anonymous users can't edit pages
 * code: noedit
 * info: You don't have permission to edit pages
 * code: pagedeleted
 * info: The page has been deleted since you fetched its timestamp
 * code: emptypage
 * info: Creating new, empty pages is not allowed
 * code: emptynewsection
 * info: Creating empty new sections is not possible.
 * code: editconflict
 * info: Edit conflict detected
 * code: revwrongpage
 * info: rrevid is not a revision of ``pagename ''
 * Thrown if an invalid revid is given for  or
 * code: undo-failure
 * info: Undo failed due to conflicting intermediate edits
 * code: missingtitle
 * (see above nocreate 参数)

使用Ajax编辑
Below is sample code for editing a page via an Ajax request:

大文本
当文本超过 8000 字时, 使用 "multipart/form-data" as it does not require escaping and will be significantly smaller than its urlencoded counterpart. Multipart has roughly 160 bytes of overhead for each 参数, so for seven 参数 that's ~1.1kb overhead. 例子: POST http://en.wikipedia.org/w/api.php HTTP/1.1 User-Agent: Bot Framework Content-Type: multipart/form-data; boundary=---8ce61ec834cf268 Host: en.wikipedia.org Cookie: Content-Length: 1348 Accept-Encoding: gzip Connection: Keep-Alive

-8ce61ec834cf268 Content-Disposition: form-data; name="action"

edit -8ce61ec834cf268 Content-Disposition: form-data; name="title" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit

Title here -8ce61ec834cf268 Content-Disposition: form-data; name="text" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit

Text here -8ce61ec834cf268 Content-Disposition: form-data; name="summary" Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit

Summary -8ce61ec834cf268 Content-Disposition: form-data; name="token"

1f287ba00a908e9622045e7b18ffa352+\ -8ce61ec834cf268 Content-Disposition: form-data; name="assert"

user -8ce61ec834cf268 Content-Disposition: form-data; name="format"

xml -8ce61ec834cf268--