Bearbeiten von „Modul:PropertyLink“
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 1: | Zeile 1: | ||
function | 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 | |||
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 7: | Zeile 13: | ||
if targetEntity and targetEntity['sitelinks'] then | if targetEntity and targetEntity['sitelinks'] then | ||
if targetEntity['sitelinks']['dewiki'] then | if targetEntity['sitelinks']['dewiki'] then | ||
linkTarget = | linkTarget = 'wikipedia:de:' .. targetEntity['sitelinks']['dewiki']['title'] | ||
elseif targetEntity['sitelinks']['enwiki'] then | elseif targetEntity['sitelinks']['enwiki'] then | ||
linkTarget = | linkTarget = 'wikipedia:' .. targetEntity['sitelinks']['enwiki']['title'] | ||
end | end | ||
end | end | ||
end | |||
local linkTitle = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] ) | local linkTitle = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] ) | ||
return linkTarget and linkTitle and mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle ) | |||
or linkTitle | |||
elseif propValue and propValue['type'] == 'string' then return propValue.value end | |||
elseif propValue and propValue['type'] == 'string' then | |||
end | end | ||
function property( frame ) | function property( frame ) | ||
return getProperty(string.upper(frame.args[1] | return getProperty(string.upper(frame.args[1])) | ||
end | end | ||
Zeile 75: | Zeile 46: | ||
end | end | ||
function | function getLabels( frame ) | ||
propertyName = frame.args[1] | propertyName = frame.args[1] | ||
local entity = mw.wikibase.getEntityObject() | local entity = mw.wikibase.getEntityObject() | ||
Zeile 88: | Zeile 59: | ||
if not propValue then return '' end --property doesnt exist | if not propValue then return '' end --property doesnt exist | ||
local value = | local value | ||
if propValue['type']=='wikibase-entityid' then | |||
value = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] ) | |||
elseif propValue['type'] == 'string' then | |||
value = propValue.value | |||
end | |||
if retVal == '' then | if retVal == '' then | ||
retVal = value | retVal = value | ||
Zeile 130: | Zeile 107: | ||
getImageLink = getImageLink, | getImageLink = getImageLink, | ||
getLabel = getLabel, | getLabel = getLabel, | ||
getLabels = getLabels, | |||
} | } |