Content deleted Content added
→Link to Wikidata: note on hiding the pen icon |
→Complex date dependencies: -deleted |
||
(24 intermediate revisions by 11 users not shown) | |||
Line 1:
{{Module rating |protected}}
{{#ifeq:{{SUBPAGENAME}}|sandbox||{{High-use
{{ombox|text=For a more user-friendly wrapper of this module see {{t|wdib}}.}}
This module is
One of the two sandboxes should be used for testing anything other than trivial amendments.
Line 38 ⟶ 39:
# <code>getAwardCat</code> if the item has values of P166 (award received), then it examines each of those awards for P2517 (category for recipients of this award) and it returns the corresponding category, with the item's P734 (family name) as sort key, or no sort key if there is no family name
# <code>getIntersectCat</code> for each value of the prop1 it fetches the value's main category and then each value of prop2, then it returns all of the categories representing the intersection of those properties
# <code>getSumOfParts</code> scans the property 'has part' (P527) for values matching a list
# <code>getCoords</code>
# <code>getPreferredValue</code> - {{color|red|'''Deprecated'''}} but retained for backward compatibility. Use the <code>|getValue|rank=best</code> parameters instead
The obsolete call getSourcedValue has now been removed as it is redundant to getValue which can do the same job using the {{para|onlysourced|true}} parameter (which is set by default)
===Utilities functions===
# <code>getLink</code> if there is a sitelink to an article on the local Wiki, it returns a link to the article with the Wikidata label as the displayed text. If there is no sitelink, it returns the label as plain text. If there is no label in the local language, it returns the entity-ID
# <code>getAT</code> (Article Title) If there is a sitelink to an article on the local Wiki, it returns the sitelink as plain text, otherwise nothing
Line 49 ⟶ 50:
# <code>getAllLabels</code> fetches the set of labels and formats it for display as wikitext
# <code>labelorid</code> returns the label with all wikitext removed, or the entity-ID if no label
# <code>getDescription</code> returns the article description for the Wikidata entity if the local parameter is "Wikidata"
# <code>getAllDescriptions</code> fetches the set of descriptions and formats it for display as wikitext
# <code>getAliases</code> returns the aliases for the entity in the current or given language
Line 64 ⟶ 65:
# <code>followQid</code> given a list of properties, looks for each property in turn and returns the entity-ID of the first value that matches (optionally, returns all entity-IDs that match)
# <code>getGlobe</code> returns the entity-ID of the globe used in P625 (coordinate ___location), or nil if there isn't one
# <code>getCommonsLink</code> returns one of the following in order of preference: the Commons sitelink of the linked Wikidata item; the Commons sitelink of the topic's main category of the linked Wikidata item
# <code>siteID</code> returns the root of the globalSiteID, e.g. "en" for "enwiki", "enwikisource", "en-gb", etc.
# <code>projID</code> same as siteID
Line 75 ⟶ 76:
# <code>showNoLinks</code> displays the article titles that should not be linked
===Examples of calls
<nowiki>{{#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> |qual=<ALL/DATES/P999> |list=<ubl/hlist/prose> |linked=<yes/no> |<local parameter>}}</nowiki>
Line 85 ⟶ 86:
<nowiki>{{#invoke:WikidataIB |getValueByLang |<PropertyID> |lang=<language code to match> |name=<fieldname> |suppressfields=<list of fields which will never display> |fetchwikidata=<list of fields to fetch values from Wikidata> |onlysourced=<yes/no>}}</nowiki>
== Function getValue ==
Line 149:
| onlysourced
| osd
| A boolean which will filter out Wikidata values that are unsourced or only sourced to Wikipedia. [[Wikipedia:Wikidata/2018_Infobox_RfC#Discussion|This 2018 RFC]] requires that Wikidata values displayed in article infoboxes must be sourced. Values <code>no</code>, <code>false</code> and <code>0</code> are all false; anything else is true.
| true
|-
Line 279:
| noicon
|
| A boolean which will suppress the trailing "edit at Wikidata" pen-icon. Useful for when the returned value is to be further processed. Values <code>no</code>, <code>false</code> and <code>0</code> are all false (i.e. shows the icon); anything else is true (i.e. suppresses the icon).
| false
|-
Line 314:
| parameterset
| ps
| Convenience parameter to allow commonly used sets of parameters to be specified with a single parameter: ps=1 gets a simple linked value wherever possible; ps=2 represents a plain text value. See [[#Parameter sets|Parameter sets]].
|
|-
Line 336:
=== Sourcing ===
The getValue function will accept a boolean parameter <code>onlysourced</code> which will suppress return of Wikidata values that are unsourced or only sourced to
=== Link to Wikidata ===
Line 401:
To simplify the use of <code>getValue</code> in other circumstances, common combinations of parameters can be specified with {{para|parameterset}} or its alias {{para|ps}} for convenience. Two combinations are implemented at present and these are:
;ps=1 : a common set of overrides to get a simple value, linked where possible:
<pre>
* rank = "best"▼
|rank ="best"
</pre>
;ps=2 : a sort of raw value in plain text:
<pre>
▲* rank = "best"
|linked = "no"
</pre>
Other sets could be created if there is a demand.
Line 457 ⟶ 462:
==== Example of getValueByQual ====
In {{Q|Q10990}} there is a property {{Q|P443}} that has multiple values, each of which has a qualifier {{Q|P407}}. We can return the property value whose qualifier has the value {{Q|
* <code><nowiki>{{#invoke:WikidataIB |getValueByQual |qid=Q10990 |P443 |qualID=P407 |qvalue=
=== Function getValueByLang ===
Line 662 ⟶ 667:
; [[Template:If then wikilink]] : tests whether the first unnamed parameter is not an empty string and if it isn't, it returns the parameter formatted as piped wiki-link using an optional namespace prefix.
; [[Template:Formatter link]] : takes an external identifier code as {{para|code}} and uses a formatter url as {{para|url}} to construct a link to the external resource, which uses the code as display.
; [[Template:Emptyor]] : tests a piece of text to ascertain whether it's effectively empty or contains some text. If the unnamed parameter consists only of html tags, punctuation (e.g.
== Example of use: Infobox book ==
Line 755 ⟶ 760:
</pre>
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.
== Exporting the module ==
WikidataIB has been developed to run on any language wiki (or Wikimedia project) with a minimum of modification. An optional sub-module [[Module:WikidataIB/i18n]] may be created to replace the values for error messages, ordinal suffixes etc. as shown in the local i18n definitions in the module. Although the same result can be arrived at by directly editing those values in WikidataIB, using the sub-module will allow an updated version of WikidataIB to directly replace the older module without having to re-edit the i18n definitions.
=== Linked items ===
If the target Wiki has a convention that certain items are not normally linked (see [[:en:Wikipedia:Manual of Style/Linking #What generally should not be linked]] for an example), then a sub-module [[Module:WikidataIB/nolinks]] can be created to list items that should not be linked, using the English Wikipedia sub-module as an exemplar.
=== Italic titles ===
If the target Wiki has a convention that certain works should be italicised or quoted (see [[:en:Wikipedia:Manual of Style/Text formatting #Names and titles]] for an example), then a sub-module [[Module:WikidataIB/titleformats]] can be created to list items that should be italicised or quoted, using the English Wikipedia sub-module as an exemplar.
=== Complex date ===
Most of the output from the module will use the local language (or any user-specified one on multi-lingual wikis) where the sitelink or label exists on Wikidata. However, dates are more complicated and not handled perfectly in all languages. To solve this, WikidataIB uses [[Module:Complex date]] – developed on Commons by {{u|Jarekt}} – which allows expansion to support a wider variety of languages. As a result, it is necessary to install Complex date and its dependencies alongside WikidataIB when installing on another Wikimedia project.
==== Complex date dependencies ====
[[Module:Complex_date]] relies on the following modules:
* [[Module:ISOdate]]
** [[Module:DateI18n]] (no dependencies)
* [[Module:i18n/complex date]]
** [[Module:Ordinal]] (lazy loading)
*** [[Module:I18n/ordinal]] (no dependencies)
*** [[Module:Yesno]] (from en.wikipedia) (no dependencies)
*** [[Module:Formatnum]] (no dependencies)
** [[Module:Roman]] (lazy loading with no dependencies)
Unless otherwise noted, the authoritative version of each module can be found on [https://commons.wikimedia.org/ Commons] although the versions on English Wikipedia are usually kept in sync.
==See also==
|