API:Compara

From MediaWiki.org
Jump to navigation Jump to search
This page is a translated version of the page API:Compare and the translation is 27% complete.
Other languages:
English • ‎dansk • ‎español • ‎français • ‎polski • ‎русский • ‎ไทย • ‎日本語

Conseguir la diferencia entre dos páginas.

A revision number, a page title, or a page ID for both "from" and "to" must be passed.

Parámetros

  • fromtitle: Primer título para comparar.
  • fromid: Primera ID de página para comparar. Type: integer 1.20+
  • fromrev: Primera revisión para comparar. Type: integer
  • fromtext: Use this text instead of the content specified by fromtitle, fromid or fromrev. 1.30+
  • frompst: Do a pre-save transform on fromtext. Type: boolean 1.30+
  • totitle: Segundo título para comparar.
  • toid: Segunda ID de página para comparar. Type: integer 1.20+
  • torev: Segunda revisión para comparar. Type: integer
  • torelative: Compare to a relative revision of fromtitle, fromid or fromrev. All the other "to" options will be ignored. Possible values: prev, next, cur 1.30+
  • totext: Use this text instead of the content specified by totitle, toid, torev, or torelative. 1.30+
  • topst: Do a pre-save transform on totext. Type: boolean 1.30+
  • prop: Which pieces of information to get. (Default: diff|ids|title) 1.30+
    • diff: La HTML diferencia
    • diffsize: The size of the diff HTML, in bytes.
    • rel: The revision IDs of revisions 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 user name and ID of the "from" and "to" revisions.
    • comment: The comment on the "from" and "to" revisions.
    • parsedcomment: The parsed comment on the "from" and "to" revisions.
    • size: The size (in bytes) of the "from" and "to" revisions.

Relative comparison at first and last revision

You can ask for a relative comparison to prev at the first revision of a page:

https://en.wikipedia.org/w/api.php?action=compare&fromrev=14189795&torelative=prev

This will result in the full text of the first revision being returned as the diff. Note that this is not accurate, since in some cases there may be default content for the page before its first revision. The fromrevid property will be absent from the results.

Similarly, you can ask for the next relative comparison on the last revision of a page:

https://en.wikipedia.org/w/api.php?action=compare&fromrev=874792395&torelative=next

(Note: this is the last revision as of the writing of this topic. Because the page is protected, it probably should not change.) The result is an empty diff, and the torevid will be absent. Unlike most revision comparisons, these results will change if a new revision is created.

This behaviour in the API is historical. It isn't consistent with the conceptual model of page history as a series of revisions. There is no "previous" revision to compare against the first revision, nor is there a "next" revision to compare against the last. Because of this, future versions of MediaWiki may give different results for this API call.

Ejemplo

Compare two revisions from the same page

Compare the current revisions of two different pages

Compare a revision of a page to some text

Using the HTML output

The prop values diff and parsedcomment return HTML snippets. The diff HTML is a list of table rows (<tr> elements) which should be embedded into a table with at least the following markup:

<table class="diff">
  <colgroup>
    <col class="diff-marker">
    <col class="diff-content">
    <col class="diff-marker">
    <col class="diff-content">
  </colgroup>
  <tbody>
    DIFF HTML SNIPPET GOES HERE
  </tbody>
</table>

To display metadata as well, e. g. the user or comment, add extra rows and place the metadata inside a <td colspan="2"> element.

To make sure this diff displays correctly (e. g., that the diff marker and content columns aren’t the same width), you can add the mediawiki.diff.styles ResourceLoader module to your page:

<link rel="stylesheet" href="https://www.mediawiki.org/w/load.php?modules=mediawiki.diff.styles&only=styles">

If you want to display the parsedcomment, you will likewise want to add the mediawiki.legacy.shared module, which includes some basic styles for comments and autocomments:

<link rel="stylesheet" href="https://www.mediawiki.org/w/load.php?modules=mediawiki.legacy.shared&only=styles">

And if you want to display both the diff and the parsedcomment HTML on the page, you can combine these two tags into one:

<link rel="stylesheet" href="https://www.mediawiki.org/w/load.php?modules=mediawiki.legacy.shared|mediawiki.diff.styles&only=styles">



action=compare

(main | compare)

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.

Parameters:
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 number. 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, text/css, text/plain, text/x-wiki, text/javascript
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, SecurePoll, sanitized-css, MassMessageListContent, flow-board, Scribunto, JsonSchema, NewsletterContent, wikitext, javascript, json, css, text
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, text/css, text/plain, text/x-wiki, text/javascript
fromcontentmodel
Deprecated.

Specify fromslots=main and use fromcontentmodel-main instead.

One of the following values: GadgetDefinition, SecurePoll, sanitized-css, MassMessageListContent, flow-board, Scribunto, JsonSchema, NewsletterContent, wikitext, javascript, json, css, text
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: prev, next, cur
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 number. 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, text/css, text/plain, text/x-wiki, text/javascript
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, SecurePoll, sanitized-css, MassMessageListContent, flow-board, Scribunto, JsonSchema, NewsletterContent, wikitext, javascript, json, css, text
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, text/css, text/plain, text/x-wiki, text/javascript
tocontentmodel
Deprecated.

Specify toslots=main and use tocontentmodel-main instead.

One of the following values: GadgetDefinition, SecurePoll, sanitized-css, MassMessageListContent, flow-board, Scribunto, JsonSchema, NewsletterContent, wikitext, javascript, json, css, text
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 user name and ID of the 'from' and 'to' revisions.
comment
The comment on the 'from' and 'to' revisions.
parsedcomment
The parsed comment on the 'from' and 'to' revisions.
size
The size of the 'from' and 'to' revisions.
Values (separate with | or alternative): diff, diffsize, rel, ids, title, user, comment, parsedcomment, size
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 *.
Example:
Create a diff between revision 1 and 2.
api.php?action=compare&fromrev=1&torev=2 [open in sandbox]