יחידה:PropertyLink: הבדלים בין גרסאות בדף
מאין תקציר עריכה |
ניסיון להוספת קבלת מקור |
||
| שורה 96: | שורה 96: | ||
property = property[1] | property = property[1] | ||
local propValue = property.mainsnak.datavalue | local propValue = property.mainsnak.datavalue | ||
if not propValue then return '' end --property | if not propValue then return '' end --property doesn't exist | ||
if propValue['type'] == 'wikibase-entityid' then | if propValue['type'] == 'wikibase-entityid' then | ||
| שורה 105: | שורה 105: | ||
end | end | ||
-- Return the label for property, or the label of the linked | -- Return the label for property, or the label of the linked entity of that property | ||
function label( frame ) | function label( frame ) | ||
return getLabel( string.upper(frame.args[1] )) | return getLabel( string.upper(frame.args[1] )) | ||
end | |||
function getReference( propertyName , referenceID) | |||
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 ref = property.references[referenceID] | |||
local refValue = ref.mainsnak.datavalue | |||
if not refValue then return '' end --reference doesn't exist | |||
if refValue['type'] == 'wikibase-entityid' then | |||
return mw.wikibase.label( "Q" ..refValue.value['numeric-id'] ) | |||
elseif refValue['type'] == 'string' then | |||
return refValue.value | |||
end | |||
end | |||
-- Return the reference for property | |||
function reference( frame ) | |||
return getReference( string.upper(frame.args[1] ), string.upper(frame.args[2] )) | |||
end | end | ||