ماڈیول:Wikidata/دستاویز

آزاد دائرۃ المعارف، ویکیپیڈیا سے

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

Methods[ترمیم]

The module "Wikidata" 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:

  • getValue: Returns wiki-linked values, if applicable. All other values with be output like {{#property:}}, regardless of their rank.
  • getRawValue: Returns non-linked property values and numbers with the thousand separator. All other values with be output like {{#property:}}.
  • getDateValue: 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".

Wikidata qualifier values (if present) can be retrieved by the following methods:

  • getQualifierValue: returns only wiki-linked values, if applicable.
  • getRawQualifierValue: returns non-linked values
  • getQualifierDateValue: returns formatted dates

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

Other methods:

  • pageId: returns the Wikidata id (Q…) of the current page or nothing if the page is not connected to Wikidata

Parameters[ترمیم]

  • For the generalized 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, which becomes the returned value.
  • 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.

استعمال[ترمیم]

مثال:spouse[ترمیم]

  • {{#invoke:Wikidata|getValue|P26|}} = returns nothing, so suppresses the display of spouse in an infobox
  • {{#invoke:Wikidata|getValue|P26|FETCH_WIKIDATA}} = returns the linked value(s) of property P26 (spouse) stored in wikidata for the corresponding article (e.g. for article بل کلنٹن, it returns Hillary Rodham Clinton)
  • {{#invoke:Wikidata|getValue|P26|[[ہیلری کلنٹن]]}} = returns ہیلری کلنٹن, 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:Wikidata|getValue|P26|{{{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")

Optionally, it could be called as:

  • | data55 = {{#invoke:Wikidata|getValue|P26|{{{spouse|}}} }}

which should behave as the parameter does now, unless the parameter is set to FETCH_WIKIDATA when it displays the linked value(s) fetched from Wikidata.

مثال:مقام پیدائش[ترمیم]

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

  • {{#invoke:Wikidata|getValue|P19|}} = returns nothing, so suppresses the display of birth place in an infobox
  • {{#invoke:Wikidata|getValue|P19|FETCH_WIKIDATA}} = returns the linked value(s) of property P19 (place of birth) stored in wikidata for the corresponding article (e.g. for article بل کلنٹن, it returns Hope, Arkansas)
  • {{#invoke:Wikidata|getValue|P19|[[Hope, Arkansas|Hope]]}} = returns Hope, allowing an infobox to use a local value rather than the value stored in Wikidata.

مثال:جنس[ترمیم]

We don't want the returned value linked, so use:

  • - {{#invoke:Wikidata|getRawValue|P21|FETCH_WIKIDATA}}

مثال:تاریخ پیدائش[ترمیم]

If we want the date of birth in dmy format, we use:

  • - {{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|dmy}}

If we want the date of birth in mdy format, we use:

  • - {{#invoke:Wikidata|getDateValue|P569|FETCH_WIKIDATA|mdy}}

مثال: ویکی ڈیٹا ایٹم سے ربط کرنا[ترمیم]

Use the following code to just retrieve the Q-ID:

  • - {{#invoke:Wikidata|pageId}}

Linking to Wikidata used the usual Wiki markup:

  • - [[d:{{#invoke:Wikidata|pageId}}|Name of Link]]

جانچ[ترمیم]

Testing spouse[ترمیم]

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

* - {{#invoke:Wikidata|getValue|P26|}}
* - {{#invoke:Wikidata|getValue|P26|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getValue|P26|[[ہیلری کلنٹن]]}}

In بل کلنٹن you should get:

In بارک اوبامہ you should get:

In Richard Burton you should get:

In فرانز کافکا you should get:

جانچ مقام پیدائش[ترمیم]

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

* - {{#invoke:Wikidata|getValue|P19|}}
* - {{#invoke:Wikidata|getValue|P19|FETCH_WIKIDATA}}
* - {{#invoke:Wikidata|getValue|P19|[[Newport]]}}

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!):

* - {{#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}}

This should return the Wikidata values for birthplace, spouse, citizenship, religion, gender and date of birth (twice) if they exist. The dob is first in dmy format and then in mdy.