模板:Diff/doc

来自决策链云智库

This template is intended to be useful for creating links to "diffs"; that is, links to pages that show the differences between two versions of a wiki page.

Every version of a page has a revision ID, which you can find from the history of the page by looking at the timestamp link for the edit. The timestamp link is in this form:
http[s]://en.wikipedia.org/w/index.php?title=SomePageName&oldid=442212827
The number after oldid= is the revision ID.

Given one or two revision IDs, you can construct links to several types of diffs.

Usage

{{Diff|title|diff|oldid|label|diffonly=yes}}
  • title模板:SndsThe title of the page (optional in most cases)
  • diff模板:SndsThe ID or keyword that is used against the base ID. Possible keywords are:
    cur模板:SndsCompare with the current version of a page.
    prev模板:SndsCompare with the previous version of a page.
    next模板:SndsCompare with the next version of a page.
    id模板:SndsThis should be larger than oldid.
  • oldid模板:SndsThe base ID onto which the diff is generated.
  • label模板:SndsText to display as link (optional)模板:Nsmdnsno label will generate a numbered link as the label.
  • |diffonly=yes模板:SndsDisplays the page comparisons only (optional)模板:Nsmdnsparameter name required if used.

Only the diff parameter is required; all other parameters are optional. Omitted parameters must be empty (by using a double pipe). You can also use the named parameters title, diff, oldid, and label.

Helper subtemplate

In order to make this template simpler to use the helper subtemplate {{Diff/translator}} is available, to be used only in the preview window.

Syntax
{{Diff/translator|label|url=diff URL}}

For instance, imagine you want to refer to the following diff URL: https://en.wikipedia.org/w/index.php?title=Main_Page&diff=139993&oldid=139992&diffonly=1; you only need to transcribe that URL in the {{Diff/translator}} subtemplate and produce a preview, without saving the page:

{{Diff/translator|Sic exorsi sumus|url=https://en.wikipedia.org/w/index.php?title=Main_Page&diff=139993&oldid=139992&diffonly=1}}
模板:Diff/translator

Now copy the code generated (模板:Diff/translator) into the edit window where {{Diff/translator}} was and publish the page.

Examples

Below each example in the left-hand column is the pseudocode for that example in 模板:Font color and indented. Elements that should be entered literally are in 模板:Font color. When a parameter is left blank, the resulting two adjacent pipes are underlined (but not bolded): 模板:Font color.

Code Output
{{模板:Uu|Main Page|prev|204901573|Diff between a numbered version and the previous version}}
模板:Font color
Diff between a numbered version and the previous version

This is the form that would be used most often.

  • The diff= parameter (parameter number 2) should be the word prev.
  • The oldid= parameter (parameter number 3) should be the known revision number.
{{模板:Uu|Foobar|616706711|616706707|Diff between two numbered versions of a page}}
模板:Font color
Diff between two numbered versions of a page
  • The title= parameter (parameter number 1) should be a name of a page, for instance Foobar.
  • The diff= parameter (parameter number 2) should be the larger revision number.
  • The oldid= parameter (parameter number 3) should be the smaller revision number.
{{模板:Uu||616706711|616706707|Diff between two numbered versions of a page without title parameter}}
模板:Font color
Diff between two numbered versions of a page without title parameter
  • The title= parameter (parameter number 1) may be left blank, thereby leaving a double pipe.
  • The diff= parameter (parameter number 2) should be the larger revision number.
  • The oldid= parameter (parameter number 3) should be the smaller revision number.
{{模板:Uu|Wikipedia:Pagediff|204934693|204901573|Diff between two numbered versions of a page in Wikipedia namespace}}
模板:Font color
Diff between two numbered versions of a page in Wikipedia namespace
  • The title= parameter (parameter number 1) should be a name of a page, for instance Wikipedia:Pagediff.
  • The diff= parameter (parameter number 2) should be the page revision to appear on the right (proposed change).
  • The oldid= parameter (parameter number 3) should be the page revision to appear on the left (original).
{{模板:Uu|Main Page|next|204901573|Diff between a numbered version and the subsequent version}}
模板:Font color
Diff between a numbered version and the subsequent version
  • The diff= parameter (parameter number 2) should be the word next.
  • The oldid= parameter (parameter number 3) should be the known revision number.
{{模板:Uu|Main Page|cur|204901573|Diff between a numbered version and the current version of a page}}
模板:Font color
Diff between a numbered version and the current version of a page
  • The diff= parameter (parameter number 2) should be the word cur.
  • The oldid= parameter (parameter number 3) should be the known revision number.
{{模板:Uu|Main Page|cur||Diff showing the most recent change to a page}}
模板:Font color
Diff showing the most recent change to a page
  • The diff= parameter (parameter number 2) should be the word cur.
  • The oldid= parameter (parameter number 3) should be empty.
{{模板:Uu|Main Page||204901573|A link to a numbered version of a page}}
模板:Font color
A link to a numbered version of a page
  • The diff= parameter (parameter number 2) should be empty.
  • The oldid= parameter (parameter number 3) should be the known revision number.
  • The result is not actually a diff, so this might be considered misuse of the template. See the {{oldid}} template.
{{模板:Uu|Main Page|204901573|202506579|Comparison display without page display of two numbered versions of a page |diffonly=yes}}
模板:Font color
Comparison display without page display of two numbered versions of a page
  • The title= parameter (parameter number 1) should be a name of a page, for instance Main Page.
  • The diff= parameter (parameter number 2) should be the larger revision number.
  • The oldid= parameter (parameter number 3) should be the smaller revision number.
  • The diffonly= parameter, which must include the parameter name, can only be set to yes

TemplateData

This is the TemplateData for this template used by TemplateWizard, VisualEditor and other tools. See a monthly parameter usage report for Template:Diff in articles based on its TemplateData.

TemplateData for Diff

A template that is intended to be useful for creating links to diffs; that is, links to pages that show the differences between two versions of a wiki page.

模板参数

参数描述类型状态
titletitlepage1

The title of the page.

页面名称可选
Diffdiff2

The ID or keyword that is used against the base ID. Possible keywords are:

  • cur – compare with the current version of a page.
  • prev – compare with the previous version of a page.
  • next – compare with the next version of a page.
  • <var>id</var> – compare against this revision ID; should be <em>larger</em> than <code>oldid</code>.

单行文本必需
Oldidoldid3

The base ID onto which the diff is generated. Some number like "442212827" (without the quotes).

数字可选
Labellabel4

Text to display as link. No label will give a numbered link.

单行文本可选
Diffonlydiffonly

Displays the page comparisons only. If you use this, the value should be "yes" (without the quotes).

单行文本可选

See also