יחידה:PropertyLink: הבדלים בין גרסאות בדף
מאין תקציר עריכה |
מ תיקון יחידות מידה מקוצרות, הכנה לREF |
||
| שורה 20: | שורה 20: | ||
local propValue = property.mainsnak and property.mainsnak.datavalue | local propValue = property.mainsnak and property.mainsnak.datavalue | ||
local lang = mw.getContentLanguage() | local lang = mw.getContentLanguage() | ||
local langCode = lang:getCode() | |||
local asOfDate = asOfDateQualifier(property) | local asOfDate = asOfDateQualifier(property) | ||
local localAmount = lang:formatNum( tonumber(propValue.value.amount) ) | local localAmount = lang:formatNum( tonumber(propValue.value.amount) ) | ||
| שורה 28: | שורה 29: | ||
-- name from label | -- name from label | ||
unit = mw.wikibase.label( unitEntityId ) or '' | unit = mw.wikibase.label( unitEntityId ) or '' | ||
local unitSymbol = mw.wikibase.getBestStatements(unitEntityId, ' | local unitSymbol = mw.wikibase.getBestStatements(unitEntityId, 'P5061') | ||
-- name from properties | -- name from properties | ||
if unitSymbol then | if unitSymbol then | ||
local writingSystemElementId = 'Q33513' -- hebrew writing system | local writingSystemElementId = 'Q33513' -- hebrew writing system | ||
local langElementId = 'Q9288' -- hebrew | local langElementId = 'Q9288' -- hebrew | ||
local labelFilter = ' | local labelFilter = 'P5061[language:'..langCode..'], P5061[P282:' .. writingSystemElementId .. ', P407:' .. langElementId .. ']' | ||
local WDS = require( 'Module:WikidataSelectors' ) | local WDS = require( 'Module:WikidataSelectors' ) | ||
local labelClaims = WDS.filter( {[' | local labelClaims = WDS.filter( {['P5061']=unitSymbol }, labelFilter ) | ||
for r, claim in pairs( labelClaims ) do | for r, claim in pairs( labelClaims ) do | ||
if claim.mainsnak | if claim.mainsnak and claim.mainsnak.datavalue.type == 'monolingualtext' and claim.mainsnak.datavalue.value.text then | ||
unit = claim.mainsnak.datavalue.value.text | |||
break; | |||
elseif claim.mainsnak and claim.mainsnak.datavalue and claim.mainsnak.datavalue.type == 'string' and claim.mainsnak.datavalue.value ~= '' then | |||
unit = claim.mainsnak.datavalue.value | unit = claim.mainsnak.datavalue.value | ||
break | break; | ||
end | end | ||
end | end | ||
| שורה 229: | שורה 229: | ||
return getProperty(string.upper(frame.args[1]), (frame.args[2] and string.len(frame.args[2])>0) or false, true, frame.args['entity'], ', ', '', true) | return getProperty(string.upper(frame.args[1]), (frame.args[2] and string.len(frame.args[2])>0) or false, true, frame.args['entity'], ', ', '', true) | ||
end | end | ||
-- formatted reference for statement. Only for non imported statements | |||
function refStatement(statement) | |||
if not statement.references or #statement.references == 0 then return '' end -- no reference | |||
local formattedReferences = {} | |||
local frame = mw.getCurrentFrame() | |||
for j, curRef in ipairs(statement.references) do | |||
local isImportedRef = curRef.snaks and (curRef.snaks['P143'] or curRef.snaks['P4656']) | |||
if not isImportedRef then | |||
if curRef.snaks['P854'] then | |||
table.insert(formattedReferences, frame:extensionTag{ name = 'ref', content = mw.wikibase.renderSnak(curRef.snaks['P854'][1])}) | |||
elseif curRef.snaks['P2699'] then | |||
table.insert(formattedReferences, frame:extensionTag{ name = 'ref', content = mw.wikibase.renderSnak(curRef.snaks['P2699'][1])}) | |||
end | |||
end | |||
end | |||
return table.concat(formattedReferences, '') | |||
end | |||
--[[ | --[[ | ||
Fetch property from specified entity. | Fetch property from specified entity. | ||
| שורה 257: | שורה 276: | ||
options['qualifiers-sep'] = options['qualifiers-sep'] or ', ' | options['qualifiers-sep'] = options['qualifiers-sep'] or ', ' | ||
options['img-width'] = options['img-width'] or '250px' | options['img-width'] = options['img-width'] or '250px' | ||
options['source'] = options['source'] or false | |||
local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName) | local propertyVals = mw.wikibase.getBestStatements(entityId, propertyName) | ||
| שורה 301: | שורה 321: | ||
elseif propValue['type'] == 'quantity' then | elseif propValue['type'] == 'quantity' then | ||
local formattedValue = formatQuantity(property) | local formattedValue = formatQuantity(property) | ||
if options['source'] and property.references then | |||
formattedValue = formattedValue.. refStatement(property) | |||
end | |||
if formattedValue then | if formattedValue then | ||
formattedValue = formattedValue .. formatOptionalQualifiers(property, options['qualifiers'], options['qualifiers-sep']) | formattedValue = formattedValue .. formatOptionalQualifiers(property, options['qualifiers'], options['qualifiers-sep']) | ||