יחידה:PropertyLink: הבדלים בין גרסאות בדף

מאין תקציר עריכה
מאין תקציר עריכה
שורה 1: שורה 1:
--[[
Fetch property from wikidata:
* if the entity or the claim doesn't exist - nil
* if the property exist:
- for entity reference - returns link to entity (using sitelink) with label as text, otherwise wikidata label as text
- for string - returns the string
- for quantity - returns the amount
- for time - returns the time as string
- for image - returns image inclusion with 250px size
]]
function getProperty( propertyName )
function getProperty( propertyName )
     local entity = mw.wikibase.getEntityObject()
     local entity = mw.wikibase.getEntityObject()
שורה 7: שורה 17:


     property = property[1]
     property = property[1]
   
     local propValue = property.mainsnak and property.mainsnak.datavalue
     local propValue = property.mainsnak and property.mainsnak.datavalue
     if not propValue then return end --property doesnt exist
     if not propValue then return end --property doesnt exist
 
local isImage = (property.mainsnak.datatype=='commonsMedia')
     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'] )
שורה 16: שורה 27:
             or linkTitle
             or linkTitle
     elseif propValue['type'] == 'string' then
     elseif propValue['type'] == 'string' then
    if isImage then
    return mw.ustring.format( '[[File:%s|250px]]', propValue.value )
    end
     return propValue.value  
     return propValue.value  
     elseif propValue['type'] == 'quantity' then
     elseif propValue['type'] == 'quantity' then