Zum Inhalt springen

Modul:PropertyLink: Unterschied zwischen den Versionen

keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Keine Bearbeitungszusammenfassung
Zeile 1: Zeile 1:
function getProperty( propertyName )
function getLinkLabel(propValue)
    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 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
Zeile 22: Zeile 15:
         return linkTarget and linkTitle and mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle )
         return linkTarget and linkTitle and mw.ustring.format( "[[%s|%s]]", linkTarget, linkTitle )
             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
end
 
function getProperty( propertyName )
    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)
end
end
   
   
Zeile 46: Zeile 53:
end
end


function getLabels( frame )
function getLinkLabels( frame )
propertyName = frame.args[1]
propertyName = frame.args[1]
     local entity = mw.wikibase.getEntityObject()
     local entity = mw.wikibase.getEntityObject()
Zeile 59: Zeile 66:
if not propValue then return '' end --property doesnt exist
if not propValue then return '' end --property doesnt exist


local value
local value = getLinkLabel(propValue)
if propValue['type']=='wikibase-entityid' then
value = mw.wikibase.label( "Q" ..propValue.value['numeric-id'] )
elseif propValue['type'] == 'string' then
value = propValue.value
end
if retVal == '' then
if retVal == '' then
retVal = value
retVal = value
Zeile 107: Zeile 108:
     getImageLink = getImageLink,
     getImageLink = getImageLink,
     getLabel = getLabel,
     getLabel = getLabel,
     getLabels = getLabels,
     getLinkLabels = getLinkLabels,
}
}
11.008

Bearbeitungen

Cookies helfen uns bei der Bereitstellung von Android Wiki. Durch die Nutzung von Android Wiki erklärst du dich damit einverstanden, dass wir Cookies speichern.