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 getProperty( propertyName ) | |||
local entity = mw.wikibase.getEntity() | |||
function getProperty(propertyName | |||
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 property = entity.claims[propertyName] | local property = entity.claims[propertyName] | ||
if not property then return end--no such property for this item | if not property then return end--no such property for this item | ||
property = property[ | property = property[0] | ||
local propValue = property.mainsnak and property.mainsnak.datavalue | local propValue = property.mainsnak and property.mainsnak.datavalue | ||
if not propValue then return end --property doesnt exist | 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 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 | |||
end | end | ||
function property( frame ) | function property( frame ) | ||
return getProperty | return getProperty(frame.args[1]) | ||
end | end | ||
function getLabel( propertyName ) | function getLabel( propertyName ) | ||
local entity = mw.wikibase.getEntity() | local entity = mw.wikibase.getEntity() | ||
Zeile 74: | Zeile 35: | ||
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 | return getLabel( frame.args[1] ) | ||
end | end | ||
function getImageLink( propName, width) | function getImageLink( propName, width) | ||
local entity = mw.wikibase.getEntity() | local entity = mw.wikibase.getEntity() | ||
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 property = entity.claims[propName or " | local property = entity.claims[propName or "p18"] | ||
if property then | if property then | ||
local width = width or "220" | local width = width or "220" | ||
return mw.ustring.format( '[[File:%s|%spx]]', property[ | return mw.ustring.format( '[[File:%s|%spx]]', property[0].mainsnak.datavalue.value, width ) | ||
end | end | ||
end | end | ||
Zeile 116: | Zeile 53: | ||
--use this function to get associated image to be used in the article | --use this function to get associated image to be used in the article | ||
function imageLink( frame ) | function imageLink( frame ) | ||
return getImageLink | return getImageLink(frame.args[1], frame.args["width"]) | ||
end | end | ||
Zeile 129: | Zeile 66: | ||
getProperty = getProperty, | getProperty = getProperty, | ||
getImageLink = getImageLink, | getImageLink = getImageLink, | ||
getLabel = getLabel | getLabel = getLabel | ||
} | } |