This is the documentation page for ମଡ୍ୟୁଲ:WikidataIB


This module is designed specifically to implement a mechanism which moves control of whether Wikidata values are used in an infobox from the template coder at the infobox design level to the editor at the article level. It should only be used inside an infobox.

The module provides these calls specifically for use in infoboxes at present:

  1. getValue
  2. getPreferredValue
  3. getSourcedValue
  4. getCoords
  5. getQualifierValue

The call getSourcedValue is kept for backwards compatibility as it is now redundant to getValue which can do the same job using the |onlysourced=true parameter.

There are also these utility calls:

  1. getLink
  2. getLabel
  3. getAT
  4. formatDate
  5. checkBlacklist

Generalised calls:

{{#invoke:WikidataIB |getValue |<PropertyID> |name=<fieldname> |suppressfields=<list of fields which will never display> |fetchwikidata=<list of fields to fetch values from Wikidata> |onlysourced=<yes/no> |noicon=<yes/no> |df=<dmy/mdy/y> |bc=<BC/BCE> |<local parameter>}}
{{#invoke:WikidataIB |getPreferredValue |<PropertyID> |name=<fieldname> |suppressfields=<list of fields which will never display> |fetchwikidata=<list of fields to fetch values from Wikidata> |onlysourced=<yes/no> |noicon=<yes/no> |df=<dmy/mdy/y> |bc=<BC/BCE> |<local parameter>}}
{{#invoke:WikidataIB |getSourcedValue |<PropertyID> |name=<fieldname> |suppressfields=<list of fields which will never display> |fetchwikidata=<list of fields to fetch values from Wikidata> |<local parameter>}}
{{#invoke:WikidataIB |getCoords |name=<fieldname> |suppressfields=<list of fields which will never display> |fetchwikidata=<list of fields to fetch values from Wikidata> |<local parameter>}}
{{#invoke:WikidataIB |getQualifierValue |<PropertyID> |pval=<ID of target value for the property> |qual=<qualifier ID for that target value> |name=<fieldname> |suppressfields=<list of fields which will never display> |fetchwikidata=<list of fields to fetch values from Wikidata> |onlysourced=<yes/no>}}
  • getValue can also take a named parameter |qid= which is the Wikidata ID for the article. This will not normally be used but is available for testing, although it makes the call expensive.
  • The property to be returned is passed in the first unnamed property.
  • The name of the field that this function is called from is passed in the named parameter |name=, which is first checked against a blacklist of fields that are never to be displayed, (i.e. the call must return nil in all circumstances). If the field is not on the blacklist, it is then checked against a whitelist. If the name of the field matches, the call will return any locally supplied value if it is supplied as the second unnamed parameter, or the Wikidata value otherwise.
  • The name is compulsory when the blacklist or whitelist is used, so the module returns nil if it is not supplied.
  • The blacklist is passed in the named parameter |suppressfields=
  • The whitelist is passed in the named parameter |fetchwikidata=

The getValue function will accept a boolean parameter onlysourced which will suppress return of Wikidata values that are unsourced or only sourced to Wikipedia. The absence of the parameter, an empty parameter (|onlysourced=) and the empty string ("") all default to true (i.e. only referenced values are returned). The values no, false and 0 are treated as false (i.e. all values are returned); any other value is true (although |onlysourced=yes is recommended for readability).

The getValue function will accept a boolean parameter noicon which will suppress the trailing "edit at Wikidata" icon for when the returned value is to be further processed by the infobox (e.g. a url). The absence of the parameter or an empty parameter (|noicon=) default to false (i.e. the icon is added). The empty string ("") and the values no, false and 0 are treated as false; any other value is true (although |noicon=true is recommended for readability).

In order to handle the requirement for dates in mdy, dmy or just year formats, getValue accepts a named parameter |df= that may take the values "dmy", "mdy", or "y" - default is "dmy".

As an article may require either of suffixes BC and BCE, getValue accepts a named parameter |bc= that may take the values "BC", or "BCE" - default is "BCE". Some test cases are shown at Module talk:WikidataIB #Calls to getValue for dates.

Formatting multiple returned values

ସମ୍ପାଦନା
  • |sorted=<yes|no> is a boolean passed to enable sorting of the values returned. No parameter, or an empty string, or "false", or "no", or "0" disables sorting. It's only a very dumb alphabetical sort and sorts linked values as "[[ ..."
  • |sep=<separator characters> allows the separator between multiple returned values to be defined. The default is ", " (comma plus normal space). If the separator has leading or trailing spaces, enclose it in double quotes (e.g. |sep=" - "). Any double quotes are stripped from the separator. The pipe character (|) must be escaped as {{!}}.
  • |list=<hlist|ubl> allows multiple returned values to be displayed as a horizontal list (|list=hlist), or a vertical unbulleted list (|list=ubl). These override the separator and do not display the 'pen icon' linked to "Edit at Wikidata"

Function getPreferredValue

ସମ୍ପାଦନା

The getPreferredValue function works exactly like getValue, taking the same parameters, but if any values for a property have the preferred rank set, it will only return those values.

Comparison example

ସମ୍ପାଦନା

Fetching the name(s) of the (P170) from (Q29016906):

  • {{#invoke:WikidataIB |getValue |P170 |fetchwikidata=ALL |qid=Q29016906 |onlysourced=no}} → Artemisia Gentileschi, Aniella di Beltrano, Massimo Stanzione  
  • {{#invoke:WikidataIB |getPreferredValue |P170 |fetchwikidata=ALL |qid=Q29016906 |onlysourced=no}} → Artemisia Gentileschi  

Function getSourcedValue

ସମ୍ପାଦନା
  • getSourcedValue works exactly as getValue does, but only returns values that have a reference to something other than a Wikipedia. That's not a guarantee of a reliable source, but it helps separate the wheat from the chaff.

Example of getSourcedValue

ସମ୍ପାଦନା

From (Q151973):

Burton currently has four values for ବୃତ୍ତି (P106) on Wikidata:

Using getValue in Richard Burton:

  • {{#invoke:WikidataIB |getValue |P106 |name=occupation |fetchwikidata=ALL}} -> କଥାଚିତ୍ର ଅଭିନେତା, diarist, ମଞ୍ଚ ଅଭିନେତା, ଅଭିନେତ୍ରୀ, କଥାଚିତ୍ର ନିର୍ଦ୍ଦେଶକ, କଥାଚିତ୍ର ପ୍ରଯୋଜକ, producer, ନିର୍ଦ୍ଦେଶକ  

Using getSourcedValue in Richard Burton:

  • {{#invoke:WikidataIB |getSourcedValue |P106 |name=occupation |fetchwikidata=ALL}} -> Script error: The function "getSourcedValue" does not exist.

Function getCoords

ସମ୍ପାଦନା
  • getCoords can also take a named parameter |qid= which is the Wikidata ID for the article. This will not normally be used but is available for testing, although it makes the call expensive.
  • The coordinates from Wikidata are parsed and passed to Template:Coord which returns the display as if it were called manually.
  • The name of the field that this function is called from is passed in the named parameter |name=, which is first checked against a blacklist of fields that are never to be displayed, (i.e. the call must return nil in all circumstances). If the field is not on the blacklist, it is then checked against a whitelist. If the name of the field matches, the call will return any locally supplied value if it is supplied as the unnamed parameter, or the Wikidata value otherwise.
  • The name is compulsory when the blacklist or whitelist is used, so the module returns nil if it is not supplied.
  • The blacklist is passed in the named parameter |suppressfields=
  • The whitelist is passed in the named parameter |fetchwikidata=

Function getQualifierValue

ସମ୍ପାଦନା

The getQualifierValue is for use when we want to fetch the value of a qualifier. We need to know the property and the value of the property that it qualifies. The parameters are:

  • The property ID passed in the unnamed parameter (or |1=)
  • The target value for that property in |pval=
  • The qualifier ID for that target value in |qual=
  • The name of the field where its called from to implement whitelisting and blacklisting of the property in
  • The list of fields to be fetched ("whitelist") in |fetchwikidata= - accepts |fetchwikidata=ALL to fetch all fields
  • Optional list of fields not to be displayed ("blacklist") in |suppressfields=
  • Optional boolean to specify whether only sourced values of the property are returned (defaults to "no") in |onlysourced=
  • Optional item ID for arbitrary access (expensive call!) in |qid=

Example of getQualifierValue

ସମ୍ପାଦନା

In (Q1513315) there is a property (P793), which has a value (Q385378). That has two qualifiers, ଆରମ୍ଭ ସମୟ (P580) and ଶେଷ ସମୟ (P582). To get the start date:

  • {{#invoke:WikidataIB |getQualifierValue |P793 |pval=Q385378 |qual=P580 |name=xyz |fetchwikidata=ALL }}

In South Pole Telescope it returns:

  • ନଭେମ୍ବର ୨୦୦୬  

getLink returns the label for a Qid wiki-linked to the local article (if the article exists). If label doesn't exist, it returns the Qid wiki-linked to the local article (if the article exists).

getLabel returns the label for a Qid. If label doesn't exist, it returns the Qid. Note that this is the label given to the Wikidata entry in the same language as the current Wikipedia, if the label exists.

  • {{#invoke:WikidataIB |getLabel |Q29016906}} → Corisca and the Satyr
  • {{#invoke:WikidataIB |getLabel |Q3621491}} → ପ୍ରତ୍ନ‌ତ‌ତ୍ତ୍ୱବିଦ

getAT returns the article title for a Qid. If the article title doesn't exist, it returns nothing. Note that this is the title of the article in the current Wikipedia, if the interlanguage link exists in the Wikidata entry.

  • {{#invoke:WikidataIB |getAT |Q29016906}}
  • {{#invoke:WikidataIB |getAT |Q3621491}}

Function formatDate

ସମ୍ପାଦନା

formatDate accepts a datetime of the usual format from mw.wikibase.entity:formatPropertyValues, like "1 August 30 BCE" as parameter 1 and formats it according to the df (date format) and bc parameters.

  • {{#invoke:WikidataIB |formatDate | 1 August 30 BCE |bc=BCE |df=dmy}} → 1 August 30 BCE
  • {{#invoke:WikidataIB |formatDate | 1 August 30 BCE |bc=BC |df=mdy}} → August 1, 30 BC
  • df = "dmy" / "mdy" / "y" - default is "dmy"
  • bc = "BC" / "BCE" - default is "BCE"

Coding into an infobox

ସମ୍ପାଦନା

Typically, the getValue call will be invoked in an infobox definition, using appropriate template parameters. One simple implementation is given as an example in Template:Infobox book/Wikidata/Sandbox. As an illustration, the 'author' field in the infobox is coded like this:

| label2  = Author{{#if:{{{authors|}}}|s}}
|  data2  = {{#invoke:WikidataIB |getValue |P50 |name=author |fetchwikidata={{{fetchwikidata|}}} |suppressfields={{{suppressfields|}}} |{{{authors|{{{author|}}}}}} }}

The property to be fetched is the first unnamed parameter. In this case it is ଲେଖକ (P50).

The name of the field is passed in |name= and that name is checked against the blacklist and the whitelist. To always suppress the author field in a particular article, an editor will set |suppressfields=author in the infobox. The author field will then never be displayed.

If the field is not blacklisted, then the infobox can be set to display a locally supplied value for author simply by setting |author=George Orwell, for example, in the infobox. It also accepts |authors=. If the name of the field is on the whitelist, e.g. |fetchwikidata=author; genre; pub_date; pages; dewey; congress, and the local value is not supplied, then the infobox will display the value retrieved from Wikidata. Any separators can be used, except | and {}.

As a shorthand, |fetchwikidata=ALL will fetch all of the fields that are not blacklisted, as long as no local value is already provided in the article for a given field.

Since Wikidata labels are normally lower case, the sentence case function from Module:String2 can be used to capitalise the first letter of the returned text, e.g.

  • {{#invoke:String2 | sentence | {{#invoke:WikidataIB |getValue |P136 |name=genre |fetchwikidata=ALL |onlysourced=false}} }} in (Q1396889) produces:
  • Roman à clef, satirical fiction, ନୀତିଶିକ୍ଷା, dystopian fiction  

The getCoords call will display the output of Template:Coord when supplied with the coordinates returned from Wikidata.There's an example in Template:Sandbox/Infobox biosphere reserve where it's coded like this:

|label20 = Coordinates
| data20 = {{#invoke:WikidataIB |getCoords |name=coordinates |suppressfields={{{suppressfields|}}} |fetchwikidata={{{fetchwikidata|}}} |{{{coordinates|}}} }}

Upgrading existing infoboxes

ସମ୍ପାଦନା

Since the parameter |fetchwikidata= is needed for any Wikidata functionality, an existing infobox may be replaced by an infobox incorporating these calls without any change whatsoever to any article. Each article using the new infobox can later be enabled by supplying |fetchwikidata=ALL, or a list of required fields for that article. At that point, the onus is on the editor enabling the functionality to check that no unwanted fields are now being displayed. If so, they can be added to a blacklist for the article by setting |suppressfields= to the list of unwanted fields.

Where it will always be essential for a particular field to only contain values that are referenced, use getValue, making sure that |onlysourced= is not set to 'false', '0' or 'no'. By default it will exclude values that are unsourced or only sourced to a Wikipedia, thus making the job of checking easier at the article level. If unsourced data is acceptable (!), set |onlysourced=true. As it is beyond my wit to produce an automated mechanism that knows whether an existing source is reliable or not in a given context, that job must still be performed at the article level by an editor familiar with the subject. It should always be done when first enabling Wikidata for that article.

This section is taken from Template:Infobox book/Wikidata/Sandbox/doc.

{{Infobox book/Wikidata/Sandbox
| suppressfields =
| fetchwikidata  =
| name           = Animal Farm
| title_orig     = Animal Farm: A Fairy Story
| image          = Animal Farm - 1st edition.jpg
| image_size     = 200px
| caption        = First edition cover
| author         = [[George Orwell]]
| country        = United Kingdom
| language       = English
| genre          = Political satire
}}

Works as a non-aware infobox: only locally supplied parameters are displayed.

{{Infobox book/Wikidata/Sandbox
| name           = Animal Farm
| title_orig     = Animal Farm: A Fairy Story
| image          = Animal Farm - 1st edition.jpg
| image_size     = 200px
| caption        = First edition cover
| author         = [[George Orwell]]
| country        = United Kingdom
| language       = English
| genre          = Political satire
}}

The blacklist and whitelist can be omitted if unused

{{Infobox book/Wikidata/Sandbox
| suppressfields = 
| fetchwikidata  = author; genre; pub_date; pages; dewey; congress
}}

Fetches all of its values from Wikidata.

{{Infobox book/Wikidata/Sandbox
| fetchwikidata  = ALL
}}

As shorthand, the |fetchwikidata= can be set to ALL to fetch all available fields. Any of them can be suppressed by |suppressfields=, or overridden by supplying a local value.

Never display genre

ସମ୍ପାଦନା
{{Infobox book/Wikidata/Sandbox
| suppressfields = genre
| fetchwikidata  = author; genre; pub_date; pages; dewey; congress
}}

The genre field will always be suppressed, even if a local value is supplied.

{{Infobox book/Wikidata/Sandbox
| suppressfields = genre
| fetchwikidata  = author; genre; pub_date; pages; dewey; congress
| genre          = Political satire
}}
{{Infobox book/Wikidata/Sandbox
| fetchwikidata  = author; genre; pub_date; pages; dewey; congress
| genre          = Political satire
}}

The genre field is set to display "Political satire", no matter what is stored in Wikidata.

{{Infobox book/Wikidata/Sandbox
| fetchwikidata  = ALL
| genre          = Novel
}}

The genre field is set to display "Novel", no matter what is stored in Wikidata.

{{Infobox book/Wikidata/Sandbox
| suppressfields = 
| fetchwikidata  = author; pub_date; pages; dewey; congress
}}

The genre field will not be fetched from Wikidata.

{{Sandbox/Infobox biosphere reserve
| fetchwikidata = ALL
}}

Displays coordinates when used in an article where Wikidata has coordinates.