पटलम्:WikidataIB/doc

विकिपीडिया, कश्चन स्वतन्त्रः विश्वकोशः

यह पटलम्:WikidataIB हेतु प्रलेख पृष्ठ है

This module is designed specifically to implement a mechanism which moves control of whether Wikidata values are used in an infobox from the template coder at the infobox design level to the editor at the article level. It should only be used inside an infobox.

One of the sandboxes at Module:WikidataIB/sandbox, Module:WikidataIB/sandbox1 or Module:WikidataIB/sandbox2 should be used for testing anything other than trivial amendments.

Test cases for the main module can be found at Module talk:WikidataIB/testing.

Test cases for the sandboxes are at Module talk:WikidataIB/sandbox/testing and Module talk:WikidataIB/sandbox1/testing.

Overview[सम्पादयतु]

The module provides these calls specifically for use in infoboxes at present:

  1. getValue
    getSourcedValue - obsoleted; use getValue instead.
  2. getPreferredValue
  3. getNormalValue
  4. getCoords
  5. getQualifierValue

The obsolete call getSourcedValue is now removed as it is redundant to getValue which can do the same job using the |onlysourced=true parameter.

There are also these utility calls:

  1. getLink
  2. getLabel
  3. getAT
  4. formatDate
  5. checkBlacklist
  6. emptyor

Generalised calls:

{{#invoke:WikidataIB |getValue |<PropertyID> |name=<fieldname> |suppressfields=<list of fields which will never display> |fetchwikidata=<list of fields to fetch values from Wikidata> |onlysourced=<yes/no> |noicon=<yes/no> |df=<dmy/mdy/y> |bc=<BC/BCE> |<local parameter>}}
{{#invoke:WikidataIB |getPreferredValue |<PropertyID> |name=<fieldname> |suppressfields=<list of fields which will never display> |fetchwikidata=<list of fields to fetch values from Wikidata> |onlysourced=<yes/no> |noicon=<yes/no> |df=<dmy/mdy/y> |bc=<BC/BCE> |<local parameter>}}
{{#invoke:WikidataIB |getSourcedValue |<PropertyID> |name=<fieldname> |suppressfields=<list of fields which will never display> |fetchwikidata=<list of fields to fetch values from Wikidata> |<local parameter>}}
{{#invoke:WikidataIB |getCoords |name=<fieldname> |suppressfields=<list of fields which will never display> |fetchwikidata=<list of fields to fetch values from Wikidata> |<local parameter>}}
{{#invoke:WikidataIB |getQualifierValue |<PropertyID> |pval=<ID of target value for the property> |qual=<qualifier ID for that target value> |name=<fieldname> |suppressfields=<list of fields which will never display> |fetchwikidata=<list of fields to fetch values from Wikidata> |onlysourced=<yes/no>}}

Function details[सम्पादयतु]

Function getValue[सम्पादयतु]

  • getValue can also take a named parameter |qid= which is the Wikidata ID for the article. This will not normally be used but is available for testing, although it makes the call expensive.
  • The property to be returned is passed in the first unnamed property.
  • The name of the field that this function is called from is passed in the named parameter |name=, which is first checked against a blacklist of fields that are never to be displayed, (i.e. the call must return nil in all circumstances). If the field is not on the blacklist, it is then checked against a whitelist. If the name of the field matches, the call will return any locally supplied value if it is supplied as the second unnamed parameter, or the Wikidata value otherwise.
  • The name is compulsory when the blacklist or whitelist is used, so the module returns nil if it is not supplied.
  • The blacklist is passed in the named parameter |suppressfields=
  • The whitelist is passed in the named parameter |fetchwikidata=

The getValue function will accept a boolean parameter onlysourced which will suppress return of Wikidata values that are unsourced or only sourced to Wikipedia. The absence of the parameter, an empty parameter (|onlysourced=) and the empty string ("") all default to true (i.e. only referenced values are returned). The values no, false and 0 are treated as false (i.e. all values are returned); any other value is true (although |onlysourced=yes is recommended for readability).

The getValue function will accept a boolean parameter noicon which will suppress the trailing "edit at Wikidata" icon for when the returned value is to be further processed by the infobox (e.g. a url). The absence of the parameter or an empty parameter (|noicon=) default to false (i.e. the icon is added). The empty string ("") and the values no, false and 0 are treated as false; any other value is true (although |noicon=true is recommended for readability).

In order to handle the requirement for dates in mdy, dmy or just year formats, getValue accepts a named parameter |df= that may take the values "dmy", "mdy", or "y" - default is "dmy".

As an article may require either of suffixes BC and BCE, getValue accepts a named parameter |bc= that may take the values "BC", or "BCE" - default is "BCE". Some test cases are shown at Module talk:WikidataIB/testing #Calls to getValue for dates.

Specific value-type handlers[सम्पादयतु]

The module has specific handlers for the following data types:

  1. Items that correspond to an article in some Wikipedia, called "wikibase-items". These will be linked to the corresponding (and disambiguated) article on English Wikipedia where possible.
  2. Items that represent dates.
  3. Items that represent Commons media, urls, external ids, or other sorts of plain text.

Items that represent other types of data are returned using the mwdiawiki library call formatPropertyValues().

The third class of data types may be used with the parameters:

  • |prefix=, |postfix=, |linkprefix=, |linkpostfix=

If you don't supply |linkprefix=, then just |prefix= and |postfix= are used. For example, when getting the Minor Planet Center observatory code (P717) in Vienna Observatory (Q532127):

  • {{#invoke:WikidataIB/sandbox|getValue|P717|fetchwikidata=ALL|onlysourced=no |prefix="before " |postfix=" after" |qid=Q532127}} → before 045 after Edit this on Wikidata

Use double-quotes to enclose the parameter value if it has leading or trailing spaces (otherwise they are stripped out). If you supply |linkprefix=, then all four parameters are used and a link is made for each value like this:

  • [[ linkprefix WikidataValue1 linkpostfix | prefix WikidataValue1 postfix]], [[ linkprefix WikidataValue2 linkpostfix | prefix WikidataValue2 postfix]], etc.

That allows multiple links to be made to different sections of a list article, such as List of observatory codes. For example, when getting the Minor Planet Center observatory code (P717) in Vienna Observatory (Q532127) we can make the links:

  • {{#invoke:WikidataIB/sandbox|getValue|P717|fetchwikidata=ALL|onlysourced=no |prefix= |postfix= |linkprefix="List of observatory codes#" |linkpostfix= |qid=Q532127}}045 Edit this on Wikidata

Formatting multiple returned values[सम्पादयतु]

  • |sorted=<yes|no> is a boolean passed to enable sorting of the values returned. No parameter, or an empty string, or "false", or "no", or "0" disables sorting. It's only a very dumb alphabetical sort and sorts linked values as "[[ ..."
  • |sep=<separator characters> allows the separator between multiple returned values to be defined. The default is ", " (comma plus normal space). If the separator has leading or trailing spaces, enclose it in double quotes (e.g. |sep=" - "). Any double quotes are stripped from the separator. The pipe character (|) must be escaped as {{!}}. For reasons of accessibility (see MOS:PLIST), do not use |sep=<br> for vertical unbulleted lists; use |list=ubl instead.
  • |list=<hlist|ubl> allows multiple returned values to be displayed as a horizontal list (|list=hlist), or a vertical unbulleted list (|list=ubl). These override the separator and do not display the 'pen icon' linked to "Edit at Wikidata"

Function getPreferredValue[सम्पादयतु]

The getPreferredValue function works exactly like getValue, taking the same parameters, but if any values for a property have the preferred rank set, it will only return those values.

Function getNormalValue[सम्पादयतु]

The getNormalValue function complements getPreferredValue, taking the same parameters, but if any values for a property have the normal rank set, it will only return those values.

If a property has a mixture of preferred and normal ranks set, these functions will separate them.

Comparison example[सम्पादयतु]

Fetching the name(s) of the रचियता (P170) from Corisca and the Satyr (Q29016906):

  • {{#invoke:WikidataIB |getValue |P170 |fetchwikidata=ALL |qid=Q29016906 |onlysourced=no}} → आर्टेमिसिया जेंटिल्स्की, Aniella di Beltrano, Massimo Stanzione Edit this on Wikidata
  • {{#invoke:WikidataIB |getPreferredValue |P170 |fetchwikidata=ALL |qid=Q29016906 |onlysourced=no}} → आर्टेमिसिया जेंटिल्स्की Edit this on Wikidata
  • {{#invoke:WikidataIB |getNormalValue |P170 |fetchwikidata=ALL |qid=Q29016906 |onlysourced=no}}स्क्रिप्ट त्रुटि: "getNormalValue" फंक्शन मौजूद नहीं है।

Function getCoords[सम्पादयतु]

  • getCoords can also take a named parameter |qid= which is the Wikidata ID for the article. This will not normally be used but is available for testing, although it makes the call expensive.
  • The coordinates from Wikidata are parsed and passed to Template:Coord which returns the display as if it were called manually.
  • The name of the field that this function is called from is passed in the named parameter |name=, which is first checked against a blacklist of fields that are never to be displayed, (i.e. the call must return nil in all circumstances). If the field is not on the blacklist, it is then checked against a whitelist. If the name of the field matches, the call will return any locally supplied value if it is supplied as the unnamed parameter, or the Wikidata value otherwise.
  • The name is compulsory when the blacklist or whitelist is used, so the module returns nil if it is not supplied.
  • The blacklist is passed in the named parameter |suppressfields=
  • The whitelist is passed in the named parameter |fetchwikidata=

Function getQualifierValue[सम्पादयतु]

The getQualifierValue is for use when we want to fetch the value of a qualifier. We need to know the property and the value of the property that it qualifies. The parameters are:

  • The property ID passed in the unnamed parameter (or |1=)
  • The target value for that property in |pval=
  • The qualifier ID for that target value in |qual=
  • The name of the field where its called from to implement whitelisting and blacklisting of the property in
  • The list of fields to be fetched ("whitelist") in |fetchwikidata= - accepts |fetchwikidata=ALL to fetch all fields
  • Optional list of fields not to be displayed ("blacklist") in |suppressfields=
  • Optional boolean to specify whether only sourced values of the property are returned (defaults to "no") in |onlysourced=
  • Optional item ID for arbitrary access (expensive call!) in |qid=

Example of getQualifierValue[सम्पादयतु]

In South Pole Telescope (Q1513315) there is a property महत्वपूर्ण घटना (P793), which has a value निर्माण (Q385378). That has two qualifiers, आरंभ समय (P580) and समाप्ति तिथि (P582). To get the start date:

  • {{#invoke:WikidataIB |getQualifierValue |P793 |pval=Q385378 |qual=P580 |name=xyz |fetchwikidata=ALL }}

In South Pole Telescope it returns:

  • नवेम्बर् २००६ Edit this on Wikidata

Function getLink[सम्पादयतु]

getLink returns the label for a Qid wiki-linked to the local article (if the article exists). If label doesn't exist, it returns the Qid wiki-linked to the local article (if the article exists).

Wikidata: Corisca and the Satyr (Q29016906) and पुरातत्त्ववेत्ता (Q3621491)
  • {{#invoke:WikidataIB |getLink |Q29016906}} → Corisca and the Satyr
  • {{#invoke:WikidataIB |getLink |Q3621491}} → पुरातत्त्ववेत्ता

Function getLabel[सम्पादयतु]

getLabel returns the label for a Qid. If label doesn't exist, it returns the Qid. Note that this is the label given to the Wikidata entry in the same language as the current Wikipedia, if the label exists.

Wikidata: Corisca and the Satyr (Q29016906) and पुरातत्त्ववेत्ता (Q3621491)
  • {{#invoke:WikidataIB |getLabel |Q29016906}} → Corisca and the Satyr
  • {{#invoke:WikidataIB |getLabel |Q3621491}} → पुरातत्त्ववेत्ता

Function getAT[सम्पादयतु]

getAT returns the article title for a Qid. If the article title doesn't exist, it returns nothing. Note that this is the title of the article in the current Wikipedia, if the interlanguage link exists in the Wikidata entry.

Wikidata: Corisca and the Satyr (Q29016906) and पुरातत्त्ववेत्ता (Q3621491)
  • {{#invoke:WikidataIB |getAT |Q29016906}}
  • {{#invoke:WikidataIB |getAT |Q3621491}}

Function formatDate[सम्पादयतु]

formatDate accepts a datetime of the usual format from mw.wikibase.entity:formatPropertyValues, like "1 August 30 BCE" as parameter 1 and formats it according to the df (date format) and bc parameters.

  • {{#invoke:WikidataIB |formatDate | 1 August 30 BCE |bc=BCE |df=dmy}} → 1 August 30 BCE
  • {{#invoke:WikidataIB |formatDate | 1 August 30 BCE |bc=BC |df=mdy}} → August 1, 30 BC
  • df = "dmy" / "mdy" / "y" - default is "dmy"
  • bc = "BC" / "BCE" - default is "BCE"

Coding into an infobox[सम्पादयतु]

Typically, the getValue call will be invoked in an infobox definition, using appropriate template parameters. One simple implementation is given as an example in Template:Infobox book/Wikidata/Sandbox. As an illustration, the 'author' field in the infobox is coded like this:

| label2  = Author{{#if:{{{authors|}}}|s}}
|  data2  = {{#invoke:WikidataIB |getValue |P50 |name=author |fetchwikidata={{{fetchwikidata|}}} |suppressfields={{{suppressfields|}}} |{{{authors|{{{author|}}}}}} }}

The property to be fetched is the first unnamed parameter. In this case it is लेखक (P50).

The name of the field is passed in |name= and that name is checked against the blacklist and the whitelist. To always suppress the author field in a particular article, an editor will set |suppressfields=author in the infobox. The author field will then never be displayed.

If the field is not blacklisted, then the infobox can be set to display a locally supplied value for author simply by setting |author=George Orwell, for example, in the infobox. It also accepts |authors=. If the name of the field is on the whitelist, e.g. |fetchwikidata=author; genre; pub_date; pages; dewey; congress, and the local value is not supplied, then the infobox will display the value retrieved from Wikidata. Any separators can be used, except | and {}.

As a shorthand, |fetchwikidata=ALL will fetch all of the fields that are not blacklisted, as long as no local value is already provided in the article for a given field.

Since Wikidata labels are normally lower case, the sentence case function from Module:String2 can be used to capitalise the first letter of the returned text, e.g.

  • {{#invoke:String2 | sentence | {{#invoke:WikidataIB |getValue |P136 |name=genre |fetchwikidata=ALL |onlysourced=false}} }} in एनिमल फार्म (Q1396889) produces:
  • Roman à clef, satirical fiction, नीतिकथा, dystopian fiction edit this on wikidata

Example of calls in an infobox[सम्पादयतु]

Basic use of getValue:

  • {{#invoke:WikidataIB |getValue |P000 |name=fieldname |qid={{{qid|}}} |fetchwikidata={{{fetchwikidata|}}} |onlysourced={{{onlysourced|}}} |{{{localparameter|}}} }}

Full collection of parameters:

  • {{#invoke:WikidataIB |getValue |P000 |name=fieldname |qid={{{qid|}}} |suppressfields={{{suppressfields|}}} |fetchwikidata={{{fetchwikidata|}}} |onlysourced={{{onlysourced|}}} |noicon={{{noicon|}}} |wdl={{{wikidatalink|}}} |df={{dateformat|}} |bc={{{bc|}}} |prefix= |postfix= |linkprefix= |linkpostfix= |sorted={{{sorted|}}} |sep={{{separator|}}} |list={{listtype|}}} |{{{localparameter|}}} }}

Any of the parameters can, of course, be be fixed for a given field in an infobox, rather than taking the parameter supplied to the infobox, which will affect all fields. For example, one field may set |list=hlist where a series of short words is expected; whereas another field could use |list=ubl where an unbulleted vertical list of several words on each line is required.

Coodinates[सम्पादयतु]

The getCoords call will display the output of Template:Coord when supplied with the coordinates returned from Wikidata. It can be coded like this:

|label20 = Coordinates
| data20 = {{#invoke:WikidataIB |getCoords |name=coordinates |suppressfields={{{suppressfields|}}} |fetchwikidata={{{fetchwikidata|}}} |{{{coordinates|}}} }}

An example is Template:Infobox biosphere reserve

{{Infobox biosphere reserve
| fetchwikidata = ALL
}}

Displays coordinates in the usual positions when used in an article where Wikidata has coordinates.

Upgrading existing infoboxes[सम्पादयतु]

Since the parameter |fetchwikidata= is needed for any Wikidata functionality, an existing infobox may be replaced by an infobox incorporating these calls without any change whatsoever to any article. Each article using the new infobox can later be enabled by supplying |fetchwikidata=ALL, or a list of required fields for that article. At that point, the onus is on the editor enabling the functionality to check that no unwanted fields are now being displayed. If so, they can be added to a blacklist for the article by setting |suppressfields= to the list of unwanted fields.

Verifiability[सम्पादयतु]

Where it will always be essential for a particular field to only contain values that are referenced, use getValue, making sure that |onlysourced= is not set to 'false', '0' or 'no'. By default it will exclude values that are unsourced or only sourced to a Wikipedia, thus making the job of checking easier at the article level. If unsourced data is acceptable (!), set |onlysourced=no. As it is beyond my wit to produce an automated mechanism that knows whether an existing source is reliable or not in a given context, that job must still be performed at the article level by an editor familiar with the subject. It should always be done when first enabling Wikidata for that article.

Example of use: Infobox book[सम्पादयतु]

This section is taken from Template:Infobox book/Wikidata/Sandbox/doc.

No Wikidata[सम्पादयतु]

{{Infobox book/Wikidata/Sandbox
| suppressfields =
| fetchwikidata  =
| name           = Animal Farm
| title_orig     = Animal Farm: A Fairy Story
| image          = Animal Farm - 1st edition.jpg
| image_size     = 200px
| caption        = First edition cover
| author         = [[George Orwell]]
| country        = United Kingdom
| language       = English
| genre          = Political satire
}}

Works as a non-aware infobox: only locally supplied parameters are displayed.

{{Infobox book/Wikidata/Sandbox
| name           = Animal Farm
| title_orig     = Animal Farm: A Fairy Story
| image          = Animal Farm - 1st edition.jpg
| image_size     = 200px
| caption        = First edition cover
| author         = [[George Orwell]]
| country        = United Kingdom
| language       = English
| genre          = Political satire
}}

The blacklist and whitelist can be omitted if unused

All Wikidata[सम्पादयतु]

{{Infobox book/Wikidata/Sandbox
| fetchwikidata  = author; genre; pub_date; pages; dewey; congress
}}

Fetches the author, publication date, number of pages, Dewey index, and Library of Congress catalogue number values from Wikidata.

{{Infobox book/Wikidata/Sandbox
| fetchwikidata  = ALL
}}

As shorthand, the |fetchwikidata= parameter can be set to ALL to fetch all available fields. Any field can be suppressed by naming it in |suppressfields=, or overridden by supplying a local value.

Never display genre[सम्पादयतु]

{{Infobox book/Wikidata/Sandbox
| suppressfields = genre
| fetchwikidata  = author; genre; pub_date; pages; dewey; congress
}}

The genre field will always be suppressed, even if a local value is supplied.

{{Infobox book/Wikidata/Sandbox
| suppressfields = genre
| fetchwikidata  = author; genre; pub_date; pages; dewey; congress
| genre          = Political satire
}}

Local override[सम्पादयतु]

{{Infobox book/Wikidata/Sandbox
| fetchwikidata  = author; genre; pub_date; pages; dewey; congress
| genre          = Political satire
}}

The genre field is set to display "Political satire", no matter what is stored in Wikidata.

{{Infobox book/Wikidata/Sandbox
| fetchwikidata  = ALL
| genre          = Novel
}}

The genre field is set to display "Novel", no matter what is stored in Wikidata.

Don't fetch genre[सम्पादयतु]

{{Infobox book/Wikidata/Sandbox
| suppressfields = 
| fetchwikidata  = author; pub_date; pages; dewey; congress
}}

The genre field will not be fetched from Wikidata. Only the author, publication date, number of pages, Dewey index, and Library of Congress catalogue number are imported. A local value for genre will display.

See also[सम्पादयतु]


"https://sa.wikipedia.org/w/index.php?title=पटलम्:WikidataIB/doc&oldid=435178" इत्यस्माद् प्रतिप्राप्तम्