API:Main page/es


 * Esta es una vista general de la API de "acción". Selecciona el menú de la derecha para información más detallada sobre otros subtemas y otras API.

La API de acción de MediaWiki es un servicio web que proporciona un acceso conveniente a características, datos, y metadatos de la wiki sobre HTTP, a través de una URL que normalmente es. Los clientes solicitan "acciones" particulares especificando un parámetro, principalmente   para obtener información. Era conocida como  la  API de MediaWiki, pero en la actualidad hay otras APIs que se conectan a MediaWiki tales como RESTBase y el servicio de consultas de Wikidata.

Introducción
The MediaWiki action API can be used to monitor a MediaWiki installation, or create a bot to automatically maintain one. It provides direct, high-level access to the data contained in MediaWiki databases. Client programs can log in to a wiki, get data, and post changes automatically by making HTTP requests to the web service. Supported clients include bots, thin web-based JavaScript clients such as Navigation popups and LiveRC, end-user applications such as Vandal Fighter, and other web sites ([//tools.wmflabs.org Toolforge]'s utilities).

En las nuevas instalaciones de MediaWiki, el servicio web está habilitado por defecto, pero un administrador puede deshabilitarlo.

MediaWiki has two other outward-facing interfaces:


 * The Special:Export page, which provides bulk export of wiki content as XML. Véase para más información.
 * The standard web-based interface (which you are likely using right now to view this page). Read for information on using the web-based interface.

Un ejemplo simple
This URL tells English Wikipedia's web service API to send you the content of the main page:

Use any programming language to make an HTTP GET request for that URL (or just visit that link in your browser), and you'll get a JSON document which includes the current wiki markup for the page titled "Main Page". Changing the format to  will return a "pretty-printed" HTML result good for debugging.

Let's pick that URL apart to show how it works.

The endpoint
This is the endpoint. It's like the home page of the MediaWiki web service API. This URL is the base URL for English Wikipedia's API, just as  is the base URL for its web site.

If you're writing a program to use English Wikipedia, every URL you construct will begin with this base URL. If you're using a different MediaWiki installation, you'll need to find its endpoint and use that instead. All Wikimedia wikis have endpoints that follow this pattern:

Since, we have RSD for the endpoint: look for the  in the HTML source of any page and extract the   URL; the actual link contains additional info. For instance, on this wiki it's:

Otherwise, there's no safe way to locate the endpoint on any wiki. If you're lucky, either the full path to index.php will not be hidden under strange rewrite rules so that you'll only have to take the "edit" (or history) link and replace index.php (etc.) with api.php, or you'll be able to use the default script path (like ).

Now let's move on to the parameters in the query string of the URL.

The format
This tells the API that we want data to be returned in JSON format. You might also want to try  to get an HTML version of the result that is good for debugging. The API supports other output formats such as XML and native PHP, but there are plans to remove less popular formats (T95715), so you might not want to use them.

The action
The MediaWiki web service API implements dozens of actions and extensions implement many more; the dynamically generated API help documents all available actions on a wiki. In this case, we're using the "query" action to get some information. The "query" action is one of the API's most important actions, and it has extensive documentation of its own. What follows is just an explanation of a single example.

Action-specific parameters
The rest of the example URL contains parameters used by the "query" action. Here, we're telling the web service API that we want information about the Wiki page called "Main Page". (The %20 is a percent-encoded space.) If you need to query multiple pages, put them all in one request to optimize network and server resources:. See the query documentation for details.

You can request many kinds of information, or properties, about a page. This parameter tells the web service API that we want information about a particular revision of the page. Since we're not specifying any revision information, the API will give us information about the latest revision &mdash; the main page of Wikipedia as it stands right now.

Finally, this parameter tells the web service API that we want the content of the latest revision of the page. If we passed in  instead, we'd get the latest page content and the name of the user who made the most recent revision.

Again, this is just one example. Queries are explained in more detail here, and the API reference lists all the possible actions, all the possible values for, and so on.



Getting started
Before you start using the MediaWiki web service API, be sure to read these documents:


 * The FAQ.
 * The page about input and output formats
 * The page about errors and warnings
 * Any policies that apply to the wiki you want to access, such as Wikimedia Foundation wikis' terms of use, trademark policy. These terms apply to you when you access or edit using the API, just as they do when you use your web browser.

Beyond that point, what you need to read depends on what you want to do. The right-hand menu links to detailed, task-specific documentation, and some more general guidelines are given below.

Identifying your client
When you make HTTP requests to the MediaWiki web service API, be sure to specify a  header that properly identifies your client. Don't use the default  provided by your client library, but make up a custom header that identifies your script or service and provides some type of means of contacting you (e.g., an e-mail address).

An example User-Agent string might look like: MyCoolTool/1.1 (https://example.org/MyCoolTool/; MyCoolTool@example.org) BasedOnSuperLib/1.4

On Wikimedia wikis, if you don't supply a  header, or you supply an empty or generic one, your request will fail with an HTTP 403 error (cf. User-Agent policy). Other MediaWiki installations may have similar policies.

If you are calling the API from browser-based JavaScript, you won't be able to influence the  header: the browser will use its own. To work around this, use the  header:

In PHP, you can identify your user-agent with code such as this:

O si utilizas de rizo:

Finalizar la sesión
Vuestro cliente probablemente necesitará a registro en a MediaWiki, posiblemente vía su cuenta de usuario propia. Ve el login página manual para detalles.

API etiquette
Complacer también leído: API:Etiquette

Si vuestras peticiones obtienen dato que puede ser cached para un rato, tendrías que tomar pasos a cache lo, así que no pides el mismo dato encima y encima otra vez. Más información aproximadamente índice-limitativo, concurrency, y general API etiquette puede ser encontrado en API:Etiquette. Algunos clientes pueden ser capaces a cache dato ellos, pero para otros (particularmente clientes de Javascript), esto no es posible.

Por la especificación de HTTP, peticiones de CORREO no pueden ser cached. Por tanto, siempre que estás leyendo dato del servicio web API,  tendrías que utilizar CONSEGUIR peticiones, no CORREO.

i También nota que una petición no puede ser servida de cache a no ser que el URL es exactamente igual. Si haces una petición para $código1, y cache el resultado, entonces una petición para $código2 no pasará por el cache — incluso aunque MediaWiki regresa el mismo dato!

Tendrías que cuidar para normalizar el URLs envías al MediaWiki servicio web, de modo que ligeramente entrada de usuario diferente no te causará para malgastar tiempo en peticiones de HTTP innecesario. Puedes normalizar una lista de títulos de página por  estámoviendo duplicados y  esorting los títulos alfabéticamente. Las técnicas similares trabajarán para otras clases de datos.

Enlaces útiles
hey La barra de carta en el lado correcto de estos enlaces de página a más detallados, tarea-documentación concreta. Aquí es algunos enlaces teniendo que hacer con el API globalmente:


 * El API sandbox disponible encima todo Wikimedia wikis lo hace fácil de probar fuera de acciones diferentes interactivamente.
 * [//en.wikipedia.org/w/api.php El API referencia] contiene automáticamente-generó descripciones de todas las acciones y parámetros.
 * Gancho a información de Wikipedia que utiliza PHP y el MediaWiki API (IBM developerWorks artículo, 17 mayo 2011)
 * Hook into Wikipedia using Java and the MediaWiki API (6 April 2012)
 * Mailing list for notifications and questions: API mailing list
 * Low-traffic mailing list for announcements only (all posts to this list are posted to mediawiki-api as well): mediawiki-api-announce
 * View and report API bugs in the MediaWiki-API Phabricator project (When reporting new bugs, don't forget to add MediaWiki-API to Projects)
 * — El esquema actuals de bases de datos de MediaWiki
 * — El esquema actuals de bases de datos de MediaWiki

Enlaces archivados

 * 2006 API discusión