Jump to content

Module:Wikidata/doc

विकिपीडिया से
RexxS (बातचीत | योगदान) (update testing instructions) के द्वारा 17:29, 26 अगस्त 2013 के बदलाव

This module is a 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 wiki-linked value(s) for spouse (property p26) from Wikidata.
  • a call (getBirthPlace) that allows the calling script to retrieve the wiki-linked value(s) for birth_place (property p19) from Wikidata.
  • a call (getValue) that allows the calling script to retrieve the wiki-linked value(s) for any property from Wikidata by supplying the property ID as the first parameter.

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.

Generalised

  • - {{#invoke:Sandbox/RexxS|getValue|p26|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|getValue|p19|FETCH_WIKIDATA}} = returns the linked value(s) of property p19 (spouse) stored in wikidata for the corresponding article (e.g. for article Bill Clinton, it returns Hope, Arkansas)

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

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

which causes the infobox to:

  1. not display spouse if the infobox parameter |spouse is set to be blank (i.e. "| 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]]" will display Hillary Clinton)

Parameters

  • For the pre-defined cases (getSpouse and getBirthPlace), 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)
  • For the generalised case (getvalue), two unnamed parameters are supplied. The first is the ID of the property that is to be retrieved (e.g. p19 for birthplace or p26 for spouse). The second 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]]}}

Testing getValue and non-linked values

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

* - {{#invoke:Sandbox/RexxS|getValue|p19|FETCH_WIKIDATA}}
* - {{#invoke:Sandbox/RexxS|getValue|p26|FETCH_WIKIDATA}}
* - {{#invoke:Sandbox/RexxS|getValue|p27|FETCH_WIKIDATA}}
* - {{#invoke:Sandbox/RexxS|getValue|p140|FETCH_WIKIDATA}}
* - {{#invoke:Sandbox/RexxS|getRawValue|p21|FETCH_WIKIDATA}}
* - {{#invoke:Sandbox/RexxS|getDateValue|p569|FETCH_WIKIDATA}}

This should return the Wikidata values for birthplace, spouse, citizenship, religion, gender and date of birth if they exist.