Difference between revisions of "Module:Wikidata/doc"

From blackwiki
Jump to navigation Jump to search
blackwiki>RexxS
(→‎Usage: update to agree with logic used)
blackwiki>RexxS
(update documentation to include getBirthPlace)
Line 1: Line 1:
 
This module is a cosmetic modification of the original at [[Module:Sandbox/Tom Morris]] which was created 19 May 2013.
 
This module is a cosmetic modification of the original at [[Module:Sandbox/Tom Morris]] which was created 19 May 2013.
  
The module "{{BASEPAGENAME}}" contains one available call (getSpouse) that allows the calling script to retrieve the value for spouse (property P26) from Wikidata.
+
The module "{{BASEPAGENAME}}" contains:
 +
* a call (getSpouse) that allows the calling script to retrieve the value for spouse (property P26) from Wikidata.
 +
* a call (getBirthPlace) that allows the calling script to retrieve the value for birth_place (property P19) from Wikidata.
  
If the spouse property is not defined in Wikidata for the article that invokes this code, then an empty string ("") is returned.
+
If the property is not defined in Wikidata for the article that invokes this code, then an empty string ("") is returned.
  
 
== Usage ==
 
== Usage ==
 +
=== Spouse ===
 
* <code><nowiki>{{#invoke:Sandbox/RexxS|getSpouse|}}</nowiki></code> = returns nothing, so suppresses the display of spouse in an infobox
 
* <code><nowiki>{{#invoke:Sandbox/RexxS|getSpouse|}}</nowiki></code> = returns nothing, so suppresses the display of spouse in an infobox
 
* <code><nowiki>{{#invoke:Sandbox/RexxS|getSpouse|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 Rodham Clinton]])
 
* <code><nowiki>{{#invoke:Sandbox/RexxS|getSpouse|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 Rodham Clinton]])
Line 16: Line 19:
 
# display the linked value(s) from Wikidata if the infobox parameter <code>|spouse</code> is not supplied
 
# 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 Clinton"</code>)
 
# display the local infobox parameter <code>|spouse</code> if it is supplied (e.g. <code>"|spouse = Hillary Clinton"</code>)
 +
 +
=== Birth place ===
 +
This works in just the same way as the calls above:
 +
* <code><nowiki>{{#invoke:Sandbox/RexxS|getBirthPlace|}}</nowiki></code> = returns nothing, so suppresses the display of spouse in an infobox
 +
* <code><nowiki>{{#invoke:Sandbox/RexxS|getBirthPlace|FETCH_WIKIDATA}}</nowiki></code> = returns the linked value(s) of property P19 (place of birth) stored in wikidata for the corresponding article (e.g. for article [[Bill Clinton]], it returns [[Hope, Arkansas]])
 +
* <code><nowiki>{{#invoke:Sandbox/RexxS|getBirthPlace|[[Hope, Arkansas|Hope]]}}</nowiki></code> = returns [[Hope, Arkansas|Hope]], allowing an infobox to use a local value rather than the value stored in Wikidata.
  
 
== Parameters ==
 
== Parameters ==
Line 21: Line 30:
  
 
== Examples ==
 
== Examples ==
Testing: Copy and paste the following into any article and preview it (please don't save!):
+
=== Testing getSpouse ===
 +
Copy and paste the following into any article and preview it (please don't save!):
 
<pre>
 
<pre>
 
* - {{#invoke:Sandbox/RexxS|getSpouse|}}
 
* - {{#invoke:Sandbox/RexxS|getSpouse|}}
Line 50: Line 60:
 
* -
 
* -
 
* - [[Hillary Clinton]]
 
* - [[Hillary Clinton]]
 +
 +
 +
=== Testing getBirthplace ===
 +
Copy and paste the following into any article and preview it (please don't save!):
 +
<pre>
 +
* - {{#invoke:Sandbox/RexxS|getBirthPlace|}}
 +
* - {{#invoke:Sandbox/RexxS|getBirthPlace|FETCH_WIKIDATA}}
 +
* - {{#invoke:Sandbox/RexxS|getBirthPlace|[[Newport]]}}
 +
</pre>

Revision as of 20:47, 25 August 2013

This module is a cosmetic modification of the original at Module:Sandbox/Tom Morris which was created 19 May 2013.

The module "Wikidata" contains:

  • a call (getSpouse) that allows the calling script to retrieve the value for spouse (property P26) from Wikidata.
  • a call (getBirthPlace) that allows the calling script to retrieve the value for birth_place (property P19) from Wikidata.

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

Usage

Spouse

  • {{#invoke:Sandbox/RexxS|getSpouse|}} = returns nothing, so suppresses the display of spouse in an infobox
  • {{#invoke:Sandbox/RexxS|getSpouse|FETCH_WIKIDATA}} = 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 Rodham Clinton)
  • {{#invoke:Sandbox/RexxS|getSpouse|[[Hillary Clinton]]}} = returns Hillary Clinton, allowing an infobox to use a local value rather than the value stored in Wikidata.

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

  • | data55 = {{#invoke:Sandbox/RexxS|getSpouse|{{{spouse|FETCH_WIKIDATA}}} }}

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 Clinton")

Birth place

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

  • {{#invoke:Sandbox/RexxS|getBirthPlace|}} = returns nothing, so suppresses the display of spouse in an infobox
  • {{#invoke:Sandbox/RexxS|getBirthPlace|FETCH_WIKIDATA}} = returns the linked value(s) of property P19 (place of birth) stored in wikidata for the corresponding article (e.g. for article Bill Clinton, it returns Hope, Arkansas)
  • {{#invoke:Sandbox/RexxS|getBirthPlace|[[Hope, Arkansas|Hope]]}} = returns Hope, allowing an infobox to use a local value rather than the value stored in Wikidata.

Parameters

  • A single, unnamed parameter is supplied. This may be null, "FETCH_WIKIDATA", or any other string (within the module it is assigned to the local variable spouse_input)

Examples

Testing getSpouse

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

* - {{#invoke:Sandbox/RexxS|getSpouse|}}
* - {{#invoke:Sandbox/RexxS|getSpouse|FETCH_WIKIDATA}}
* - {{#invoke:Sandbox/RexxS|getSpouse|[[Hillary Clinton]]}}

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 getBirthplace

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

* - {{#invoke:Sandbox/RexxS|getBirthPlace|}}
* - {{#invoke:Sandbox/RexxS|getBirthPlace|FETCH_WIKIDATA}}
* - {{#invoke:Sandbox/RexxS|getBirthPlace|[[Newport]]}}