API:Assert

From mediawiki.org
This page is a translated version of the page API:Assert and the translation is 55% complete.
MediaWiki バージョン:
1.23

assert パラメータ は Action API についてあらゆる API 呼び出しに適用し、特定の条件を確認してからリクエストした操作を実行させます。

利用できる選択肢は以下の通りです:

  • assert=anon: IP 利用者 として操作してください。 これにより登録アカウント を使った履歴が偶然、残らないようにします。 MW 1.35 Gerrit change 572374 以降
  • assert=user: 登録アカウントからログインしているか確かめます (「名前付き」でも暫定でも。) これにより偶発的に特定の IP 利用者への履歴フォールバックを予防します。
  • assert=bot: ログインしたアカウントが「ボット 」利用者権限を持つかどうか確認する This prevents your script from interacting with wikis where your bot does not have the bot flag.
  • assertuser=...: Check that you are logged-in with the expected user name. MW 1.28 以降

留意点は、暫定的な利用者でも assert=user に適合、assert=anon は不適合です。

起こりうるエラー

確認(assert)が失敗した場合、返してくるエラーコードは以下のいずれかです。

  • assertanonfailed
  • assertuserfailed
  • assertbotfailed
  • assertnameduserfailed

根拠と使用事例

これらのパラメータの趣旨は以下の2種類の問題を対象に、第2の防衛策とされています:

ボット遣いのエラー

It's easy for a simple operator error to cause a lot of bad edits, such as the bot running on the wrong wiki or under the wrong username, especially if you're running more than one bot task. The assert=bot and assertuser=... parameters are intended to help prevent those mistakes.

ログイン セッションの時間切れ

After logging in, the cookies you receive are only valid for 30 days by default, after which time your bot will become logged out, and may continue working with its actions being attributed to the IP address or a temporary username (if logged-out users are allowed to perform them).

The assert=user parameter is intended to prevent this.

利用者アカウントの切り替え

Interactive tools (in the browser) using the API to edit often want to make sure the user understands how their work will be attributed.

When the user logs in or out in another browser tab (or their login session expires), this won't be immediately reflected in the tool's interface, but the new login session will be used for saving actions. The assertuser=... and assert=anon parameters are intended to allow detecting this scenario and displaying an appropriate message before continuing.


スタンドアローンの確認

If you want to check whether your HTTP client is logged into the Action API, without performing any other action, you can send a request with the parameters action=query&assert=user. This will return an empty response ({} in the JSON format) if you are indeed logged in, or the assertuserfailed error if not.

Normally, you will not need to perform a separate request like this. Instead, set the assert=user parameter on each of your requests.