יחידה:PropertyLink: הבדלים בין גרסאות בדף
לבקשת ערן |
ביטול החזרת מחרוזת ריקה: הפונקציות נקראות גם ממודולים אחרים, ולמחרוזת ריקה יש ערך "אמת", מה שעלול לגרום לשגיאות. במקום זה - החזרת nil. |
||
| שורה 1: | שורה 1: | ||
function property( frame ) | function property( frame ) | ||
local entity = mw.wikibase.getEntity() | local entity = mw.wikibase.getEntity() | ||
if not entity or not entity.claims then return | if not entity or not entity.claims then return end--the entity doesnt exist or have no claims | ||
local propertyName = type( frame ) == string and frame or frame.args[1] | local propertyName = type( frame ) == string and frame or frame.args[1] | ||
local property = entity.claims[propertyName] | local property = entity.claims[propertyName] | ||
if not property then return | if not property then return end--no such property for this item | ||
property = property[0] | property = property[0] | ||
local propValue = property.mainsnak and property.mainsnak.datavalue | local propValue = property.mainsnak and property.mainsnak.datavalue | ||
if not propValue then return | if not propValue then return end --property doesnt exist | ||
if propValue['type'] == 'wikibase-entityid' then | if propValue['type'] == 'wikibase-entityid' then | ||
local linkTarget = mw.wikibase.sitelink( "Q" .. propValue.value['numeric-id'] ) | local linkTarget = mw.wikibase.sitelink( "Q" .. propValue.value['numeric-id'] ) | ||
| שורה 14: | שורה 14: | ||
or linkTitle | or linkTitle | ||
elseif propValue and propValue['type'] == 'string' then return propValue.value end | elseif propValue and propValue['type'] == 'string' then return propValue.value end | ||
return | return | ||
end | end | ||
| שורה 20: | שורה 20: | ||
function label( frame ) | function label( frame ) | ||
local entity = mw.wikibase.getEntity() | local entity = mw.wikibase.getEntity() | ||
if not entity or not entity.claims then return | if not entity or not entity.claims then return end--the entity doesnt exist or have no claims | ||
local propertyName = type( frame ) == "string" and frame or frame.args[1] | local propertyName = type( frame ) == "string" and frame or frame.args[1] | ||
local property = entity.claims[propertyName] | local property = entity.claims[propertyName] | ||
if not property then return | if not property then return end--no such property for this item | ||
property = property[0] | property = property[0] | ||
| שורה 34: | שורה 34: | ||
return propValue.value | return propValue.value | ||
end | end | ||
end | end | ||
| שורה 41: | שורה 40: | ||
function imageLink( frame ) | function imageLink( frame ) | ||
local entity = mw.wikibase.getEntity() | local entity = mw.wikibase.getEntity() | ||
if not entity or not entity.claims then return | if not entity or not entity.claims then return end --the entity doesnt exist or have no claims | ||
local property = entity.claims[frame and frame.args and frame.args[1] or "p18"] | local property = entity.claims[frame and frame.args and frame.args[1] or "p18"] | ||
if property then | if property then | ||
| שורה 47: | שורה 46: | ||
return mw.usitring.format( '[[File:%s|%spx]]', property, width ) | return mw.usitring.format( '[[File:%s|%spx]]', property, width ) | ||
end | end | ||
end | end | ||