API:Data formats/pt

Category:MediaWiki action API/pt

Entrada

A API recebe a sua entrada através de parâmetros fornecidos pelo pedido HTTP no formato application/x-www-form-urlencoded ou multipart/form-data. (unlike REST API, the Action API currently does not support application/json input format.) Cada módulo e sub módulo tem o seu próprio conjunto de parâmetros, que são listados na documentação e em action=help. Eles também podem ser recuperados por meio de action=paraminfo.

Codificar

Todas as entradas devem ser válidas em UTF-8, na forma NFC O MediaWiki tentará converter os outros formatos, o que pode resultar num erro.

Parâmetros de valores múltiplos

Os parâmetros que recebem múltiplos valores são normalmente submetidos com os valores separados utilizando o caráter "|" (|), por exemplo, param=value1|value2. If a value contains the pipe character in itself, use U+001F (Unit Separator) as the separator and prefix the value with U+001F, e.g. param=%1Fvalue1%1Fvalue2.

Whether a parameter accepts multiple values is listed explicitly in its module documentation.

Parâmetros boolianos

If a boolean parameter is specified in an HTTP request, it is considered true regardless of its value. For a false value, omit the parameter entirely. The best way to specify a true parameter in an HTTP request is to use someParam=; the trailing = ensures the browser or HTTP library does not discard the "empty" someParam.

Marcas de tempo

Parameters that take timestamp values accept multiple timestamp formats:

Timestamps are always output in ISO 8601 format.

Saída

The standard and default output format in MediaWiki is JSON. All other formats are discouraged.

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

  • json: JSON format. (recommended)
  • php: serialized PHP format. (deprecated)
  • xml: Formato XML (deprecated)
  • txt: Formato PHP print_r(). (removed in 1.27)
  • dbg: Formato PHP var_export(). (removed in 1.27)
  • yaml: Formato YAML. (removed in 1.27)
  • wddx: Formato WDDX. (removed in 1.26)
  • dump: Formato PHP var_dump(). (removed in 1.26)
  • none: Devolve uma resposta em branco. 1.21+

Exemplo

Obter a saída em JSON.

Resposta

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

Unless specified, all modules allow data output in all generic formats. To simplify debugging, all generic formats have "pretty-print in HTML" alternatives with an fm suffix, e.g. jsonfm.

Parâmetros 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. Type: boolean.
  • ascii: Encodes all non-ASCII characters using hexadecimal escape sequences. Type: 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: Response in the JSON format, by wrapping the result in a JavaScript function call. For security reasons, these responses ignore any browser session cookies and respond without information specific to a current logged-in user. This means the following features are disabled for safety:
    • 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.

Notas adicionais

  • 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.

Consultar também

Category:MediaWiki action API/pt