API:Edit/ja
| このページは MediaWiki API ドキュメントの一部です。 |
| 言語: | English • Deutsch • español • français • 日本語 • Tiếng Việt • 中文 |
|---|
| MediaWiki バージョン: | 1.13 |
Requires the selected MediaWiki to have the following configuration settings set to true: $wgEnableAPI and $wgEnableWriteAPI. See Manual:DefaultSettings.php.
Contents |
トークン [edit]
ページを編集するために、編集トークンが必要です。このトークンはすべてのページに対して同じですが、ログインごとに変わります。編集の衝突から保護するために(賢明なことです)、最後のリビジョンのタイムスタンプを取得することも必要です。これらの値を次のように取得します:
| 結果 |
|---|
| The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <query> <pages> <page pageid="15580374" ns="0" title="Main Page" touched="2008-03-27T21:15:39Z" lastrevid="199631190" counter="0" length="4712" edittoken="000000000000000000+\"> <revisions> <rev revid="199631190" user="David Levy" timestamp="2008-03-20T17:26:39Z" comment="Have you tested it in every major browser at every resolution." /> </revisions> </page> </pages> </query> </api> |
| The above content has been placed in a collapsed box for improved usability. |
When passing this to the Edit API, always pass the token parameter last, or at least, after the text parameter.
ページの編集 [edit]
action=edit で、ページの編集や作成ができます。
パラメータ [edit]
- Some of these parameters seem to be revised in v1.20; for the current list, see ApiEditPage::getAllowedParams(). To see the parameter list currently in use at Wikipedia, see: {{ApiEx/ja}}
title: 編集するページ。Cannot be used together withpageid.pageid: Page ID of the page to edit. Cannot be used together withtitle.section: 編集するセクション。トップのセクションに対しては0、新しいセクションに対して'new'を使うsectiontitle: (バージョン1.19で追加) 新しいセクションを追加する場合にセクション名として使う。省略した場合は替わりにsummaryで指定した内容が使われるtext: 新しいページ(もしくはセクションの)内容token: Edit token. Especially if you are not using themd5parameter, the token should be sent as the last parameter, or at least, after the text parameter, to prevent a bad edit from getting committed if transmission of the body is interrupted for some reason.summary: 編集のコメントminor: 設定されると、細部の編集としてマークするnotminor: 設定されると、"Mark all my edits minor by default"とMy preferences(オプション)で有効にしていたとしても、細部の編集としてマークしない[1]。bot: If set, mark the edit as bot; even if you are using a bot account the edits will not be marked unless you set this flag [1]basetimestamp: 最後のリビジョンのタイムスタンプで、編集の衝突を検知するために使われます。衝突を無視するためには設定されてない状態にしておきますstarttimestamp: Timestamp when you obtained the edit token. Used to detect edit conflicts. Leave unset and userecreateto ignore conflictsrecreate: 設定されると、ページが削除されている間のエラー表示を抑制しページを再作成する[1]createonly: 設定されると、ページが既に存在する場合にエラーをスローする[1]nocreate: 設定されると、ページが存在しない場合にエラーをスローする[1]watchlist: Specify how the watchlist is affected by this edit, set to one of "watch", "unwatch", "preferences", "nochange":watch: ページをウォッチリストに追加するunwatch: ウォッチリストからページを削除するpreferences: use the preference settings (Default)nochange: don't change the watchlist
md5: MD5 hash (hex) of thetextparameter. If this parameter is set and the hashes don't match, the edit is rejected. This can be used to guard against data corruptioncaptchaid: CAPTCHA ID from the previous requestcaptchaword: Answer to the CAPTCHAundo: Revision ID to undo. Overridestext,prependtextandappendtextundoafter: Undo all revisions fromundoup to but not including this one. If not set, just undo one revision
- ↑ 1.0 1.1 1.2 1.3 1.4 The presence of this variable activates its feature. For instance adding the value "recreate" with or without a value will suppress errors about the page being previously deleted.
例 [edit]
注: この例では、簡潔性のためだけにすべてのパラメータはGETリクエストに渡されますが。しかしながらaction=editはPOSTリクエストを必要です; GET リクエストはエラーを引き起こします。リクエストのヘッダにContent-Typeとしてapplication/x-www-form-urlencodedをセットするのを忘れないようにしてください。The token that you received is terminated with +\, this needs to be urlencoded (so it will end with %2B%5C) before it is passed back.
| 結果 |
|---|
| The following content has been placed in a collapsed box for improved usability. |
<?xml version="1.0" encoding="utf-8"?> <api> <edit result="Success" pageid="12" title="Talk:Main Page" oldrevid="465" newrevid="471" /> </api> |
| The above content has been placed in a collapsed box for improved usability. |
CAPTCHAと拡張機能のエラー [edit]
編集がCAPTCHAを必要な場合、次のようなエラーが表示されます:
<?xml version="1.0" encoding="utf-8"?> <api> <edit result="Failure"> <captcha type="math" mime="text/tex" id="509895952" question="36 + 4 = " /> </edit> </api>
大抵の場合、you won't get a math 数学のCAPTCHAを得られず、(urlフィールドの)画像へのURLになります。CAPTCHAを解決したとき、リクエストを再試行して下さい(この場合は captchaid=509895952&captchaword=40で)。
Other extensions that use the APIEditBeforeSaveフックを使う別のフックは通常のエラーフォーマットで説明されたどちらかのフォーマットを使うとエラーを返すことがあります。
起こり得るエラー [edit]
通常のものに加えて以下のエラーがあります:
- code: notitle
- info: titleパラメータを設定しなけばなりません
- code: notext
- info: textパラメータを設定しなければなりません
- code: notoken
- info: tokenパラメータを設定しなければなりません
- code: invalidsection
- info: sectionパラメータは整数もしくは'new'に設定しなければなりません
- code: protectedtitle
- info: このタイトルは作ることができないように保護されています
- code: cantcreate
- info: 新しいページを作るパーミッションを持っていません
- code: cantcreate-anon
- info: 匿名ユーザは新しいページを作ることができません
- code: articleexists
- info: 作ろうとした記事は既に作れたものです
- code: noimageredirect-anon
- info: 匿名ユーザは画像のリダイレクトを作ることができません
- code: noimageredirect
- info: 画像のリダイレクトを作るパーミッションを持っていません
- code: spamdetected
- info: スパムのフラグメント(断片)が含まれているので、編集が拒否されました: ``wikitext''
- code: filtered
- info: フィルタコールバック関数が編集を拒否しました
- code: contenttoobig
- info: あなたが提供した内容はbytesバイトの記事の制限を越えます
- code: noedit-anon
- info: 匿名ユーザはページを編集できません
- code: noedit
- info: ページを編集するパーミッションを持っていません。
- code: pagedeleted
- info: タイムスタンプを取得した後でページは削除されました
- code: emptypage
- info: 新しい、空のページを作ることは許可されてません
- code: emptynewsection
- info: Creating empty new sections is not possible.
- code: editconflict
- info: 編集の衝突が検出されました
- code: revwrongpage
- info: rrevid is not a revision of ``pagename''
- Thrown if an invalid revid is given for
undoorundoafter
- Thrown if an invalid revid is given for
- info: rrevid is not a revision of ``pagename''
- code: undo-failure
- info: Undo failed due to conflicting intermediate edits
- code: missingtitle
- (see above nocreate parameter)
Editing via Ajax [edit]
Below is sample code for editing a page via an Ajax request:
function addNewSection( summary, content, editToken ) { $.ajax({ url: mw.util.wikiScript( 'api' ), data: { format: 'json', action: 'edit', title: mw.config.get( 'wgPageName' ), section: 'new', summary: summary, text: content, token: editToken }, dataType: 'json', type: 'POST', success: function( data ) { if ( data && data.edit && data.edit.result == 'Success' ) { window.location.reload(); // reload page if edit was successful } else if ( data && data.error ) { alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info ); } else { alert( 'Error: Unknown result from API.' ); } }, error: function( xhr ) { alert( 'Error: Request failed.' ); } }); }
Large texts [edit]
When using texts over 8000 characters, use "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 parameter, so for seven parameters that's ~1.1kb overhead. Example:
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: <removed> 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--