API:Edit/fr

Requête POST pour modifier une page.

Exemple
L'extrait de code de cet exemple est en Python. Voir pour les exemples et les réponses dans.

Requête POST
Faire des modifications, et bien sûr toute requête POST, sont un processus qui se déroule en plusieurs étapes.


 * 1. Se connecter, en utilisant une des méthodes décrites dans . Notez bien que ceci est nécessaire pour attribuer correctement les modifications à leur auteur, mais que beaucoup de wikis permettent réellement à l'utilisateur de modifier sans être enregistré ni être connecté sous un compte.


 * 2. Obtenir (GET) un :


 * 3. Envoyer une requête POST, avec le jeton CSRF, pour faire une action sur une page :

La section Response ci-dessous est pour la fin de la requête POST, pour réaliser l'action sur la page. Voir les pages sur et  pour les réponses intermédiaires JSON et les étapes qui précèdaient.

Also note that the tokens in the queries on this page are sample values. Actual tokens are unique to each login session and cross-site request. They are included only to demonstrate how to properly format queries.

Exemple de code
edit.py

Conflits d'édition
The Python sample above is a basic implementation, of an edit request by a registered user. In real-world scenarios care should be taken to prevent edit conflicts. These occur when two or more users are attempting to edit the same page at the same time.

Conflicts can be prevented by retrieving the last timestamp when we request a CSRF token. Adding  to the CSRF token request in Step 3 allows us to access the timestamp for the last revision. This timestamp will be used as the  when we make our the edit request.

We also need the exact time when we start our edit. This can be retrieved by adding  to the CSRF request as well. This value will serve as our.

Finally, in the actual edit request, set the  and   parameters, like so:

Grandes modifications
POST requests containing large amounts of text content (8000+ characters) should be sent with  indicated in the header. Because  does not need to add HTML escape characters (i.e., percent encoding) for spaces and punctuation, the amount of data passed will subsequently be much smaller than the percent-encoded equivalent.

However, there is still some overhead added by  -- roughly, 160 bytes per parameter. For short messages that don't require adding many escape characters, this amount of overhead can be inefficient, and percent-encoding is preferred.

Note that in our Python sample code, the request is percent-encoded by default.

See the MDN web docs for a more technical discussion of content-type and POST requests. See the Python Requests documentation for how to pass  using syntax similar to our Python sample code.

Les CAPTCHAs
If the wiki you are targeting uses, your request may return an error containing an id number and a simple test, such as a question, a math problem, or an URL to an image. In order to complete your edit, you must complete the test, then retry your request with the id and the correct answer(s) appended to the original query string, like so:

Other CAPTCHA systems and extensions may use different parameters for similar use. In general, use the field names for the id and test questions as the parameters in your second request.

Historique des paramètres

 * v1.25: ajouté
 * v1.21: ajouté ,
 * v1.20: ajouté
 * v1.19: ajouté
 * v1.18: obsolète ,
 * v1.17: ajouté
 * v1.16: obsolète ,
 * v1.16: ajouté
 * v1.15: ajouté ,
 * v1.14: ajouté

Notes supplémentaires

 * Log in is not strictly required by the API, but it is needed to correctly attribute the edit to its author. A successful edit from a user who is not logged in will be attributed to their IP address.
 * Bots that are not logged in may face restrictions on editing and other write requests; see for more details.
 * Users who are not logged in will always be given the empty CSRF token,.
 * The process for requesting a token has changed several times across versions. See for more information.
 * provides a way to access edit tokens when running code within a wiki page.
 * You can use the same login token for all edit operations across the same wiki, during a single login session.
 * It is a good practice to pass any tokens in your request at the end of the query string, or at least after the text parameter. That way, if the connection is interrupted, the token will not be passed and the edit will fail. If you are using the object to make requests, this is done automatically.
 * Although  and   have, technically, been removed from API:Edit since v1.18,  extends API:Edit to work with CAPTCHAs. Thus, with ConfirmEdit installed, these parameters are still available. ConfirmEdit comes packaged with the MediaWiki software, v1.18+.

Voir aussi

 * - contains useful links on editing articles.
 * - describes how to log in using a simplified interface when accessing wikis via a script or application, rather than the GUI.
 * - more details on using a bot to automatically edit pages.
 * - provides a way to access edit tokens when running Javascript within a MediaWiki page.
 * - has more details on using tokens to log in or make POST requests.
 * - a deprecated API, distinct from, for requesting tokens in earlier versions of MediaWiki.
 * - allows you to diff between edits on a page.
 * - alters tags on a page.
 * - reverts a series of edits.
 * - rolls back files to an earlier state.
 * - deletes and restores revisions to a page.