Module:Wikidades/doc

Ón Vicipéid, an chiclipéid shaor.

This is the documentation page for Module:Wikidades

This is the documentation of Module:Wikidades in English.

This module fetches formatted data from Wikidata. It works in local language and it has options for internationalization.

Wondering what does Wikidades mean? See wikt:en:dada#Catalan.

Functions[athraigh foinse]

Basic function:

  • claim: returns the value (or values) of a statement or a qualifier formatted with parameters or using a default format depending on the data type.

Other functions:

Other utility functions: getSiteLink, lang, numStatements, validProperty, formatNum.

Function claim[athraigh foinse]

Returns the value (or values) of a statement or a qualifier formatted with parameters or using a default format depending on the data type. By default, it refers to the Wikidata item (Qid) associated to the current page.

Full syntax:

{{#invoke:Wikidades|claim|item= |lang= |property= |qualifier= |value= |list= |tablesort= |formatting= |separator= |conjunction= |editicon= |showerrors= |default= }}

Additional syntax for table format:

{{#invoke:Wikidades|claim|item= |lang= |property= |qualifier= |qualifier2= |...|qualifierx= |formatting=table |tablesort= |sorting= |rowformat= |rowsubformat1= |...|rowsubformatx= |colformat0= |...|colformatx= |case0= |...|casex= |separator= |conjunction= |editicon= |showerrors= |default= |references= }}

General parameters[athraigh foinse]

  • item= (optional) Specifies an item (Qid) other than the associated to current page. Use it with moderation as arbitrary access to Wikidata is expensive. It can be defined in the parent frame of the template. Alias from.
  • lang= (optional) Indicates the code of a given language. It can be defined in the parent frame of the template. By default, it uses the local language of the wiki. If there is no label in this language then it tries in the fall back languages ​​defined in MediaWiki. On the debug console type =mw.dumpObject(mw.language.getFallbacksFor(mw.getContentLanguage():getCode())) to see the fallback languages of your wiki. If the label has not been found in the preferred language, it adds the language code and a label icon to translate it on Wikidata. Edit the value on Wikidata to translate it on Wikidata.
  • property= (required) Property id of the statement (Pid). It is possible to define alternative properties with any separator, for example "P17 or P131", and it gets the first one found. It also accepts a minuscule p, but it is not recommended. It also accepts the property label, for example "property=country" is equivalent to "property=P17" for Tír (P17).
  • qualifier= (optional) Qualifier (Pid) of a property value.
  • value= (optional) Value preferred to Wikidata one. It can be an optional parameter in a template with format {{{parameter|}}}, so if it exists then it takes the value of the parameter, if it is void then it gets the value of Wikidata.
    • value=NONE With this special value, it returns a void string. This allows to set a parameter that does not fetch anything from Wikidata, or to show only values provided in the template with {{{parameter|NONE}}}. It is equivalent to wiki syntax: {{#ifeq:{{{parameter|}}}|NONE|<!-- do nothing -->}}.
  • list= (optional):
    • list=true (default) shows a list of all preferred and normal values (see separator and conjuction below). It never fetches deprecated values.
    • list=false or list=no shows only one value, the best ranked (preferred or normal) or the oldest of those with the best rank.
    • list=bestrank shows a list of the best ranked values. It is equivalent to list=true if all values have the same rank. It is equivalent to list=false if only one value is best ranked. Definition list=firstrank is an alias.
    • list=lang for monolingual values, shows values corresponding to the language of the lang parameter. See parameters lang and formatting for monolingualtext.
    • list=notlang for monolingual values, it does not show values corresponding to the language of the lang parameter.
    • list=<number> Sets the maximum number of values to be returned. Setting it to list=1 is equal to list=false. Setting it to list=0 is equal to list=true.
    • tablesort=0 (optional) sorts the list in ascending order. By default, sorting is by rank (preferred, normal), and by order in Wikidata.
  • separator= (optional) Separator to use in lists or tables. For lists the default is MediaWiki:Comma-separator (in English a comma and a blank space ',%nbsp;'). For tables the default is a line break <br />. In some specials cases, a <br /> may not work if it is included with strip markers. The alternative is to use the mark of a line feed control character: separator=LF.
  • conjunction= (optional) Conjunction to use as a separator between the last two elements of a list. By default it is equal to 'separator' if it is defined, otherwise it is MediaWiki:And plus MediaWiki:Word-separator (in English ' and '). For tables the default is a line break <br />.
  • itemgender= (optional) Item where to check Gnéas nó inscne (P21) for using the feminine form if necessary. By default it is item. It is used in combination with case=gender.
  • editicon= (optional) Definition of the pencil icon Edit the value on Wikidata to show and edit the statement fetched from Wikitada (planned to pop-up an editing interace by mw:Wikidata Bridge). Value of editicion is get from invoke call, or from parent frame of the template, or by default from definition of value addpencil in Module:Wikidades/i18n as wiki setting.
    • editicon=true: show the icon. It will not be necessary if this is the default value of the wiki.
    • editicon=false or editicon=no: do not show the icon.
    • editicon=right: show the icon and align it to the right.
  • showerrors= (optional) With any value, typically 'yes', it shows error messages, if any. By default it shows the 'default' parameter.
  • default= (optional) Text to show for any error if 'showerrors' parameter is not defined.
  • sandbox= (opcional) With any value, typically 'yes', it redirects the invokes to Module:Wikidades/sandbox. The title of the subpage is retrived from MediaWiki:Sandboxlink-subpage-name, "sandbox" in English, check it in the wiki language if necessary. This parameter can be used as parent from a template. It makes no sense used directly in an invoke or require for testing purpouses. To be used only in preview or temporaly as the sandbox module sould not have any permanent link.

Parameters for formatting[athraigh foinse]

formatting= (optional). Options for formatting depending on the data value and type:

Data value entity:

  • formatting=raw Wikidata id (Qid or Pid) of the value.
  • formatting=label Label of the value in local language, its fall backs or as raw.
  • formatting=sitelink Title of the local site page, not linked. If there is no local page then it returns the format raw preffixed with interwiki link "d:".
  • formatting=internallink Internal link whenever possibe: 1) to local wiki page (sitelink), 2) red link to the label if it does not exist as sitelink in another Wikidata item, 3) to Wikidata as last option.
  • formatting=pattern Format using a pattern with $1 as a parameter to replace. It can include templates or parser functions with a non expanded format: {{((}}template{{!}}$1{{))}} or {{((}}template{{!}}parameter name{{=}}$1{{))}}, or alike.
The default format is a piped link with link target as sitelink and link label as label. A link to Wikidata is formatted with light blue color different than the internal blue link.
  • formatting=ucfirst Variant of the default piped link with uppercase in first letter of label. In a list, it is used only for the first value.
  • formatting=ucinternallink Both "ucfirst" and "internallink".

Data value string:

General:
  • formatting=pattern Format using a pattern with $1 as a parameter to replace, for example: formatting=[http://whc.unesco.org/en/list/$1 $1]. For identifiers statements with an autogenerated link, the pattern can be found in the talk page of the property. It can include templates or parser functions with a non expanded format (see above for entity).
Type URL:
  • formatting=weblink Format as external link with the website as label: [http://www.example.com example.com], [http://example.com/en/page example.com…].
Type external-id:
  • formatting=externalid Format as external link with the URL pattern from Formatter URL (P1630) in entity Pid of property.
Type math formula:
Returns the content wrapped with tag <math> that generates an image of the formua. See mw:Extension:Math and examples in Foirmle (P2534).
Type musical notation
Returns the content wrapped with tag <score> that generates an image of the score. See mw:Extension:Score and examples in Musical motif (P6686). Format options:
  • formatting=sound (optional) Adds the attribute sound="1" to the tag embeding an audio player after the score image.

Data value quantity:

By default it show the quantity.
  • formatting=unit Shows the quantity and the unit. It can show plural units if it is defined at Module:Wikidades/Units.
  • formatting=unitcode Shows the quantity and the code or abbreviation of the unit defined in Siombail (P5061). It can be changed locally at Module:Wikidades/Units. If not found it shows the unit name.
  • formatting=duration Shows a duration quantity broken into human-readable units: millennia, centuries, decades, years, days, hours, minutes, and seconds. For example 123456 seconds: 1 day, 10 hours, 17 minutes and 36 seconds. Previously it tries to convert the unit to seconds (using convert=Q11574), otherwise it assumes the quantity is expressed in seconds.
    • formatting=durationhms Shows the duration abbreviated in hours, minutes and seconds. For example 12345 seconds: 3h 25m 45s. Format of local abbreviations can be defined at Module:Wikidades/i18n in table "hms".
    • formatting=durationh:m:s Show the duration hms simplified, as in 3:25:45, or minutes and seconds as in 01:23 or 45:00.
  • formatting=raw Shows the quantity without any language format, that is with decimal point and no thousand separators. It is the appropriate format for numerical calculations. See also the function formatNum for applying the format to the final result according to language definitions.
  • formatting=pattern Format using a pattern with $1 as a parameter to replace.
  • convert=Qid (optional) Convert the quantity to the unit requested by its Qid. Conversions are made according to factors indicated in Qid for properties Conversion to SI unit (P2370) or Conversion to standard unit (P2442), except for temperatures defined with conversion formulas between ºC, ºF and ºK. For example, a value of "74 inch" with convert=Q174728 (ceintiméadar (Q174728)) gives "188 centimeters" according to the conversion "2.54 centimeter" indicated in orlach (Q218593). It is rounded keeping the default precision of the original value according to the number of significant figures. It can be combined with formatting=unitcode. It can also be used with formatting=table, see below.
  • convert=default (optional) Convertion of units defined in table convert_default at Module:Wikidades/Units.
  • convert=default2 (optional) Variant that shows two values: the converted quantity and the original quantity in brackets.
  • convert=M Converts to millions, rounding with no decimals, if the quantity is greater than 100,000,000. Adds M before the unit name or code, for example Meuro, M$.

Data value monolingual (monolingualtext):

  • formatting=language Returns the language code of a monolingual value, for example used in Ainm oifigiúil (P1448).
  • formatting=text Returns the text wrapped in a span with lang attribute, if it's different from the local language: <span lang="xx">foreign text</span>.
  • formatting=pattern Format using a pattern with $language and $text as parameters to be replaced, for exemple "formatting=($language) $text".
  • list=lang Shows the values corresponding to the defined language or the default language. See lang parameter above.
  • list=notlang Does not show the values corresponding to the defined language or the default language. For example, it may be useful for Ainm sa teanga dhúchais (P1559) avoiding redundancy in wiki local language.

Data value coordinates (globecoordinate):

  • formatting=latitude Returns the latitude in decimal format.
  • formatting=longitude Returns the longitude in decimal format.
  • formatting=globe (default) Returns the globe parameter recognized by Template:Coord. It is requested for coordinates of globes other than Earth.
  • formatting=$lat...$lon...$globe Format using a pattern with $lat, $lon and optionally $globe as parameters to be replaced. It can include templates with non expanded format, i.ex. {{((}}coord{{!}}$lat{{!}}$lon{{))}}.
  • formatting=dimension Returns the dimension in meters equivalent to dim parameter of GeoHack.

Data value datetime (labeled time):

By default it uses the format defined Module:Wikidades/i18n, in datetime table, depending on the precision. Optionally, for precision of day:
  • formatting= #time syntax Accepts any valid format of #time parser function. For example: formatting=d-m-Y (24-03-2024), formatting=[[j xg]] (24 an Mhárta), formatting=Y (2024).
Adds the calendar when it may be ambiguous: if the date is before 1582-10-15 and it is set to Gregorian, or if it is later than 1582-10-04 and it is set to Julian. See en:Adoption of the Gregorian calendar for further reading.

Parameters of table with propiety and qualifiers[athraigh foinse]

property qualifier1 qualifier2 etc.
values 1st statement $0 $1 $2, etc.
2nd, etc. $0 $1 $2, etc.

formatting=table A statement with qualifiers is considered as a table of values shown at right. You can define the format of the rows and each column in the table. Separators for rows by default are line breaks (see separator and conjunction above). If you really want the output in a wikitable you can use separator=</tr><tr> and the corresponding opening and closing tags before and after the invoke. Specific parameters for this format:

Columns:

  • qualifier1 ... qualifierx= Qualifiers with consecutive numbers without any limitation. General parameter qualifier is an alias for qualifier1.
    • qualifierx = Pid1 OR Pid2 Alternatives values for a qualifier, without limitation of successive ORs. It takes the first one found. A tyical example is Am (P585) OR Am tosaigh (P580).
    • qualifierx = Pid1/Pid2 From the entity value of property Pid1 it gets the parent value Pid2. This allows to obtain additional data in the table even though defined in a parent element. For example, to get railway lines with its icon: qualifier=P81/P154. It can be combined with the OR option taking priority the OR.
    • qualifierx = /Pid Equivalent to previous one but without Pid1, it gets another propiety of same entity. This allows to obtain values defined either in a qualifier or in a property.
  • colformat0 ... colformatx= Format to apply to each column, using 0 for the property and 1-x for every qualifier. It accepts the same syntax as formatting for each data type. See above #Parameters for formatting.
  • case0 ... casex= Grammatical case to apply to each column. Parameter case, without numbering, applies to all values. See above #General parameters.
  • convert0 ... convertx= Conversion of units to apply to each column. See above #Parameters for formatting, data type quantity.
  • whitelist0 ... whitelistx= List raw values, usually Qids, in a column to show the statement, with any separator.
  • blacklist0 ... blacklistx= List raw values, usually Qids, in a column to do not show the statement, with any separator. If a whitelist is used in a column and a blacklist in another column then results may be inexpected (vegeu un see a comment, in Catalan).
  • selectvalue1 ... selectvaluex= List raw values, usually Qids, in a column to show its value.
  • ignorevalue1 ... ignorevaluex= List raw values, usually Qids, in a column to do not show its value.

Rows:

  • rowformat= Format of the rows of values for property and qualifiers. The property uses the placeholder $0 and the qualifiers $1 to $x. By default it is rowformat=$0 ($1, ... $x). You can include list tags * or # and also templates or parser functions not expanded: {{((}}template{{!}}unnamed parameter{{!}}name{{=}}named parameter{{))}}. If used with parameter "references" (see above) you must include the placeholder $R0 for references.
  • rowsubformat1 ... rowsubformatx= Previous format to apply to $1-$x defined in rowformat, only if there is any value. For example "rowformat=$0 $1" and "rowsubformat1=($1)" gives "$0 ($1)" or "$0" if $1 is void, avoiding empty parenthesis. A rowsubformat may have several variables $1-$x. Note that substitutions are made consecutively in numeric order, so it may include a posterior $x but not an anterior one as it has been already handled.
  • tablesort= with values 0 to x, it sorts the table per property (0) or per qualifier (1 to x). Sorting is in ascending order alphabetically, numerically or by date. It accepts multiple sorting keys with any separator, i.e. tablesort=0/2/1. By default it sorts the property by rank (preferred, normal), and by order in Wikidata.
  • sorting=-1 sorts in descending order. With any other value, or by default, it sorts in ascending order. If tablesort is used with multiple keys, the sorting order is applied to all the keys.
  • list=false shows only the first row of the table, according to the order indicated or by default.

Function getLabel[athraigh foinse]

Returns the label of an item.

  • 1= (first positional parameter, required) Wikitada id of the item (Qid or Pid). Alias: item, from.
  • lang= (optional) Language code, as in function claim. See above #General parameters.
  • itemgender= (optional) Qid to determine the gender form to use for the label, as in function claim. See above #General parameters.
  • linked= (optional) With any value, except 'no', it returns the label linked either to sitelink page or to Wikidata.
  • label= (optional) Shows this label instead of one fetched from Wikidata. It makes sense if used with linked=yes.
  • editicon= (optional) allows to remove the pencil edit icon, as in function claim. See above #General parameters.

Function getParentValues[athraigh foinse]

Returns recursively values of a property labeled with a parent value.

  • item= (optional) Specifies an item (Qid) other than the associated to current page. Use it with moderation as arbitrary access to Wikidata is expensive.
  • property= (optional) Property id of the statement (Pid). By default it is Lonnaithe sa limistéar riaracháin (P131). Supports a list of alternative values ​​with any separator.
  • label= (optional) Parent property id to use as label. By defaut it is Sampla de (P31).
  • upto= (optional) Last iteration to fetch, if previously there is not any 'property' not found. Possible values:
    • upto=label: last 'label' to fetch, for example "upto=country".
    • upto=quantity: maximum number of iterations. By default it is 10 as a protection, large enough for commons cases.
  • uptolabelid= (optional) Alternative to upto=label using Qid instead.
  • uptovalueid= (optional) Alternative to uptolabelid using Qid of values instead of labels. It supports multiple values ​​with any separator. Alias uptolinkid provisionally for backwards compatibility.
  • labelshow= (optional) White list of labels to show with a slash as a separator.
  • showlabelid= (optional) Alternative to labelshow using Qid instead.
  • include_self=true (optional) Includes current page on the output list.
  • sorting=-1 (optional) Sorts the list of paired values in descending order.
  • last_only=true (optional) Only shows the last value fetched. For example with uptolinkid=Qid and last_only=true it will show the value correspondig to label Qid.
  • formatting= (optional) Format for the property value. By default it is a piped link to local page or Wikidata (see above formatting for data value entity).
  • valuetext= (optional) Property to use as link label with 'property' value as link target.
  • labelformat= (optional) Format for the label. By default it is "label" (see above formatting for data value entity).
  • rowformat= (optional) Output format for each pair of values, with placeholder $0 for the label and $1 for the value. By default it is "rowformat=$0 = $1", for example "country = [[France]]"
  • separator= (optional) Separator for each pair of label-value, by default <br />.
  • cascade=true (optional) Output with indentation. It may be useful if rowformat only uses $1.

Note: labels can be fixed for needs of an infobox in Module:Wikidades/labels. For example, in Catalan "Municipi del Brasil" is modified to "Municipi" removing the determiner introduced by a preposition.

Function linkWithParentLabel[athraigh foinse]

Creates a link with the label of a parent property.

It accepts most parameters of function claim, except "formatting" that uses the default "internallink". Additionally:

  • parent= the parent property id to use as a link label. It accepts alternative values with any separator, as it does the parameter "property" of function claim.

Function yearsOld[athraigh foinse]

Returns the age of a person calculating the completed years between birth date and death date or current date. If both dates do not have presicion of day then it show a range of years, maximum a decade.

The syntax is: {{#invoke:Wikidades|yearsOld|formatting= |item= }}. Parameters item and formatting are optionals. By default it show the quantity.

  • formatting=unit (optional) Gets the unit from table i18n["years-old"] at Module:Wikidades/i18n for singular or plural, in addition to paucal used in Slavic languages as Russian. See parser function PLURAL at mw:Help:Magic words#Localization.
  • formatting=pattern (optional) Format using a pattern with $1 as a placeholder for the quantity. A common use case is " ($1 years old)". It does not evaluate the expression in singular, plural or paucal amb fetches the unit from (Q24564698). As an alternative you can define a global pattern in table i18n["years-old"] that allows the parameter $1.

Function editAtWikidata[athraigh foinse]

Returns the pencil icon to edit a declaration on Wikidata.

Ssyntax: {{#invoke:Wikidades|editAtWikidata|<value>|item= |property= |lang= |editicon= }}

  • 1 (opcional), first unnamed parameter. If it exists it will not show any icon. For example if a parameter is informed locally then it has not been fetched from Wikidata and the icon is not needed.
  • property=Pid (required). Id of the property to link with anchor. It does not check the Pid, other anchors can be used, for example property=identifiers to link to the identifiers section.
  • item=Qid (optional). Id of the item. It will not be necessary if it is the same as the associated page.
  • lang=code (optional). Language code. Opening the link to Wikidata will display the page in this language. By default it uses the local wiki language for the main article space or the user language defined in the preferences for other namespaces.
  • editicon=<right/true> (optional). With value right it aligns to the right. Value true only makes sense if the wiki is set with ["addpencil"]=false at Module:Wikidades/i18n.

See above #General parameters for more reading about these parameters.

Utility functions[athraigh foinse]

  • getSiteLink Returns the title of local page for a given item. Syntax:
    {{#invoke:Wikidades|getSiteLink|<Qid>|<wiki>}}
    Without any parameter it return the current page. With a Qid it returns the local page linked in the Qid item. It returns a void string if there is no local page linked. A second parameter with the wiki code it return the page linked for this wiki (enwiki, frwiki,... cawiktionary, etc.)
  • lang Returns the language code as managed by function claim. See #General parameters above. Syntax:
    {{#invoke:Wikidades|lang|{{{lang|}}}}}
    Parameter lang is optional.
  • numStatements Returns the number of statements of a multivalue property considering only best ranked values. It allows the decide how to handle long lists. With a second unnamed parameter it counts the number of values of a qualifier. Syntax:
    {{#invoke:Wikidades|numStatements|<Pid>|item={{{item|}}} }}
    {{#invoke:Wikidades|numStatements|<Pid>|<Qual_id>|item={{{item|}}} }}
    Example: {{#invoke:Wikidades|numStatements|P47|item=Q1861}} → 6
    For more complex queries, for example with list=true for preferred and normal ranking or with filters as whitelist, it can be used with the same syntax as function claim, without positional parameters.
  • validProperty Returns "void" if the property is not found, or it has only statements with values "no value" or "some value" or with deprecated rank. Syntax:
    {{#invoke:Wikidades|validProperty|<Pid>|item={{{item|}}}
    It can be used as an alternative to #property. It accepts the same parameter used by this parser function: from is a alias for item.
  • formatNum Formats a quantity according to language definitions. It is equivalent to magic word formatnum with the option to specify a language other than the wiki default. Syntax:
    {{#invoke:Wikidades|formatNum|<num>|<lang>}}
    First requested parameter is the number to format. Second optional parameter is the language code (see parameter lang of function claim).
  • getTAValue Old function retrieving values of Terminologia Anatomica 98 ID (P1323). Removed and replaced with a simple call {{#invoke:Wikidades | claim | property=P1323 | formatting=externalid | separator=<br />}}.

Wikidata redirects[athraigh foinse]

A Wikidata element can be a redirect to another element, often as a result of a merge. The values ​​of a property can be provisionally a redirect, usually fixed by bot after a week. The treatment of redirects is as follows:

  • Function claim
    • With formatting=raw it returns the target of the redirect.
    • With parameters whitelist or blacklist, if the list of values ​​includes any redirect, it considers both the redirected Qid and the target Qid.
  • Function getLabel
    • It follows the redirected Qid to fetch the label from the target Qid.

All redirected Qids should be fixed in templates. There is a tracking in place to find them at Special:WhatLinksHere/Template:Track/wikidata/redirect.

The provisional tracking Special:WhatLinksHere/Template:Track/wikidata/redirect identifies redirected Qid to be fixed in templates.

Resolving redirects is pending of phab:T157868. Current technical solution may be expensive if there is no label in local language nor in fall back languages. It is recommanded to check the provisional tracking Special:WhatLinksHere/Template:Track/wikidata/label and add missing labels.

Using from another module[athraigh foinse]

All functions (claim, getLabel, getParentValues, linkWithParentLabel, yearsOld, lang) can be used from other modules via require with the same parameters provided in a table, for example:

require("Module:Wikidades").claim{item="Q...", property="P...", ...}
require("Module:Wikidades").getLabel({"Q...", ['lang']="en"})

Function claim can return a second value depending of parameter query that may be used on infobox modules for specific treatment. With query=untranslated it returns nil or true for values not translated in requested language. With query=num it returns the number of statements as function numStatements does.

Parameters that accept "true" or "false" values can be defined as boolean type.

Dependencies[athraigh foinse]

See also[athraigh foinse]