API:データ形式

From mediawiki.org
This page is a translated version of the page API:Data formats and the translation is 48% complete.

入力

APIは,入力を受け取る際,application/x-www-form-urlencoded又はmultipart/form-data形式のHTTP要求が提供したパラメータを介します。 (unlike REST API, the Action API currently does not support application/json input format.) 全モジュール及び下位モジュールは自身のパラメータ郡を持っており,文書及びaction=helpにて一覧できます。action=paraminfo を介して取得することも可能です。

符号化

全ての入力は形式Cで正規化された妥当なUTF-8であるべきです。 MediaWiki は他の形式への変換を試みますが,失敗に終わる恐れがあります。

= 複数値のパラメータ

複数の値を取るパラメータは通常パイプ文字(|)を用いて分割された値を受理します。例: param=value1|value2 値自身がパイプ文字を含む場合は,U+001Fユニット分離標識)を区切り子として用い,値にU+001Fを前置して下さい。例: param=%1Fvalue1%1Fvalue2

パラメータが複数値を受理するか否かはそのモジュール文書に明示的に掲載されています。

真偽パラメーター

真偽値のパラメーターが HTTP 要求内で指定されている場合、その値に関係なく true と見なされます。false 値を指定するには、パラメーターを丸ごと省略します。 パラメータ=を使うのが,HTTP要求内で真パラメータを指定する最良の方法です。末尾に=があることで,ブラウザ又はHTTPライブラリが空のパラメータを破棄しないことが保証されます。

タイムスタンプ

Parameters that take timestamp values accept multiple timestamp formats:

  • ISO 8601 format: 2008-08-23T18:05:46Z.
  • MediaWiki's internal timestamp format : 20080823180546.
  • MySQL's internal timestamp format: 2008-08-23 18:05:46.
  • UNIX タイムスタンプ形式 1219514746 (1970年1月1日からの経過秒数).

Timestamps are always output in ISO 8601 format.

出力

MediaWiki における標準および既定の出力形式は JSON です。他のいずれの形式も推奨されません。

The output format should always be specified using format=yourformat with yourformat being one of the following:

出力をJSONで得る。


応答

{
  "query": {
    "pages": {
      "217225": {
        "pageid": 217225,
        "ns": 0,
        "title": "Main page"
      }
    }
  }
}

指定されなければ,全てのモジュールはデータを全ての汎用形式で出力します。 To simplify debugging, all generic formats have "pretty-print in HTML" alternatives with an fm suffix, e.g. jsonfm.

JSON パラメーター

The following parameters can be used with format=json and format=jsonfm:

  • utf8: Encodes most (but not all) non-ASCII characters as UTF-8 instead of replacing them with hexadecimal escape sequences. 型: boolean.
  • ascii: Encodes all non-ASCII characters using hexadecimal escape sequences. 型: boolean.
  • formatversion: The output formatting. 1.25+
    • 1: Backwards-compatible format, uses * keys for content nodes, encodes non-ASCII characters using hexadecimal escape sequences.
    • 2: Modern format. Returns responses in a cleaner format, encodes most non-ASCII characters as UTF-8. (recommended)
  • callback: The function in which the result will be wrapped. For safety, all user-specific data will be restricted. A number of things are disabled for security:
    • The client is treated as an anonymous user (i.e. not logged in) for all purposes, even after logging in through action=login .

This means that modules which require additional rights won't work unless the target wiki allows anonymous users to use them.

追加的な注記

  • XML and PHP output formats are deprecated but still in use.

Clients written in PHP should avoid using the PHP format because it is fundamentally insecure. It is maintained for now only due to its popularity.

  • There are many conversion libraries and online converters to convert JSON responses to other formats—for example, JSON-CSV converts to Comma-Separated Values.
  • Feed modules like Feed Recent Changes override the standard output format, instead using RSS or Atom, as specified by their feedformat parameter.

In those cases, the format specified in the format parameter is only used if there's an error.

関連項目