Jump to content

Wikidata/Notes/Inclusion syntax v0.3

From Meta, a Wikimedia project coordination wiki
This is an archived version of this page, as edited by Denny Vrandečić (WMDE) (talk | contribs) at 14:54, 10 January 2013 (Accessing Item Data). It may differ significantly from the current version.
New Version (January 2013) This is a completely reworked proposal with little resemblance to the previous drafts!

This page describes the data inclusion syntax for the Wikibase client, by which the properties of data items can be included and rendered on a wiki page using templates. In short: This is how we want Wikipedia articles to include data from Wikidata.

Preliminary

The inclusion syntax presented here is meant to work for simple cases, and only for them.

Complicated cases are currently planned to be realized using Lua. We do not know yet how the binding to Lua will look like, but we are confident that it will be far easier to use than any binding to Wikitext could ever look like. (Lua would be able to access Wikidata items and then programmatically work on them).

Accessing Item Data

Properties of a Wikidata Item can be used via the #property parser function:

 {{#property:population}}

This will provide a representation of the value of the population property of the page's default item. The default item is the Wikidata item that is associated with this page via language links.

To access properties of a different item, it has to be specified explicitly, either by id

 {{#property:population|id=q12345}}

or the associated Wiki page

 {{#property:population|of=Germany}}

Formatting of qualified and sourced values

All values that are preferred are returned. The values also include qualifiers and references.

There are a number of further parameters that can be used to finetune the formatting:

  • separator: if there are several values, this is used to separate the values
  • value template: a template to call on each value, with the parameters value, qualifiers and references
  • qualifier template: a template to call on each qualifier, using the qualifier property label as the first and the qualifier values as the second parameter. Ignored if there is a qualifiers template.
  • qualifier separator: if there are several qualifiers, this is used to separate them. Ignored if there is a qualifiers template.
  • qualifiers wrapper: a template to call on the qualifiers, using the qualifiers as the parameter. Ignored if there is a qualifiers template. Ignored if there are no qualifiers.
  • qualifiers template: a template to call for all qualifiers, using the qualifier property labels as the argument names and the values as the respective value.
  • qualifiers value separator: if a single qualifier has several values, this is used to separate these values
  • reference keyvalue template: a template to call on each key-value pair of a reference, using the key label as the first and the values as the second parameter. Ignored if there is a reference template.
  • reference wrapper: a template to call on each reference, using the reference as the parameter. Ignored if there is a reference template.
  • references wrapper: a template to call on all references, using the references as the parameter. Ignored if there is a reference template. Ignored if there are nor references.
  • reference keyvalue separator: if there are several key-value pairs in one reference, this is used to separate them. Ignored if there is a reference template.
  • reference template: a template to call on each references of a value, using the key labels as the argument names and the values as the respective value.
  • reference value separator: if within a reference one key has several values, this is used to separate these values
  • reference separator: a separator to use between each reference

There is a (sensible) default value for each of these which can be changed per wiki using the messaging system.

Once you have seen this parameter list, you might understand why we want to use Lua for anything that is not "simple".

Formatting of single values

Items

  • item display template: a template that is called for items, with the named parameters label, link, id, description and property

Number

  • number display template: a template that is called for numbers, with the named parameters formatted value, value, unit, ... (to be defined once the data model is fixed)

Time

  • time display template: a template that is called for times, with the named parameters iso8601, year, month, ... (to be defined once the data model is fixed)

Coordinate

  • coordinate display template: a coordinate that is called for times, with the named parameters latitude, longitude, latitude dms, ... (to be defined once the data model is fixed)

Other

To be defined

Examples

Assumptions

The example assume reasonable default values for the above arguments. The examples assume no references, for simplicity sake. We assume here:

  • separator: ,
  • value template: {{{value}}} {{{qualifiers}}}{{{references}}}
  • qualifier template: {{{1}}} {{{2}}}
  • qualifier separator: ,
  • qualifiers wrapper: ({{{1}}})
  • qualifiers template: empty
  • qualifiers value separator: ,
  • reference keyvalue template: {{{1}}} {{{2}}}
  • reference wrapper: <ref>{{{1}}}</ref>
  • references wrapper: {{{1}}}
  • reference keyvalue separator: ,
  • reference template: empty
  • reference value separator: ,
  • reference separator: a separator to use between each reference

Example 1

Given the following statement:

Berlin


Population3,500,000[no sources]
as of 2012

{{#property:population}} will display as "3,500,000 (as of 2012)"

Example 2

Given the following statement:

Germany


ChancellorAngela Merkel[2 sources]
since 2005
Party CDU

and assuming that Template:Nothing is defined as empty, and there are articles for Angela Merkel and the CDU in the client wiki and these articles are linked to Wikidata:

Example 3

Given the following statement:

Mumbai


Population12,479,608[1 source]
as of 2011
Method Census
21,000,000[2 sources]
Method Estimate

and assuming that Template:Nothing is defined as empty, and there are articles for Estimate but not for Census in the client wiki and Estimate is linked to Wikidata and the Census item has a label:

  • {{#property:Population}} will display as "12,479,608 (as of 2011, Method Census)[5], 21,000,000 (Method Estimate)[6][7]"
  • {{#property:Population|qualifiers template=Nothing|separator= or }} will display as "12,479,608[8] or 21,000,000[9][10]"
  • {{#property:Population|qualifiers template=Nothing|reference template=Nothing|separator= or }} will display as "12,479,608 or 21,000,000"

Fake references from the examples

  1. Reference 1
  2. Reference 2
  3. Reference 1
  4. Reference 2
  5. Reference 3
  6. Reference 4
  7. Reference 5
  8. Reference 3
  9. Reference 4
  10. Reference 5