Vés al contingut

Mòdul:Wikidades/ús/en

De la Viquipèdia, l'enciclopèdia lliure

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

[modifica]

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

[modifica]

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

[modifica]
  • 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 Country (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 conjunction 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=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.
  • listrank=bestrank lists only the best ranked values, either preferred or normal. If list=lang is used then bestrank is ignored. For compatibility with older versions, list=bestrank or list=firstrank are aliases. 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.
  • listmax=<number> Sets the maximum number of values to be returned. For compatibility with older versions, list=<number> is also valid. Setting listmax=1 is equal to list=false. Setting listmax=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 />.
  • qseparator= (opcional) Separator for qualifiers to use in lists or tables. For lists, the default is separator. For tables the default is MediaWiki:Comma-separator.
  • qconjunction= (opcional) Conjunction for qualifiers. For lists the default is conjunction. For tables, the default is qseparator.
  • case= (optional) Grammatical case to be used. As a general cases handled by the module:
  • itemgender= (optional) Item where to check Sex or gender (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 interface 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 subpage /sandbox. The title of the subpage is retrieved 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 purposes. To be used only in preview or temporally as the sandbox module should not have any permanent link.

Parameters for formatting

[modifica]

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

Data value entity:

Item or property (wikibase-item, wikibase-property):
  • 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 prefixed with interwiki link "d:".
  • formatting=internallink Internal link whenever possible: 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 has class extiw that can be formatted with templatestyles with a color different from the internal blue link, for example a lighter blue and the correspondent definition for dark mode.
  • 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".
Lexeme (wikibase-lexeme):
Fetches first lemma of the lexeme with its language code if it is different from the wiki language. For example, see Personal pronoun (P6553). It accepts formatting=raw and list=lang. See these parameters above.

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 auto-generated 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 formula. See mw:Extension:Math and examples in Defining formula (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, embedding an audio player after the score image.

Data value quantity:

By default it shows the quantity.
  • formatting=unit Shows the quantity and the unit. It can show plural units if it is defined at Module:Wikidades/Units.
    • formatting=unitlinked Alternative with unit name linked.
  • formatting=unitcode Shows the quantity and the code or abbreviation of the unit defined in Unit symbol (P5061). It can be changed locally at Module:Wikidades/Units. If not found it shows the unit name.
    • formatting=unitcodelinked Alternative with unit code linked.
  • 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 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 Shows duration hms simplified, as in 3:25:45, or minutes and seconds as in 01:23 or 45:00.
    • formatting=durationm:s Shows duration in minutes and seconds, even if greater than 60 minutes (i.e. used in duration of songs).
  • 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.
  • numformat=%width.precision'flag' Formats according to string.format specifiers for numbers, where width is the total width of the returned value, a point is the decimal separator, precision is the number of decimal places to show, and flag can be: f floating point, e scientific notation, i integer, o octal, h hexadecimal, E i H upper-case, among others. For example, for number 15.656: "%.1f" formats 15.7, "%05i" formats 00015, "%.2e" formats 1.57e+01.
  • 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 (Centimetre (Q174728)) gives "188 centimeters" according to the conversion "2.54 centimeter" indicated in Inch (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) Conversion 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 Official name (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 example "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 Name in native language (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-10-2024), formatting=[[j xg]] (24 d'octubre), 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 property and qualifiers

[modifica]
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 typical example is Point in time (P585) OR Start time (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 property 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.
    Using several whitelist, or several blacklist, it works as an OR function. If a whitelist is used in a column and a blacklist in another column then results may be unexpected (see an explanatory table, 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

[modifica]

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

[modifica]

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 Located in the administrative territorial entity (P131). Supports a list of alternative values with any separator.
  • label= (optional) Parent property id to use as label. By default, it is Instance of (P31).
  • uptolabelid= (optional) Last iteration to fetch, using Qid of labels, if previously there is not any 'property' not found. It supports multiple values with any separator.
  • 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.
  • upto= (optional) Quantity value of maximum number of iterations. By default it is 50 using uptolabelid or uptovalueid, otherwise it is 10 as a protection, large enough for common cases.
  • showlabelid= (optional) White list of label Qids to show, with any separator.
    • labelshow= (deprecated) Alternative to showlabelid using label values with a slash as a separator.
  • 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 corresponding 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

[modifica]

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 the function claim.

Function yearsOld

[modifica]

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 precision of day then it shows a range of years, maximum a decade.

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

  • formatting=unit (optional) Gets the unit from table i18n["years-old"] at Module:Wikidades/i18n for singular, plural or other plural forms as 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 and fetches the unit from Years old (Q24564698). As an alternative you can define a global pattern in table i18n["years-old"] that allows the parameter $1.

Function editAtWikidata

[modifica]

Returns the pencil icon to edit a declaration on Wikidata.

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

  • 1 (optional), 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

[modifica]
  • getSiteLink Returns the title of local page for a given item. Syntax:
    {{#invoke:Wikidades|getSiteLink|<Qid>|<wiki>}}
    Without any parameter it returns 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 multi-value 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 an 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. The second optional parameter is the language code (see parameter lang of function claim).

Wikidata redirects

[modifica]

A Wikidata element can be redirected 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.

When fetching data, it follows redirects: values fetched correspond to the target element of a redirect. If a Qid is used raw, not for fetching its data but for comparison purposes as in a filter, then a Qid redirected may provoke unexpected results. This may affect function claim with parameters whitelist, blacklist, selectvalue or ignorevalue, and function getParentValues with parameters uptolabelid, uptovalueid, showlabelid.

You can validate Qids included in a template, or other page. Use {{#invoke:Wikidades/debug|validateIds|<page>}} with the page title to check. For every Qid included in the page it shows: Ok (ok), Nay (not found) or#REDIRECT(redirect). This function is expensive and for a long list it may raise an error for not enough Lua memory.

Using from another module

[modifica]

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

[modifica]

See also

[modifica]