יחידה:PropertyLink: הבדלים בין גרסאות בדף
מאין תקציר עריכה |
מאין תקציר עריכה |
||
| שורה 3: | שורה 3: | ||
function p.property(frame) | function p.property(frame) | ||
entity = mw.wikibase.getEntity() | entity = mw.wikibase.getEntity() | ||
if entity == nil or entity.claims == nil then return nil end--the entity doesnt exist or have no claims | |||
if entity == nil or entity.claims == nil then | |||
propertyName = nil | propertyName = nil | ||
if frame.args ==nil then | if frame.args ==nil then | ||
| שורה 14: | שורה 11: | ||
end | end | ||
property = entity.claims[propertyName] | property = entity.claims[propertyName] | ||
if property == nil then | if property == nil then return nil end--no such property for this item | ||
property = property[0] | property = property[0] | ||
propValue = property.mainsnak.datavalue | propValue = property.mainsnak.datavalue | ||
if propValue ==nil then | if propValue ==nil then return nil end --property doesnt exist | ||
if propValue['type']=='wikibase-entityid' then | if propValue['type']=='wikibase-entityid' then | ||
linkTarget = mw.wikibase.sitelink("Q" .. propValue.value['numeric-id']) | linkTarget = mw.wikibase.sitelink("Q" .. propValue.value['numeric-id']) | ||
| שורה 27: | שורה 20: | ||
if not ((linkTarget == nil) or (linkTitle==nil)) then | if not ((linkTarget == nil) or (linkTitle==nil)) then | ||
return "[[" .. linkTarget .. "|" .. linkTitle .."]]" | return "[[" .. linkTarget .. "|" .. linkTitle .."]]" | ||
else | |||
return linkTitle | |||
end | end | ||
elseif propValue['type']=='string' then | elseif propValue['type']=='string' then | ||
| שורה 32: | שורה 27: | ||
end | end | ||
return nil | return nil | ||
end | |||
-- Return the label for property, or the label of the linked entiy of that property | |||
function p.label(frame) | |||
entity = mw.wikibase.getEntity() | |||
if entity == nil or entity.claims == nil then return nil end--the entity doesnt exist or have no claims | |||
propertyName = nil | |||
if frame.args ==nil then | |||
propertyName = frame | |||
else | |||
propertyName = frame.args[1] | |||
end | |||
property = entity.claims[propertyName] | |||
if property == nil then return nil end--no such property for this item | |||
property = property[0] | |||
propValue = property.mainsnak.datavalue | |||
if propValue ==nil then return nil 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 | |||
return nil | |||
end | end | ||
--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 p.imageLink(frame) | function p.imageLink(frame) | ||