વિભાગ:WikidataIB/doc

વિકિપીડિયામાંથી
Jump to navigation Jump to search

This is the documentation page for વિભાગ: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.

Usage[ફેરફાર કરો]

The module provides four calls specifically for use in infoboxes at present: getValue, getSourcedValue, getCoords and getQualifierValue, although getSourcedValue is now redundant to getValue which can do the same job using a parameter.

There are also three utility calls: getLink, getLabel and formatDate.

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 |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 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 #Calls to getValue for dates.

Function getSourcedValue[ફેરફાર કરો]

  • getSourcedValue works exactly as getValue does, but only returns values that have a reference to something other than a Wikipedia. That's not a guarantee of a reliable source, but it helps separate the wheat from the chaff.

Example of getSourcedValue[ફેરફાર કરો]

From Richard Burton (Q151973):

Burton currently has four values for વ્યવસાય (P106) on Wikidata:

Using getValue in Richard Burton:

  • {{#invoke:WikidataIB |getValue |P106 |name=occupation |fetchwikidata=ALL}} -> ફિલ્મ અભિનેતા, diarist, નાટ્યકલાકાર, અભિનેતા Edit this on Wikidata

Using getSourcedValue in Richard Burton:

  • {{#invoke:WikidataIB |getSourcedValue |P106 |name=occupation |fetchwikidata=ALL}} -> Script error: The function "getSourcedValue" does not exist.

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 construction (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).

Function getLabel[ફેરફાર કરો]

getLabel returns the label for a Qid. If label doesn't exist, it returns the Qid.

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
  • 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}} }} in Animal Farm (Q1396889) produces:

Coodinates[ફેરફાર કરો]

The getCoords call will display the output of Template:Coord when supplied with the coordinates returned from Wikidata.There's an example in Template:Sandbox/Infobox biosphere reserve where it's coded like this:

|label20 = Coordinates
| data20 = {{#invoke:WikidataIB |getCoords |name=coordinates |suppressfields={{{suppressfields|}}} |fetchwikidata={{{fetchwikidata|}}} |{{{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 getSourcedValue instead of getValue. It will exclude values that are unsourced or only sourced to a Wikipedia, thus making the job of checking easier at the article level. As it is beyond my wit to produce an automated mechanism that knows whether a 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.

Examples[ફેરફાર કરો]

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
| suppressfields = 
| fetchwikidata  = author; genre; pub_date; pages; dewey; congress
}}

Fetches all of its values from Wikidata.

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

As shorthand, the |fetchwikidata= can be set to ALL to fetch all available fields. Any of them can be suppressed by |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.

Coordinates[ફેરફાર કરો]

{{Sandbox/Infobox biosphere reserve
| fetchwikidata = ALL
}}

Displays coordinates when used in an article where Wikidata has coordinates.

See also[ફેરફાર કરો]