Modul:PropertyLink: Unterschied zwischen den Versionen
Keine Bearbeitungszusammenfassung |
Keine Bearbeitungszusammenfassung |
||
Zeile 1: | Zeile 1: | ||
function | function getLinkLabel(propValue) | ||
if propValue['type'] == 'wikibase-entityid' then | |||
local linkTarget = mw.wikibase.sitelink( "Q" .. propValue.value['numeric-id'] ) | local linkTarget = mw.wikibase.sitelink( "Q" .. propValue.value['numeric-id'] ) | ||
if not linkTarget then | if not linkTarget then | ||
Zeile 22: | Zeile 15: | ||
return linkTarget and linkTitle and mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle ) | return linkTarget and linkTitle and mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle ) | ||
or linkTitle | or linkTitle | ||
elseif propValue and propValue['type'] == 'string' then return propValue.value end | elseif propValue and propValue['type'] == 'string' then | ||
return propValue.value | |||
end | |||
end | |||
function getProperty( propertyName ) | |||
local entity = mw.wikibase.getEntityObject() | |||
if not entity or not entity.claims then return end--the entity doesnt exist or have no claims | |||
local property = entity.claims[propertyName] | |||
if not property then return end--no such property for this item | |||
property = property[1] | |||
local propValue = property.mainsnak and property.mainsnak.datavalue | |||
if not propValue then return end --property doesnt exist | |||
return getLinkLabel(propValue) | |||
end | end | ||
Zeile 46: | Zeile 53: | ||
end | end | ||
function | function getLinkLabels( frame ) | ||
propertyName = frame.args[1] | propertyName = frame.args[1] | ||
local entity = mw.wikibase.getEntityObject() | local entity = mw.wikibase.getEntityObject() | ||
Zeile 59: | Zeile 66: | ||
if not propValue then return '' end --property doesnt exist | if not propValue then return '' end --property doesnt exist | ||
local | local value = getLinkLabel(propValue) | ||
if retVal == '' then | if retVal == '' then | ||
retVal = value | retVal = value | ||
Zeile 107: | Zeile 108: | ||
getImageLink = getImageLink, | getImageLink = getImageLink, | ||
getLabel = getLabel, | getLabel = getLabel, | ||
getLinkLabels = getLinkLabels, | |||
} | } |