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]

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]

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( 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( 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]

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 )
entity:formatPropertyValues( propertyId, acceptableRanks )
Get the formatted value of the claims with the given property id. 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 mw.wikibase.entity.claimRanks).

An example call might look like this:

-- Return a table like: { value = "Formatted claim value", label = "Label of the Property" }
entity:formatPropertyValues( 'P12' )
-- Return the normal ranked claims with the property Id 42 (same format as above)
entity:formatPropertyValues( 'P42', { mw.wikibase.entity.claimRanks.RANK_NORMAL } )

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

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

The available ranks are:


This can for example be used like this:

-- Return the normal ranked claims with the property id P5
entity:formatPropertyValues( 'P5', { mw.wikibase.entity.claimRanks.RANK_NORMAL } )
 -- Return all claims with id P123 (as the table passed contains all possible claim ranks)
entity:formatPropertyValues( 'P123', mw.wikibase.entity.claimRanks )

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.