Content deleted Content added
mention that references get dropped from getValue, and give a link to talk |
consistency |
||
(35 intermediate revisions by 23 users not shown) | |||
Line 1:
{{Ombox|image=[[File:Stop hand nuvola.svg|40px]]|type=delete|text=[[Module:Wikidata]] is [[deprecation|deprecated]]. Please use [[Module:WikidataIB]] or [[Module:Wd]] instead.}}
{{module rating|
{{High-use}}
== Methods ==
The module "{{BASEPAGENAME}}" 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:
* <
* <
* <
* <
* <code>getUnits</code> This takes a propertyID which is a quantity as the first parameter, and returns the name of the units that the property is using on the current page. It returns empty if the property is not a quantity type or if the value is not set. The second parameter may be used to override fetching from Wikidata, if it is anything other than "FETCH_WIKIDATA".
* <code>getUnitID</code> This takes a propertyID which is a quantity as the first parameter, and returns the QID of the units that the property is using on the current page. It returns empty if the property is not a quantity type or if the value is not set. The second parameter may be used to override fetching from Wikidata, if it is anything other than "FETCH_WIKIDATA".
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:
* <
* <
* <
* <
* <
* <code>getImageLegend</code>: returns an image legend (image is property P18; image legend is property P2096).
*: Call as <code><nowiki>{{#invoke:Wikidata |getImageLegend | <PARAMETER> | lang=<ISO-639code> |id=<QID>}}</nowiki></code>
*: 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.
* <code>getValueShortName</code>: returns the same data as getValue, but utilizes the property [[d:Property:P1813|short name]] as the label, if available. This allows for piped links to use a shorter label where preferred. If short name is not set on the item, the normal label is used.
=== Arbitrary Access ===
As of 16 September 2015, it is now possible to fetch data from other articles by using their QID.
The following call:
* <code><nowiki>{{#invoke:Wikidata|getValueFromID|<QID>|<Property>|FETCH_WIKIDATA}}</nowiki></code>
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:
* <code><nowiki>{{#invoke:Wikidata|getValueFromID|
will fetch a list of the linked values for 'spouse' (P26) from
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.
Line 39 ⟶ 46:
* For the generalized unlinked case (getRawValue), two unnamed parameters are supplied. The first is the ID of the property that is to be retrieved (e.g. P21 for gender). The second may be null, "FETCH_WIKIDATA", or any other string, which becomes the returned value.
* For the generalized date case (getDateValue), three unnamed parameters are supplied. The first is the ID of the property that is to be retrieved (e.g. P569 for date of birth). The second may be null, "FETCH_WIKIDATA", or any other string, which becomes the returned value. The third is the format that the date should be returned in, either dmy, mdy, my, or y.
Please note that lower-case parameters are no longer supported by the wikibase call: <s>p123</s>, so please check that upper-case, like P123, is used if problems should arise.
== Usage ==
=== Example: spouse (P26) ===
* <code><nowiki>{{#invoke:Wikidata|getValue|P26|}}</nowiki></code> = returns nothing, so suppresses the display of spouse in an infobox
* <code><nowiki>{{#invoke:Wikidata|getValue|P26|FETCH_WIKIDATA}}</nowiki></code> = returns the linked value(s) of property P26 (spouse) stored in wikidata for the corresponding article (e.g. for article [[Bill Clinton]], it returns [[Hillary
* <code><nowiki>{{#invoke:Wikidata|getValue|P26|[[Hillary Rodham Clinton]]}}</nowiki></code> = returns [[Hillary Rodham Clinton]], allowing an infobox to use a local value rather than the value stored in Wikidata.
=== Example in Infobox template ===
Line 51 ⟶ 58:
* <code><nowiki>| data55 = {{#invoke:Wikidata|getValue|P26|{{{spouse|FETCH_WIKIDATA}}} }}</nowiki></code>
which causes the infobox to:
# not display spouse if the infobox parameter <code>|spouse</code> is set to be blank (as <code>"| spouse ="</code>
# display the linked value(s) from Wikidata if the infobox parameter <code>|spouse</code> is not supplied
# display the local infobox parameter <code>|spouse</code> if it is supplied (e.g. <code>"|spouse = Hillary Rodham Clinton"</code>)
Optionally, it could be called as:
* <code><nowiki>| data55 = {{#invoke:Wikidata|getValue|P26|{{{spouse|}}} }}</nowiki></code>
which causes the infobox to:
# not display spouse if the infobox parameter <code>|spouse</code> is set to be blank (as <code>"| spouse ="</code>}
# not display spouse if the infobox parameter <code>|spouse</code> is not supplied
# display the local infobox parameter <code>|spouse</code> if it is supplied (e.g. <code>"|spouse = Hillary Rodham Clinton"</code>)
# display the linked value(s) from Wikidata if the infobox parameter is locally set to FETCH_WIKIDATA
See [[Module:WikidataIB]] 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 ===
Line 97 ⟶ 110:
=== Testing spouse ===
Copy and paste the following into any article and preview it (please don't save!):
<syntaxhighlight lang="wikitext">
* - {{#invoke:Wikidata|getValue|P26|}}
* - {{#invoke:Wikidata|getValue|P26|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getValue|P26|[[Hillary Rodham Clinton]]}}
</syntaxhighlight>
In [[Bill Clinton]] you should get:
* -
* - [[Hillary Rodham Clinton]]▼
* - [[Hillary Clinton]]
▲* - [[Hillary Rodham Clinton]]
Line 112 ⟶ 125:
* -
* - [[Michelle Obama]]
* - [[Hillary Rodham Clinton]]
In [[Richard Burton]] you should get:
* -
* - [[Elizabeth Taylor]], [[Sally Burton]], [[Sybil Christopher]], [[Suzy Miller]], [[Elizabeth Taylor]]
* - [[Hillary Rodham Clinton]]
Line 124 ⟶ 137:
* -
* -
* - [[Hillary Rodham Clinton]]
=== Testing birthplace ===
Copy and paste the following into any article and preview it (please don't save!):
<syntaxhighlight lang="wikitext">
* - {{#invoke:Wikidata|getValue|P19|}}
* - {{#invoke:Wikidata|getValue|P19|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getValue|P19|[[Newport]]}}
</syntaxhighlight>
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!):
<syntaxhighlight lang="wikitext">
* - {{#invoke:Wikidata|getValue|P19|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getValue|P26|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getValue|P27|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getValue|P140|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getRawValue|P21|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|dmy}}
* - {{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|mdy}}
* - {{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|y}}
</syntaxhighlight>
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!):
<syntaxhighlight lang="wikitext">
* - {{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|y}}
* - {{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|y|BCE}}
</syntaxhighlight>
This should return 65 BC and 65 BCE, respectively.
==See also==
* [[:Module:WikidataIB]], for handling Wikidata in infoboxes
<includeonly>{{#ifeq:{{SUBPAGENAME}}|sandbox||
[[Category:Wikidata modules]]
[[Category:Modules using data from Wikidata]]
}}</includeonly>
|