Jump to content

Module:HenkvD/WBHacks

Unchecked
From Wikipedia

Documentation for this module may be created at Module:HenkvD/WBHacks/doc

JSON = require('Module:HenkvD/JSON')
local p = {}
 
 function p.get( id )
    --this just returns the json object of the id
    local id = id
    if string.find(id, "P") ~= nil then
        if string.find(id, "Property") == nil then
            id = "Property:" .. id
        end
    end
    local pg = mw.title.new(id)
    return JSON:decode(pg:getContent())
end

function p.thing(obj, typ, lang)
    -- Can be used to fetch either label or description, depends on what you want.
    local x = obj[typ][lang]
    if x == nil then
        x = obj[typ].en -- fallback to english
    end
    return x
end

function p.label(frame)
    local pframe = frame:getParent()
    local config = frame.args
    local args = pframe.args
 
    local qid = config.qid
    local lang = config.lang
    local obj = p.get(qid)
    return p.thing(obj, "label", lang)

end
 
 function p.description(frame)
    local pframe = frame:getParent()
    local config = frame.args
    local args = pframe.args
 
    local qid = config.qid
    local lang = config.lang
    local obj = p.get(qid)
    return p.thing(obj, "description", lang)

end

 function p.datatype(frame)
    local pframe = frame:getParent()
    local config = frame.args
    local args = pframe.args
 
    local qid = config.qid
    local obj = p.get(qid)
    return obj["datatype"]

end

return p