Modul:WikidataCommonscat: Forskjell mellom sideversjoner

Fra Wikisida.no
Hopp til navigering Hopp til søk
(test)
Ingen redigeringsforklaring
Linje 55: Linje 55:
if commonscat then
if commonscat then
if commonscat == "" then
if commonscat == "" then
return p.wikidatacommonscat(frame)
return p.wikidatacommonscat(frame) .. "1"
else
else
return commonscat
return commonscat .. "2"
end
end
else
else
p.wikidatacommonscat(frame)
return p.wikidatacommonscat(frame) .. "3"
end
end


return p.wikidatacommonscat(frame)
return p.wikidatacommonscat(frame) .. "4"
end
end



Sideversjonen fra 10. mai 2013 kl. 18:38

Modul som brukes av {{Commonscat fra Wikidata}}


local p = {}

function dump( out )
    if type( out ) == 'table' then
        local s = '{ '
        for k,v in pairs( out ) do
                if type( k ) ~= 'number' then k = '"'..k..'"' end
                s = s .. '['..k..'] = ' .. dump( v ) .. ','
        end
        return s .. '} '
    else
        return tostring( out )
    end
end

-- Return bilde til artikkelen
function p.wikidatacommonscat(frame)
    if not mw.wikibase then
        return ""
    end
    local artikkel = mw.wikibase.getEntity()
    if not artikkel then
        return ""
    end
    local claims = artikkel.claims
    dump (claims)
    if not claims then
        return ""
    end
    local P373 = claims.P373
    if not P373 then
        return ""
    end

    return P373[0].mainsnak.datavalue.value
end

function p.framecommonscat(frame)
    local args = frame.args
    if args[1] == nil then
        local pFrame = frame:getParent();
        args = pFrame.args;
        for k,v in pairs( frame.args ) do
            args[k] = v;
        end
     end
     if args['comcat'] then
        return args['comcat']
     end
     return ""
end

function p.velgcommonscat(frame)
    local commonscat = p.framecommonscat(frame)
    if commonscat then
        if commonscat == "" then
            return p.wikidatacommonscat(frame) .. "1"
        else
           return commonscat .. "2"
        end
    else
        return p.wikidatacommonscat(frame) .. "3"
    end

    return p.wikidatacommonscat(frame) .. "4"
end

return p