Extension:Wikibase Client/Lua

From MediaWiki.org
Jump to: navigation, search

Wikibase Client provides a Lua Scribunto interface that, if activated, can be used to access data from the Wikibase repository.

mw.wikibase[edit | edit source]

In mw.wikibase general Lua functionality for working with Wikibase data can be found.

mw.wikibase.getEntityObject[edit | edit source]

wikibase.getEntityObject()
Gets a mw.wikibase.entity table with data of the Wikibase item connected to the current page.

mw.wikibase.label[edit | edit source]

wikibase.label( id )
Takes an item ID and returns the label in the language of the local Wiki.

An example call might look like this:

mw.wikibase.label( 'Q42' ) -- Returns the label of the item as a string, like "Berlin"

mw.wikibase.sitelink[edit | edit source]

wikibase.sitelink( id )
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.

An example call might look like this:

mw.wikibase.sitelink( 'Q42' ) -- Returns the given items page title in the current Wiki as a string, like "Berlin".

mw.wikibase.getEntity[edit | edit source]

wikibase.getEntity()
Gets entity data of the Wikidata item connected with the current page. The returned object will have a legacy format, where tables are 0-based rather than 1-based. Also they will hold claims with both upper an lower case property ids (lower key property ids are deprecated).

Deprecated: Please use mw.wikibase.getEntityObject

mw.wikibase.entity[edit | edit source]

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

Functions documented as mw.wikibase.entity.name are available on the global mw.wikibase.entity table; functions documented as mw.wikibase.entity:name are methods of an mw.wikibase.entity object (see mw.wikibase.entity.create).

mw.wikibase.entity:getLabel[edit | edit source]

entity:getLabel()
entity:getLabel( langCode )
Returns the label of the entity in the language given as langCode or in the Wiki's content language.

An example call might look like this:

entity:getLabel( 'de' ) -- Returns a string, like "Berlin"

mw.wikibase.entity:getSitelink[edit | edit source]

entity:getSitelink()
entity:getSitelink( globalSiteId )
Get the title the entity is linked with in the current Wiki. If globalSiteId is given, the title the item is linked with in the given Wiki will be returned.

An example call might look like this:

entity:getSitelink() -- Returns the items page title in the current Wiki as a string, like "Moskow"
entity:getSitelink( 'ruwiki' ) -- Returns the items page title in the Russian Wikipedia as a string, like "Москва"

mw.wikibase.entity:getProperties[edit | edit source]

entity:getProperties()
Get a table with all property ids attached to the item.

An example call might look like this:

entity:getProperties() -- Returns a table like: { "P123", "P1337" }

mw.wikibase.entity:formatPropertyValues[edit | edit source]

entity:formatPropertyValues( propertyId )
Get the formatted value of the claims with the given property id.

An example call might look like this:

entity:formatPropertyValues( 'P12' ) -- Returns a table like: { value = "Formatted claim value", label = "Label of the Property" }

mw.wikibase.entity.create[edit | edit source]

mw.wikibase.entity.create( data )
Creates a new mw.wikibase.entity object for the given entity data table. This function is only used for internal calls in the current state of the Lua integration.