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( propertyName ) | ||
local entity = mw.wikibase.getEntity('Q29') | |||
local entity = mw.wikibase. | |||
if not entity or not entity.claims then return end--the entity doesnt exist or have no claims | if not entity or not entity.claims then return end--the entity doesnt exist or have no claims | ||
local properties = entity.claims[propertyName] | local properties = entity.claims[propertyName] | ||
if not properties then return end--no such property for this item | if not properties then return table.getn(entity.claims) end--no such property for this item | ||
local retVal = '' | local retVal = 'lol' | ||
for | for property in pairs(properties) do | ||
local propValue = property.mainsnak.datavalue | local propValue = property.mainsnak.datavalue | ||
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 | ||
else | else | ||
retVal = retVal | retVal = retVal + ', ' + value | ||
end | end | ||
end | end | ||
Zeile 101: | Zeile 76: | ||
-- 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 130: | Zeile 105: | ||
getImageLink = getImageLink, | getImageLink = getImageLink, | ||
getLabel = getLabel, | getLabel = getLabel, | ||
getLabels = getLabels, | |||
} | } |