A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://commons.wikimedia.org/wiki/Special:MyLanguage/Commons:Structured_data/Lua below:

Commons:Structured data/Lua - Wikimedia Commons

From Wikimedia Commons, the free media repository

This page is a

work in progress

page, not an article or policy, and may be incomplete and/or unreliable.

Please offer suggestions on the

talk page

.

Lua programing language is used as a back end of many templates on Commons, including many templates that interact with Wikidata and now, it also can be used to access structured data on Commons. Documentation of Lua libraries designed to interface with Wikidata can be found at mw:Extension:Wikibase_Client/Lua. Some of the functions described there work with structured data on Commons, but some do not work as described. The rest of this page will describe what is the same, what is different and what is untested in that library as applied to Commons.

Diagram of a Commons file with terms used to describe it

According to Wikidata Glossary the entity is the content of a Wikidata page, such as an item (in the Wikidata main namespace) or a property (in the property namespace). In structured data on Commons each file (page in file namespace) has associated entity. The unique entity identifier for entities on Commons are derived from unique page ID, which can be accessed by magic word {{PAGEID}} preceded by letter "M". Those M-IDs are equivalent to Q-IDs of Wikidata items or P-IDs of properties. For example this Mona Lisa file has entity ID (M-ID) "M15442524". The content of structured data entity associated with that file can be seen through URL like https://commons.wikimedia.org/w/api.php?action=wbgetentities&ids=M15442524 or https://commons.wikimedia.org/w/api.php?action=wbgetclaims&entity=M15442524, which is equivalent to URL showing content of Wikidata item. For example content of Mona Lisa (Q12418) can be by https://commons.wikimedia.org/w/api.php?action=wbgetentities&ids=Q12418.

This section discusses how Lua modules can access data stored in Structured data

mw.wikibase.mediainfo.getEntityIdForTitle[edit]

mw.wikibase.mediainfo.getEntityIdForTitle( pageTitle )
Gets the mw.wikibase.mediainfo.entityId from the page name. An example call might look like this:

mw.wikibase.mediainfo.getEntityIdForTitle( 'File:Mona Lisa, by Leonardo da Vinci, from C2RMF retouched.jpg' ) -- Returns the M-ID for the file, like "M15442524".
mw.wikibase.mediainfo.getCaptionWithLang[edit]

mw.wikibase.mediainfo.getCaptionWithLang( id )
Get the caption from an entity, returns the label as string or nil if it couldn't be found and the language code as a second value. This doesn't apply any language fallbacks.

mw.wikibase.mediainfo.getCaptionWithLang( 'M15442524' ) -- Returns the caption in the language the user has set the interface too, returns a string, example "Leonardo da Vinci's Mona Lisa (between 1503 and 1506)" en.
mw.wikibase.mediainfo.getCaption[edit]

mw.wikibase.mediainfo.getCaption( id )
Get the caption from an entity with the interface language as preferred, returns the label as string or nil if it couldn't be found. This doesn't apply any language fallbacks.

mw.wikibase.mediainfo.getCaption( 'M15442524' ) -- Returns the caption in the language the user has set the interface too, returns a string, example "Leonardo da Vinci's Mona Lisa (between 1503 and 1506)".
mw.wikibase.mediainfo.getCaptionByLang[edit]

mw.wikibase.mediainfo.getCaptionByLang( id, languageCode )
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.

An example call might look like this:

mw.wikibase.mediainfo.getCaptionByLang( 'M15442524', 'ru' ) -- Returns the Russian label of the item as a string, like "Мона Лиза".
mw.wikibase.getEntity[edit]

wikibase.getEntity( id )

Gets a mw.wikibase.entity table with data of the Wikibase item requested by id. An example call might look like this:

mw.wikibase.getEntity( 'M15442524' ) -- Returns a mw.wikibase.entity table for the item with the id M15442524

wikibase.getEntity() without an ID should get a mw.wikibase.entity table with data of the item connected to the current page, so on Commons when used on page in File namespace should return entity for that file. However as of fall 2019, that functionality does not work. See phabricator:T237107.

mw.wikibase.getLabelByLang[edit]

wikibase.getLabelByLang( id, languageCode )
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.

An example call might look like this:

mw.wikibase.getLabelByLang( 'M15442524', 'ru' ) -- Returns the Russian label of the item as a string, like "Мона Лиза".

That function is used by Module:Wikidata label so that {{#invoke:Wikidata label|getLabel |item=M15442524|lang=ru}} returns "Мона Лиза".

mw.wikibase.entity:getBestStatements[edit]

entity:getBestStatements( propertyIdOrLabel )
Suppose to get the best statements with the given property id or label. Does not work as of fall 2019. See phabricator:T237107.

mw.wikibase.entity:getSitelink[edit]

entity:getSitelink()
entity:getSitelink( globalSiteId )
This property is removed from the MediaInfo entities. See phabricator:T240563.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4