Modul:PropertyLink
Utseende
Denne modulen kan brukes til lenker fra Wikidata. Den inneholder følgende funksjoner:
- property - gir en lenke fra et utsagn på Wikidata
- Parameter: property (for eksempel p123)
- Eksemepl: i Løve vil {{#invoke:PropertyLink|property|p70}} gi rovpattedyr. Det er bedre å bruke denne funksjonen fremfor [[{{#property:p70}}]] siden property gir etiketten i Wikidata, mens denne funksjonen gir den riktige sidelenken.
- label: gir utsagnet i Wikidata (ingen [[lenke]])
- Parameter: property (for eksempel p123)
- imageLink: Gir mulighet for bruk av en relatert fil i artikkelen
- Parametere:
- 1 parameter (valgfritt) - Property for å få commonslenke. Hvis ikke spesifisert, brukes d:Property:p18 (en generisk property for bilder på Wikidata)
- width - standard 220px
- Parametere:
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 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
function property( frame )
return getProperty(string.lower(frame.args[1]))
end
function getLabel( 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.datavalue
if not propValue then return '' end --property doesnt exist
if propValue['type']=='wikibase-entityid' then
return mw.wikibase.label( "Q" ..propValue.value['numeric-id'] )
elseif propValue['type'] == 'string' then
return propValue.value
end
end
-- Return the label for property, or the label of the linked entiy of that property
function label( frame )
return getLabel( string.lower(frame.args[1] ))
end
function getImageLink( propName, width)
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[propName or "P18"]
if property then
local width = width or "220"
return mw.ustring.format( '[[File:%s|%spx]]', property[1].mainsnak.datavalue.value, width )
end
end
--use this function to get associated image to be used in the article
function imageLink( frame )
return getImageLink(string.lower(frame.args[1]), frame.args["width"])
end
return {
imageLink = imageLink,
Image = imageLink,
File = imageLink,
label = label,
Label = label,
property = property,
Property = property,
getProperty = getProperty,
getImageLink = getImageLink,
getLabel = getLabel
}