API:Compare/de
![]() | Diese Seite ist Teil der Dokumentation der MediaWiki action API. |
GET-Abfrage um den Unterschied zwischen zwei Seiten zu erhalten.
MediaWiki Version: | ≥ 1.18 |
API-Dokumentation
![]() | Die folgende Dokumentation ist die Ausgabe von 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]
Beispiel
GET-Anfrage
Antwort
{
"compare": {
"fromid": 1882196,
"fromrevid": 739666518,
"fromns": 10,
"fromtitle": "Template:Unsigned",
"toid": 32371774,
"torevid": 909784724,
"tons": 10,
"totitle": "Template:UnsignedIP",
...
}
}
Beispielcode
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 );
} );
Mögliche Fehler
Code | Information |
---|---|
compare-relative-to-nothing | No 'from' revision for torelative to be relative to. |
compare-relative-to-deleted | torelative=value kann nicht relativ zu einer gelöschten Version verwendet werden. |
missingrev-title | No current revision of title title. |
baddiff | The diff cannot be retrieved. One or both revisions do not exist or you do not have permission to view them. |
missingcontent-revid | Missing content for revision ID revid. |
invalidtitle | Ungültiger Titel „title“. |
nosuchpageid | Es gibt keine Seite mit der ID id. |
missingtitle-byname | Die Seite name ist nicht vorhanden. |
nosuchrevid | Es gibt keine Version mit der ID id. |
missingcontent-revid-role | Fehlender Inhalt für die Versionskennung id für die Rolle main. |
compare-nosuchfromsection | There is no section name in the 'from' content. |
compare-nosuchtosection | There is no section name in the 'to' content. |
compare-maintextrequired | Der Parameter fromtext-main ist erforderlich, wenn fromslots main enthält (kann nicht den Hauptschlitz löschen). |
compare-maintextrequired | Der Parameter totext-main ist erforderlich, wenn toslots main enthält (kann nicht den Hauptschlitz löschen). |
compare-notext | Der Parameter $1 kann nicht ohne $2 verwendet werden. |
compare-no-title | Cannot pre-save transform without a title. Try specifying fromtitle or totitle. |
compare-nofromrevision | Keine Version „from“. fromrev, fromtitle oder fromid angeben. |
compare-notorevision | Keine Version „to“. torev, totitle oder toid angeben. |
sectionsnotsupported | Sections are not supported for content model model. |
sectionreplacefailed | Der aktualisierte Abschnitt konnte nicht zusammengeführt werden. |
missingparam | At least one of the parameters fromtitle , fromid , fromrev , fromtext , fromrelative und fromslots is required. |
missingparam | At least one of the parameters totitle , toid , torev , totext , torelative und toslots is required. |
Parametergeschichte
- v1.32:
fromslots
,toslots
,fromtext-{slot}
,fromsection-{slot}
,fromcontentformat-{slot}
,fromcontentmodel-{slot}
,totext-{slot}
,tosection-{slot}
,tocontentformat-{slot}
,tocontentmodel-{slot}
eingeführt - v1.30: Eingeführt
frompst
,torelative
,topst
,prop
- v1.20: Eingeführt
fromid
,toid
Zusätzliche Anmerkungen
Um den Unterschied zwischen zwei Seiten zu erhalten, muss eine Versionsnummer, ein Seitentitel oder eine Seiten-ID für from
und to
angegeben werden.
Relativer Vergleich der ersten und letzten Revision
- Du kannst einen relativen Vergleich zur ersten Version einer Seite anfragen, wobei der vollständige Text der ersten Version als Diff ausgegeben wird. Beachte, dass dies nicht genau ist, da es in einigen Fällen bereits vor der ersten Version einen Standardinhalt gegeben haben kann. Die Eigenschaft
fromrevid
wird in den Ergebnissen fehlen. - Damit vergleichbar kannst du auch den nächsten relativen Vergleich mit der letzten Version einer Seite anfragen.
- (Anmerkung: Zum Zeitpunkt des Verfassens dieses Textes ist dies die letzte Version. Da die Seite geschützt ist, wird sie sich wahrscheinlich nicht ändern.) Das Ergebnis ist ein leerer Diff und
torevid
wird fehlen. Im Gegensatz zu den meisten Versionsvergleichen werden sich diese Ergebnisse ändern, wenn eine neue Version erstellt wird.
Dieses Verhalten der API ist historisch bedingt. Es ist nicht konsistent mit dem konzeptuellen Modell einer Versionsgeschichte als einer Reihe von Versionen. Es gibt keine previous
-Version, mit der die erste Version verglichen werden kann und auch keine next
-Version, mit der die letzte Version verglichen werden kann. Daher können zukünftige Versionen von MediaWiki unterschiedliche Ergebnisse für diese API-Abfrage ausgeben.
Verwenden der HTML-Ausgabe
Die prop
-Werte diff
und parsedcomment
geben HTML-Schnipsel aus.
Das diff
-HTML ist eine Liste von Tabellen-Zeilen (<tr>
-Elementen), die in eine Tabelle mit zumindest dem folgenden Markup eingebunden werden sollten:
<table class="diff">
<colgroup>
<col class="diff-marker">
<col class="diff-content">
<col class="diff-marker">
<col class="diff-content">
</colgroup>
<tbody>
DIFF-HTML-SCHNIPSEL HIER EINFÜGEN
</tbody>
</table>
Um auch Metadaten anzuzeigen, z. B. den Benutzer oder die Zusammenfassung, füge zusätzliche Zeilen hinzu und platziere die Metadaten in einem <td colspan="2">
-Element.
Um sicherzustellen, dass der Diff korrekt angezeigt wird (z. B. dass die Diff-Markierung und die Inhaltsspalten nicht die gleiche Breite haben), kannst du das ResourceLoader-Modul mediawiki.diff.styles
zur Seite hinzufügen:
<link rel="stylesheet" href="https://www.mediawiki.org/w/load.php?modules=mediawiki.diff.styles&only=styles">
Wenn du parsedcomment
anzeigen möchtest, möchtest du vermutlich das mediawiki.legacy.shared
-Modul hinzufügen, das einige Basisdarstellungen für Zusammenfassungen und automatische Zusammenfassungen enthält:
<link rel="stylesheet" href="https://www.mediawiki.org/w/load.php?modules=mediawiki.legacy.shared&only=styles">
Wenn du sowohl das diff
-HTML als auch das parsedcomment
-HTML auf der Seite anzeigen möchtest, kannst du diese beiden Tags in einem kombinieren:
<link rel="stylesheet" href="https://www.mediawiki.org/w/load.php?modules=mediawiki.legacy.shared|mediawiki.diff.styles&only=styles">