API:Compare/fr
![]() | Cette page fait partie de la documentation de l'API MediaWiki Action. |
Requête GET pour obtenir la différence entre deux pages.
Version de MediaWiki : | ≥ 1.18 |
Documentation de l'API
![]() | La documentation qui suit est le résultat de Special: |
action=compare
- This module requires read rights.
- Source: MediaWiki
- License: GPL-2.0-or-later
Get the difference between two pages.
A revision number, a page title, a page ID, text, or a relative reference for both "from" and "to" must be passed.
- fromtitle
First title to compare.
- fromid
First page ID to compare.
- Type: integer
- fromrev
First revision to compare.
- Type: integer
- fromslots
Override content of the revision specified by fromtitle, fromid or fromrev.
This parameter specifies the slots that are to be modified. Use fromtext-{slot}, fromcontentmodel-{slot}, and fromcontentformat-{slot} to specify content for each slot.
- Values (separate with | or alternative): main
- fromtext-{slot}
Text of the specified slot. If omitted, the slot is removed from the revision.
- This is a templated parameter. When making the request, {slot} in the parameter's name should be replaced with values of fromslots.
- fromsection-{slot}
When fromtext-{slot} is the content of a single section, this is the section identifier. It will be merged into the revision specified by fromtitle, fromid or fromrev as if for a section edit.
- This is a templated parameter. When making the request, {slot} in the parameter's name should be replaced with values of fromslots.
- fromcontentformat-{slot}
Content serialization format of fromtext-{slot}.
- This is a templated parameter. When making the request, {slot} in the parameter's name should be replaced with values of fromslots.
- One of the following values: application/json, application/octet-stream, application/unknown, application/vue+xml, application/x-binary, text/css, text/javascript, text/plain, text/unknown, text/x-wiki, unknown/unknown
- fromcontentmodel-{slot}
Content model of fromtext-{slot}. If not supplied, it will be guessed based on the other parameters.
- This is a templated parameter. When making the request, {slot} in the parameter's name should be replaced with values of fromslots.
- One of the following values: GadgetDefinition, Json.JsonConfig, JsonSchema, MassMessageListContent, NewsletterContent, Scribunto, SecurePoll, css, flow-board, javascript, json, sanitized-css, text, translate-messagebundle, unknown, vue, wikitext
- frompst
Do a pre-save transform on fromtext-{slot}.
- Type: boolean (details)
- fromtext
- Deprecated.
Specify fromslots=main and use fromtext-main instead.
- fromcontentformat
- Deprecated.
Specify fromslots=main and use fromcontentformat-main instead.
- One of the following values: application/json, application/octet-stream, application/unknown, application/vue+xml, application/x-binary, text/css, text/javascript, text/plain, text/unknown, text/x-wiki, unknown/unknown
- fromcontentmodel
- Deprecated.
Specify fromslots=main and use fromcontentmodel-main instead.
- One of the following values: GadgetDefinition, Json.JsonConfig, JsonSchema, MassMessageListContent, NewsletterContent, Scribunto, SecurePoll, css, flow-board, javascript, json, sanitized-css, text, translate-messagebundle, unknown, vue, wikitext
- fromsection
- Deprecated.
Only use the specified section of the specified 'from' content.
- totitle
Second title to compare.
- toid
Second page ID to compare.
- Type: integer
- torev
Second revision to compare.
- Type: integer
- torelative
Use a revision relative to the revision determined from fromtitle, fromid or fromrev. All of the other 'to' options will be ignored.
- One of the following values: cur, next, prev
- toslots
Override content of the revision specified by totitle, toid or torev.
This parameter specifies the slots that are to be modified. Use totext-{slot}, tocontentmodel-{slot}, and tocontentformat-{slot} to specify content for each slot.
- Values (separate with | or alternative): main
- totext-{slot}
Text of the specified slot. If omitted, the slot is removed from the revision.
- This is a templated parameter. When making the request, {slot} in the parameter's name should be replaced with values of toslots.
- tosection-{slot}
When totext-{slot} is the content of a single section, this is the section identifier. It will be merged into the revision specified by totitle, toid or torev as if for a section edit.
- This is a templated parameter. When making the request, {slot} in the parameter's name should be replaced with values of toslots.
- tocontentformat-{slot}
Content serialization format of totext-{slot}.
- This is a templated parameter. When making the request, {slot} in the parameter's name should be replaced with values of toslots.
- One of the following values: application/json, application/octet-stream, application/unknown, application/vue+xml, application/x-binary, text/css, text/javascript, text/plain, text/unknown, text/x-wiki, unknown/unknown
- tocontentmodel-{slot}
Content model of totext-{slot}. If not supplied, it will be guessed based on the other parameters.
- This is a templated parameter. When making the request, {slot} in the parameter's name should be replaced with values of toslots.
- One of the following values: GadgetDefinition, Json.JsonConfig, JsonSchema, MassMessageListContent, NewsletterContent, Scribunto, SecurePoll, css, flow-board, javascript, json, sanitized-css, text, translate-messagebundle, unknown, vue, wikitext
- topst
Do a pre-save transform on totext.
- Type: boolean (details)
- totext
- Deprecated.
Specify toslots=main and use totext-main instead.
- tocontentformat
- Deprecated.
Specify toslots=main and use tocontentformat-main instead.
- One of the following values: application/json, application/octet-stream, application/unknown, application/vue+xml, application/x-binary, text/css, text/javascript, text/plain, text/unknown, text/x-wiki, unknown/unknown
- tocontentmodel
- Deprecated.
Specify toslots=main and use tocontentmodel-main instead.
- One of the following values: GadgetDefinition, Json.JsonConfig, JsonSchema, MassMessageListContent, NewsletterContent, Scribunto, SecurePoll, css, flow-board, javascript, json, sanitized-css, text, translate-messagebundle, unknown, vue, wikitext
- tosection
- Deprecated.
Only use the specified section of the specified 'to' content.
- prop
Which pieces of information to get.
- diff
- The diff HTML.
- diffsize
- The size of the diff HTML, in bytes.
- rel
- The revision IDs of the revision previous to 'from' and after 'to', if any.
- ids
- The page and revision IDs of the 'from' and 'to' revisions.
- title
- The page titles of the 'from' and 'to' revisions.
- user
- The username and ID of the 'from' and 'to' revisions. If the user has been revision deleted, a fromuserhidden or touserhidden property will be returned.
- comment
- The comment on the 'from' and 'to' revisions. If the comment has been revision deleted, a fromcommenthidden or tocommenthidden property will be returned.
- parsedcomment
- The parsed comment on the 'from' and 'to' revisions. If the comment has been revision deleted, a fromcommenthidden or tocommenthidden property will be returned.
- size
- The size of the 'from' and 'to' revisions.
- timestamp
- The timestamp of the 'from' and 'to' revisions.
- Values (separate with | or alternative): comment, diff, diffsize, ids, parsedcomment, rel, size, timestamp, title, user
- Default: diff|ids|title
- slots
Return individual diffs for these slots, rather than one combined diff for all slots.
- Values (separate with | or alternative): main
- To specify all values, use *.
- difftype
Return the comparison formatted as inline HTML.
- One of the following values: inline, table, unified
- Default: table
- Create a diff between revision 1 and 2.
- api.php?action=compare&fromrev=1&torev=2 [open in sandbox]
Exemple
Requête GET
Réponse
{
"compare": {
"fromid": 1882196,
"fromrevid": 739666518,
"fromns": 10,
"fromtitle": "Template:Unsigned",
"toid": 32371774,
"torevid": 909784724,
"tons": 10,
"totitle": "Template:UnsignedIP",
...
}
}
Exemple de code
Python
#!/usr/bin/python3
"""
compare.py
MediaWiki Action API Code Samples
Demo of `Compare` module: Compare the current revisions of two different pages
MIT license
"""
import requests
S = requests.Session()
URL = "https://en.wikipedia.org/w/api.php"
PARAMS = {
'action':"compare",
'format':"json",
'fromtitle':'Template:Unsigned',
'totitle':'Template:UnsignedIP'
}
R = S.get(url=URL, params=PARAMS)
DATA = R.json()
print(DATA)
PHP
<?php
/*
compare.php
MediaWiki Action API Code Samples
Demo of `Compare` module: Compare the current revisions of two different pages
MIT license
*/
$endPoint = "https://en.wikipedia.org/w/api.php";
$params = [
"action" => "compare",
"format" => "json",
"fromtitle" => "Template:Unsigned",
"totitle" => "Template:UnsignedIP"
];
$url = $endPoint . "?" . http_build_query( $params );
$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec( $ch );
curl_close( $ch );
echo( $output );
JavaScript
/*
compare.js
MediaWiki Action API Code Samples
Demo of `Compare` module: Compare the current revisions of two different pages
MIT license
*/
var url = "https://en.wikipedia.org/w/api.php";
var params = {
action: "compare",
format: "json",
fromtitle: "Template:Unsigned",
totitle: "Template:UnsignedIP"
};
request.get({ url: url, qs: params }, function(error, res, body) {
if (error) {
return;
}
console.log(body);
});
MediaWiki JS
/*
compare.js
MediaWiki Action API Code Samples
Demo of `Compare` module: Compare the current revisions of two different pages
MIT license
*/
var params = {
action: "compare",
format: "json",
fromtitle: "Template:Unsigned",
totitle: "Template:UnsignedIP"
},
api = new mw.Api();
api.get( params ).done( function ( data ) {
console.log( data );
} );
Erreurs possibles
Code | Information |
---|---|
compare-relative-to-nothing | Pas de révision 'depuis' pour torelative à laquelle se rapporter. |
compare-relative-to-deleted | Impossible d’utiliser torelative=value par rapport à une révision supprimée. |
missingrev-title | Aucune révision actuelle de titre title. |
baddiff | La différence ne peut être récupérée. Une ou les deux révisions n’existent pas ou vous n’avez pas le droit de les voir. |
missingcontent-revid | Contenu de la révision d’ID revid manquant. |
invalidtitle | Mauvais titre « title ». |
nosuchpageid | Il n’y a pas de page avec l’ID id. |
missingtitle-byname | La page name n’existe pas. |
nosuchrevid | Il n’y a pas de révision d’ID id. |
missingcontent-revid-role | Contenu manquant pour l’identifiant de révision id pour le rôle main. |
compare-nosuchfromsection | Il n’y a pas de section name dans le contenu 'from'. |
compare-nosuchtosection | Il n’y a pas de section name dans le contenu « to ». |
compare-maintextrequired | Le paramètre fromtext-main est obligatoire lorsque fromslots contient main (impossible de supprimer l’emplacement principal). |
compare-maintextrequired | Le paramètre totext-main est obligatoire lorsque toslots contient main (impossible de supprimer l’emplacement principal). |
compare-notext | Le paramètre $1 ne peut pas être utilisé sans $2. |
compare-no-title | Impossible de faire une transformation avant enregistrement sans titre. Essayez de spécifier fromtitle ou totitle. |
compare-nofromrevision | Aucune révision 'from'. Spécifiez fromrev, fromtitle, ou fromid. |
compare-notorevision | Aucune révision « to ». Spécifiez torev, totitle, ou toid. |
sectionsnotsupported | Les sections ne sont pas prises en charge pour le modèle de contenu model. |
sectionreplacefailed | Impossible de fusionner la section mise à jour. |
missingparam | Au moins un des paramètres fromtitle , fromid , fromrev , fromtext , fromrelative et fromslots est obligatoire. |
missingparam | Au moins un des paramètres totitle , toid , torev , totext , torelative et toslots est obligatoire. |
Historique des paramètres
- v1.32: Ajouté
fromslots
,toslots
,fromtext-{slot}
,fromsection-{slot}
,fromcontentformat-{slot}
,fromcontentmodel-{slot}
,totext-{slot}
,tosection-{slot}
,tocontentformat-{slot}
,tocontentmodel-{slot}
- v1.30: Ajouté
frompst
,torelative
,topst
,prop
- v1.20: Ajouté
fromid
,toid
Notes supplémentaires
Pour obtenir la différence entre deux pages, un numéro de révision, un titre ou un identifiant de page doivent être fournis à la fois pour from
et to
.
Comparaison relative pour la première et la dernière révision
- Vous pouvez demander une comparaison relative de la première révision d'une page avec la révision précédente, ce qui renvoie dans le diff tout le texte de la première révision : Notez que cela n'est pas toujours vrai, car dans certains cas il peut exister un contenu par défaut de la page avant sa première révision. La propriété
fromrevid
sera absente des résultats. - D'une manière similaire, vous pouvez demander à comparer la dernière révision d'une page avec la révision suivante:
- (Remarque: ceci est la dernière révision écrite pour ce sujet. Parce que la page est protégée, il est probable qu'elle ne changera pas.) Le résultat est un diff vide, et la propriété
torevid
sera absente. Au contraire de la plupart des comparaisons de révisions, ces résultats changeront si une nouvelle révision est créée.
Le comportement dans l'API est historique. Il n'est pas cohérent avec le modèle conceptuel de l'historique des pages en tant que série de révisions. Il n'existe pas de révision previous
pour la comparaison de la première révision, ni de révision next
pour comparer la dernière révision. A cause de cela, les versions futures de MediaWiki pourront donner des résultats différents pour cet appel d'API.
Utiliser la sortie HTML
Les valeurs de prop
, diff
et parsedcomment
renvoient du code HTML.
Le code HTML de diff
est une liste de lignes de tableaux (<tr>
éléments) qui doivent se trouver dans une table avec au moins les balises suivantes :
<table class="diff">
<colgroup>
<col class="diff-marker">
<col class="diff-content">
<col class="diff-marker">
<col class="diff-content">
</colgroup>
<tbody>
ICI, PORTION DU DIFF HTML
</tbody>
</table>
Pour afficher également les métadonnées, comme l'utilisateur ou le commentaire, ajoutez des lignes supplémentaires et placez les métadonnées dans un élément <td colspan="2">
.
Pour être sûr que ce diff s'affiche correctement (par exemple, que le marqueur de diff et les colonnes de contenu ne sont pas de la même largeur), vous pouvez ajouter le module ResourceLoader mediawiki.diff.styles
à votre page:
<link rel="stylesheet" href="https://www.mediawiki.org/w/load.php?modules=mediawiki.diff.styles&only=styles">
Si vous voulez afficher le parsedcomment
, vous voudrez également ajouter le module mediawiki.legacy.shared
, qui inclut quelques styles de base pour les commentaires et les commentaires automatiques:
<link rel="stylesheet" href="https://www.mediawiki.org/w/load.php?modules=mediawiki.legacy.shared&only=styles">
Et si vous voulez afficher à la fois le code HTML diff
et parsedcomment
sur la page, vous pouvez combiner ces deux balises en une seule :
<link rel="stylesheet" href="https://www.mediawiki.org/w/load.php?modules=mediawiki.legacy.shared|mediawiki.diff.styles&only=styles">