Module:PropertyLink
This module can be used for advance linking, according to Wikidata. It includes the following functions:
This module can be used for advance linking, according to Wikidata. It includes the following functions:
- property - get a link according to wikidata claim
- label: gives the label in wikidata (no [[link]])
- Parameters: property (e.g p123)
- imageLink: Get a related file to be used in the article
- Parameters:
- 1 param (optional) - Property to get commons link. If not specified it uses d:Property:p18 (a generic property for image in wikidata)
- width - default 220px
- Parameters:
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.upper(frame.args[1]))
end
function getLabel( propertyName )
local entity = mw.wikibase.getEntity()
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[0]
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.getEntity()
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[0].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
}
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.