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 | ||
function getLabel( propertyName ) | function getLabel( propertyName ) | ||
local entity = mw.wikibase.getEntity() | local entity = mw.wikibase.getEntity() | ||
Zeile 74: | Zeile 45: | ||
end | end | ||
end | end | ||
-- Return the label for property, or the label of the linked entiy of that property | -- Return the label for property, or the label of the linked entiy of that property | ||
function label( frame ) | function label( frame ) | ||
return getLabel(string.lower(frame.args[1])) | return getLabel( string.lower(frame.args[1] )) | ||
end | end | ||
Zeile 129: | Zeile 76: | ||
getProperty = getProperty, | getProperty = getProperty, | ||
getImageLink = getImageLink, | getImageLink = getImageLink, | ||
getLabel = getLabel | getLabel = getLabel | ||
} | } |