Hopp til innhold

Modul:WikidataBirthYear

Fra Wikipedia, den frie encyklopedi
Moduldokumentasjon
local p = {}
local mw = require("mw")

function p.getBirthYear(frame)
    local entity = mw.wikibase.getEntityObject()
    
    -- If the page is not connected to Wikidata
    if not entity then
        return ""
    end

    -- Check if the entity has a birth date (P569)
    if entity.claims and entity.claims["P569"] then
        local dob = entity.claims["P569"][1].mainsnak.datavalue.value.time
        local year = string.sub(dob, 2, 5) -- Extract YYYY
        if tonumber(year) then
            return year
        end
    end

    -- If no birth date is found, return a message and add a category
    return "Birth year not available [[Kategori:Sider uten fødselsår på Wikidata]]"
end

return p