Jump to content

Module:PropertyLink: Difference between revisions

m
18 revisions imported
(Nutze enwiki oder dewiki Link, wenn verfügbar)
 
m (18 revisions imported)
 
(10 intermediate revisions by the same user not shown)
Line 1: Line 1:
function getProperty( propertyName )
function getLinkLabel(propValue, frame)
    local entity = mw.wikibase.getEntityObject()
if propValue['type'] == 'wikibase-entityid' then
    if not entity or not entity.claims then return end--the entity doesnt exist or have no claims
local isWikipedia = false
    local property = entity.claims[propertyName]
    if not property then return end--no such property for this item
    property = property[1]
    local propValue = property.mainsnak and property.mainsnak.datavalue
    if not propValue then return end --property doesnt exist
    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'] )
         if not linkTarget then
         if not linkTarget then
Line 13: Line 7:
         if targetEntity and targetEntity['sitelinks'] then
         if targetEntity and targetEntity['sitelinks'] then
         if targetEntity['sitelinks']['dewiki'] then
         if targetEntity['sitelinks']['dewiki'] then
         linkTarget = 'wikipedia:de:' .. targetEntity['sitelinks']['dewiki']['title']
         linkTarget = string.gsub('de:' .. targetEntity['sitelinks']['dewiki']['title'], ' ', '_')
        isWikipedia = true
         elseif targetEntity['sitelinks']['enwiki'] then
         elseif targetEntity['sitelinks']['enwiki'] then
         linkTarget = 'wikipedia:' .. targetEntity['sitelinks']['enwiki']['title']
         linkTarget = string.gsub(targetEntity['sitelinks']['enwiki']['title'], ' ', '_')
        isWikipedia = true
     end
     end
end
end
    end
end
         local linkTitle = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] )
         local linkTitle = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] )
         return linkTarget and linkTitle and mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle )
          
             or linkTitle
        if isWikipedia then
     elseif propValue and propValue['type'] == 'string' then return propValue.value end
        template = "{{WikipediaLink|%s|%s}}"
        end
        if linkTarget and linkTitle then
        if isWikipedia then
        return frame:expandTemplate{ title = 'WikipediaLink', args = { linkTarget, linkTitle } }
        end
        return mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle )
        else
             return linkTitle
        end
     elseif propValue and propValue['type'] == 'string' then
    return propValue.value
    end
end
 
function getProperty(propertyName, frame)
    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 propValue = property.mainsnak and property.mainsnak.datavalue
    if not propValue then return end --property doesnt exist
 
return getLinkLabel(propValue, frame)
end
end
   
   
function property( frame )
function property( frame )
     return getProperty(string.upper(frame.args[1]))
     return getProperty(string.upper(frame.args[1], frame), frame)
end
end
 
function getLabel( propertyName )
function getLabel( propertyName )
     local entity = mw.wikibase.getEntity()
     local entity = mw.wikibase.getEntity()
Line 45: Line 65:
     end
     end
end
end
function getLinkLabels( frame )
propertyName = frame.args[1]
    local entity = mw.wikibase.getEntityObject()
    if not entity or not entity.claims then return end--the entity doesnt exist or have no claims
    local properties = entity.claims[propertyName]
    if not properties then return end--no such property for this item
   
   
    local retVal = ''
    for propIndex in pairs(properties) do
    local property = properties[propIndex]
local propValue = property.mainsnak.datavalue
if not propValue then return '' end --property doesnt exist
local value = getLinkLabel(propValue, frame)
if retVal == '' then
retVal = value
else
retVal = retVal .. ', ' .. value
end
end
return retVal
end
-- Return the label for property, or the label of the linked entiy of that property
-- Return the label for property, or the label of the linked entiy of that property
function label( frame )
function label( frame )
     return getLabel( string.lower(frame.args[1] ))
     return getLabel(string.lower(frame.args[1]))
end
end


Line 76: Line 120:
     getProperty = getProperty,
     getProperty = getProperty,
     getImageLink = getImageLink,
     getImageLink = getImageLink,
     getLabel = getLabel
     getLabel = getLabel,
    getLinkLabels = getLinkLabels,
}
}
11,008

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.