Commons:Structured data/Lua
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.
Basics
[edit]
According to PAGEID}} preceded by letter "M". Those M-IDs are equivalent to Q-IDs of Wikidata items or P-IDs of Mona Lisa (Q12418) can be by https://commons.wikimedia.org/w/api.php?action=wbgetentities&ids=Q12418.
Lua access
[edit]This section discusses how Lua modules can access data stored in Structured data
mw.wikibase.mediainfo
[edit]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
[edit]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 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.
Lua Modules accessing SDC
[edit]- Module:Information via {{Information}} template:
- if description field is missing, and SDC stores captions (labels) than a SDC caption will be shown in place of description.
- if source field is missing, and SDC has source of file (P7482) property, than source field is set based on P7482.
- if date field is missing, and SDC has inception (P571) property, than source field is set based on P571.
- if author field is missing, and SDC has creator (P170) property, than author field is set based on P170.
- Module:Artwork via {{Artwork}} or {{Book}} templates:
- if wikidata field is missing, and SDC has digital representation of (P6243) property, than wikidata field is set to P6243.
- if source_ field is missing, and SDC has source of file (P7482) property, than source_ field is set based on P7482. See examples here and here.
- Module:Coordinates via {{Location}} and {{Object location}} templates:
- uses coordinate location (P625) properties if coordinates are missing
- {{Title}} with wikidata field can fetch titles from wikidata. No (or very few) files have {{Title}} with wikidata field, but if Structured data has digital representation of (P6243) property, then wikidata field is set to P6243.
- Presents with {{FileSD}} an image in a thumb format with the use of Captions and Structured Data.
- {{Structured Data}} - fetches all information about the file from the structured data fields + Wikidata
- Module:SDC tracking - adds maintenance categories based on absence or presence of different SDC properties
- Module:Statement – can be used by other templates or modules