Extension:Wikibase Client/Lua

Wikibase Client provides a Lua Scribunto interface that implements functions to access data from the Wikibase repository, if the Wikibase Client configuration enables. Lua modules and wiki templates can invoke these functions.

Changes to the Wikibase Lua interface are subject to the Stable Interface Policy.

mw.wikibase
has general Lua functionality for working with Wikibase data.

mw.wikibase.getEntityIdForCurrentPage
Gets the Item id of the item connected to the current page.

An example call might look like this:

mw.wikibase.getEntityIdForTitle
Takes a string page title in the local wiki and returns the connected item ID, if it exists. Returns nil if there's no linked item.

mw.wikibase.getEntity

 * This function is expensive when called with the ID of an entity not connected to the current page. Loading entities doesn't count as expensive if the same entity is loaded twice during a module run. However, due to restrictions in the caching, if more than 14 other entities are loaded inbetween, the entity must be fetched again, which then counts as expensive.

Gets a mw.wikibase.entity table with data of the Wikibase item requested by id. If no id was given, the item connected to the current page will be returned. Requesting an item by id is only supported if arbitrary access is enabled.

An example call might look like this:

mw.wikibase.getEntityObject
Alias for mw.wikibase.getEntity.

mw.wikibase.getBestStatements
Returns a table with the "best" statements matching the given property ID on the given entity ID. The definition of "best" is that the function will return "preferred" statements, if there are any, otherwise "normal" ranked statements. It will never return "deprecated" statements. This is what you usually want when surfacing values to an ordinary reader.

An example call might look like this:

mw.wikibase.getAllStatements
Returns a table with all statements (including all ranks, even "deprecated") matching the given property ID on the given entity ID.

An example call might look like this:

mw.wikibase.getEntityUrl
Takes an entity ID and returns the canonical URL to the entity in the repo.

If no ID was specified, the URL of the item connected to the current page will be returned, if the page is connected. An example call might look like this:

mw.wikibase.getLabelWithLang
Like, but has the language the returned label is in as an additional second return parameter.

An example call might look like this:

mw.wikibase.label
Takes an item ID and returns the label in the language of the local Wiki.

If no ID was specified, then the label of the item connected to the current page will be returned, if the page is indeed connected and a label exists. The label will either be in the Wiki's language (on monolingual wikis) or the user's language (on multilingual Wikis), furthermore language fallbacks will be applied. See also.

An example call might look like this:

mw.wikibase.getLabelByLang
Get the label from an entity for a specific language, returns the label as string or nil if it couldn't be found. This doesn't apply any language fallbacks.

Note: This should not be used to get the label in the user's language on multilingual wikis, use  for that if by any means possible.

An example call might look like this:

mw.wikibase.getDescriptionWithLang
Like, but has the language the returned description is in as an additional second return parameter.

An example call might look like this:

mw.wikibase.description
Takes an item ID and returns the description in the language of the local Wiki.

If no ID was specified, then the description of the item connected to the current page will be returned, if the page is indeed connected and a description exists. The description will either be in the Wiki's language (on monolingual wikis) or the user's language (on multilingual Wikis), furthermore language fallbacks will be applied. See also.

An example call might look like this:

mw.wikibase.sitelink
Takes an item ID and returns the title of the corresponding page title on the local Wiki. This page title can be used to link to the given page.

When  is given, the page title on the specified wiki is returned, rather than the one on the local wiki.

An example call might look like this:

mw.wikibase.renderSnak
Renders a serialized Snak value to wikitext escaped plain text. This is useful for displaying References or Qualifiers.

An example call might look like this:

mw.wikibase.formatValue
Renders a serialized Snak value to rich wikitext. This is useful for displaying References or Qualifiers.

An example call might look like this:

mw.wikibase.renderSnaks
Renders a list of serialized Snak values to wikitext escaped plain text. This is useful for displaying References or Qualifiers.

An example call might look like this:

mw.wikibase.formatValues
Renders a list of serialized Snak values to rich wikitext. This is useful for displaying References or Qualifiers.

An example call might look like this:

mw.wikibase.resolvePropertyId
Returns a property id for the given label or id. This allows using the property's labels instead of ids in all places. If no property was found for the label, a nil value is returned.

An example call might look like this:

mw.wikibase.orderProperties
Returns a table with the given property IDs ordered according to the page MediaWiki:Wikibase-SortedProperties.

An example call might look like this:

mw.wikibase.getPropertyOrder
Returns a table with the order of property IDs as provided by the page MediaWiki:Wikibase-SortedProperties. If the page does not exist, a nil value is returned.

An example call might look like this:

mw.wikibase.entity
represents a Wikibase entity in Lua. A  table for the item which is linked with the current page can be obtained with.

Functions documented as  are available on the global   table; functions documented as   are methods of an   object (see  ).

mw.wikibase.entity.claimRanks
The  table contains a map of all available claim ranks.

The available ranks are:
 * 1) RANK_TRUTH
 * 2) RANK_PREFERRED
 * 3) RANK_NORMAL
 * 4) RANK_DEPRECATED

This can for example be used like this:

mw.wikibase.entity.create
Create new entity object from given data. mw.wikibase.getEntity should really be used.

Object entries include:
 * claims :very similar to :getAllStatements
 * labels :see also :getLabel
 * sitelinks :see also :getSitelink
 * descriptions :see also :getDescription
 * aliases :see also :getLabel

mw.wikibase.entity:getLabel
Returns the label of the entity in the language given as  or in the Wiki's content language (on monolingual wikis) or the user's language (on multilingual wikis). See also.

An example call might look like this:

mw.wikibase.entity:getDescription
Returns the description of the entity in the language given as  or in the Wiki's content language (on monolingual wikis) or the user's language (on multilingual wikis). See also.

An example call might look like this:

mw.wikibase.entity:getLabelWithLang
Like, but has the language the returned label is in as an additional second return parameter.

An example call might look like this:

mw.wikibase.entity:getDescriptionWithLang
Like, but has the language the returned description is in as an additional second return parameter.

An example call might look like this:

mw.wikibase.entity:getSitelink
Get the title with which the entity is linked in the current Wiki. If  is given, the title the item is linked with in the given Wiki will be returned.

An example call might look like this:

mw.wikibase.entity:getBestStatements
Get the best statements with the given property label or id. This includes all statements with rank "preferred" or, if no preferred ones exist, all statements with rank "normal". Statements with rank "deprecated" are never included.

An example call might look like this:

mw.wikibase.entity:getAllStatements
Get the all statements with the given property label or id. This includes all statements regardless of rank.

An example call might look like this:

mw.wikibase.entity:getProperties
Get a table with all property ids attached to the item.

An example call might look like this:

mw.wikibase.entity:formatPropertyValues
Get the values of the Statements with the given property (which is either identified by a property id, or by the label of the property), formatted as wikitext escaped plain text. Per default only the best claims will be returned. Alternatively a table with acceptable ranks can be given as second parameter (a mapping table with all ranks can be found in ).

An example call might look like this:

is an empty string ( '' ) if there's no statement with the given property on the entity. will be nil if the given property doesn't exist.

mw.wikibase.entity:formatStatements
Like, but the returned values will be formatted as rich wikitext, rather than just wikitext escaped plain text.