Zum Inhalt springen

Modul:Basic/Sandkasten

Aus Wikivoyage

Die Dokumentation für dieses Modul kann unter Modul:Basic/Sandkasten/Doku erstellt werden

local p = {}
local entity = mw.wikibase.getEntity()

function p.id(frame)
    if entity ~= nil then
        return entity.id
    end
end

function p.commonscat(frame)
    local catname = mw.text.trim(frame.args[1]) -- catname could be empty
    if (entity ~= nil) and (entity.claims ~= nil) and (entity.claims.p373 ~= nil) then
        catname = entity.claims.p373[0].mainsnak.datavalue.value
    end
    if catname ~="" then
        return table.concat({"[[Commons:Category:", catname, "]]"}, "")
    end
end

function p.commons(frame)
    local articlename = mw.text.trim(frame.args[1])
    if (entity ~= nil) and (entity.sitelinks ~= nil) and (entity.sitelinks.commonswiki ~= nil) then
        articlename = entity.sitelinks.commonswiki.title
    end
    if articlename ~= "" then
        return table.concat({"[[Commons:", articlename, "]]"}, "")
    end
end

function p.dewiki(frame)
    local articlename = mw.text.trim(frame.args[1])
    if (entity ~= nil) and (entity.sitelinks ~= nil) and (entity.sitelinks.dewiki ~= nil) then
        articlename = entity.sitelinks.dewiki.title
    end
    if articlename ~= "" then
        return table.concat({"[[wikipedia:de:", articlename, "]]"}, "")
    end
end

function p.desource(frame)
    local articlename = mw.text.trim(frame.args[1])
    if (entity ~= nil) and (entity.sitelinks ~= nil) and (entity.sitelinks.desource ~= nil) then
        articlename = entity.sitelinks.desource.title
    end
    if articlename ~= "" then
        return table.concat({"[[wikisource:de:", articlename, "]]"}, "")
    end
end

function p.latitude(frame)
    if (entity ~= nil) and (entity.claims ~= nil) and (entity.claims.p625 ~= nil) then
        return entity.claims.p625[0].mainsnak.datavalue.value.latitude
    end
end

function p.longitude(frame)
    if (entity ~= nil) and (entity.claims ~= nil) and (entity.claims.p625 ~= nil) then
        return entity.claims.p625[0].mainsnak.datavalue.value.longitude
    end
end

return p