Module:Wikidata/doc: Difference between revisions

Content deleted Content added
No longer maintained and obsoleted, per talk page
consistency
 
(13 intermediate revisions by 9 users not shown)
Line 1:
{{Ombox|image=[[ImageFile:Stop hand nuvola.svg|40px]]|type=delete|text=[[Module:Wikidata]] is [[deprecation|deprecated]]. Please use [[Module:WikidataIB]] or [[Module:Wd]] instead.}}
{{module rating|protected}}
{{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>getValue</code>: Returns wiki-linked values, if applicable. All other values will be output similar to <code><nowiki>{{#property:}}</nowiki></code>, except that if values with preferred rank exist, then only they are returned. Unlike <code>formatStatements</code> from [[:w:ru:Модуль:Wikidata]], <code>getValue</code> does not yet pick up any references (see [[:w:en:Module talk:Wikidata/Archive 1#Why the references from Wikidata get dropped?]]).
* <code>getRawValue</code>: Returns non-linked property values and numbers with the thousand separator. It also returns the plain numeric value of a property which is a quantity. All other values will be output similar to <code><nowiki>{{#property:}}</nowiki></code>, including normal values, even if preferred values exist.
* <code>getDateValue</code>: Special method to return formatted dates. The default date format is [day month year]; an optional third parameter can be added for other date formats: for [month day, year], add "mdy"; for [month year], add "my"; for year only, add "y". A further optional parameter, which must be fourth, such as "BCE", may be added to override the default "BC" that is suffixed for dates BC.
Line 36 ⟶ 37:
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|Q151973{{Get QID|Richard Burton (actor) }}|P26|FETCH_WIKIDATA}}</nowiki></code>
will fetch a list of the linked values for 'spouse' (P26) from 'redirect page title [[Richard Burton' (Q151973actor) ]] (corresponding to Wikidata label {{Q|{{Get QID|Richard Burton (actor) }}}}) 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.
Line 57 ⟶ 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>)
Line 109 ⟶ 110:
=== Testing spouse ===
Copy and paste the following into any article and preview it (please don't save!):
<sourcesyntaxhighlight lang="moinwikitext">
* - {{#invoke:Wikidata|getValue|P26|}}
* - {{#invoke:Wikidata|getValue|P26|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getValue|P26|[[Hillary Rodham Clinton]]}}
</syntaxhighlight>
</source>
 
In [[Bill Clinton]] you should get:
Line 140 ⟶ 141:
=== Testing birthplace ===
Copy and paste the following into any article and preview it (please don't save!):
<sourcesyntaxhighlight lang="moinwikitext">
* - {{#invoke:Wikidata|getValue|P19|}}
* - {{#invoke:Wikidata|getValue|P19|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getValue|P19|[[Newport]]}}
</syntaxhighlight>
</source>
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">
<pre>
* - {{#invoke:Wikidata|getValue|P19|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getValue|P26|FETCH_WIKIDATA}}
Line 158 ⟶ 159:
* - {{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|mdy}}
* - {{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|y}}
</syntaxhighlight>
</pre>
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">
<pre>
* - {{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|y}}
* - {{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|y|BCE}}
</syntaxhighlight>
</pre>
This should return 65 BC and 65 BCE, respectively.