Module:Wikidata/doc explained

Methods

The module "" contains the following methods, that allow the calling script to retrieve the value for any property from Wikidata by supplying the property ID as the first parameter:

Wikidata qualifier values (if present) can be retrieved by the following methods:

If the property is not defined in Wikidata for the article that invokes this code, then an empty string ("") is returned.

Other methods:

Call as <nowiki>{{#invoke:Wikidata |getImageLegend | <PARAMETER> | lang=<ISO-639code> |id=<QID>}}</nowiki>

Returns PARAMETER, unless it is equal to "FETCH_WIKIDATA", from Item QID (expensive call). If QID is omitted or blank, the current article is used (not an expensive call). If lang is omitted, it uses the local wiki language, otherwise it uses the provided ISO-639 language code.

The label is returned from the first image with 'preferred' rank; or from the first image with 'normal' rank if no image has preferred rank.

Arbitrary Access

As of 16 September 2015, it is now possible to fetch data from other articles by using their QID.The following call:

will do the same as getValue, but takes an extra parameter, which is the QID of the Wikidata item that you want to get the property value from.For example:

will fetch a list of the linked values for 'spouse' (P26) from redirect page title Richard Burton (actor) (corresponding to Wikidata label) from anywhere in the English Wikipedia.

This means that testing environments may be set up in user space, but remember that these calls are classed as expensive, so please use them as sparingly as possible.

Parameters

Please note that lower-case parameters are no longer supported by the wikibase call: p123, so please check that upper-case, like P123, is used if problems should arise.

Usage

Example: spouse (P26)

Example in Infobox template

Inside an infobox definition, it may be called like this:

which causes the infobox to:

  1. not display spouse if the infobox parameter |spouse is set to be blank (as "| spouse =")
  2. display the linked value(s) from Wikidata if the infobox parameter |spouse is not supplied
  3. display the local infobox parameter |spouse if it is supplied (e.g. "|spouse = Hillary Rodham Clinton")

Optionally, it could be called as:

which causes the infobox to:

  1. not display spouse if the infobox parameter |spouse is set to be blank (as "| spouse ="}
  2. not display spouse if the infobox parameter |spouse is not supplied
  3. display the local infobox parameter |spouse if it is supplied (e.g. "|spouse = Hillary Rodham Clinton")
  4. display the linked value(s) from Wikidata if the infobox parameter is locally set to FETCH_WIKIDATA

See for a modification that allows fields, on a per article basis, to be blacklisted so that they never display. It also allows the editor to specify, on a per article basis, which fields may be automatically fetched from Wikidata when local parameter is supplied; the default is none, allowing an infobox to be modified to accept Wikidata without any change in the articles using the infobox until the functionality is enabled in the article.

Example:birth place

This works in just the same way as the calls above:

Example:gender

We don't want the returned value linked, so use:

Example:date of birth

If we want the date of birth in dmy format, we use:

If we want the date of birth in mdy format, we use:

If we want a year of birth, we use:

If we want a year of birth that may be BC, but should read "BCE", we use:

Example: Linking to Wikidata item

Use the following code to just retrieve the Q-ID:

Linking to Wikidata used the usual Wiki markup:

Example: Linking to another wiki page

Use code like this to link to another wiki. English Wikivoyage in the example:

Testing

Testing spouse

Copy and paste the following into any article and preview it (please don't save!): * - * - * -

In Bill Clinton you should get:

In Barack Obama you should get:

In Richard Burton you should get:

In Franz Kafka you should get:

Testing birthplace

Copy and paste the following into any article and preview it (please don't save!): * - * - * - Try William Ellery and check that the Wikidata call correctly disambiguates.

Testing getValue, getRawValue and getDateValue

Copy and paste the following into any article and preview it (please don't save!): * - * - * - * - * - * - * - * - This should return the Wikidata values for birthplace, spouse, citizenship, religion, gender, date of birth (twice) and year of birth, if they exist. The dob is first in dmy format and then in mdy.

Testing dates BC/BCE

Copy and paste the following into a short section of article such as Horace #See also and preview it (please don't save!): * - * - This should return 65 BC and 65 BCE, respectively.

See also