You can edit almost every page by Creating an account. Otherwise, see the FAQ.

Modul:WikidataBilde

Fra EverybodyWiki Bios & Wiki
Hopp til:navigasjon, søk

Dokumentasjon for denne modulen kan opprettes på Modul:WikidataBilde/dok

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

local kategori = {[5] = "biografi" }
local resten = "[[Kategori:Artikler hvor bilde er hentet fra Wikidata]]"

function finnKategori(frame)
   if not mw.wikibase then
        return resten
    end
    local artikkel = mw.wikibase.getEntityObject()
    if not artikkel then
        return resten
    end
    local claims = artikkel:getBestStatements( 'P31' )
    if not claims then
        return resten
    end
    for _,v in ipairs( claims ) do
    	if v.type == 'statement' then
    		local snak = v.mainsnak
    		if snak.snaktype == 'value' then
    			if snak.datatype == 'wikibase-item' then
    				local data = snak.datavalue
    				if data.type == 'wikibase-entityid' then
    					local value = data.value
    					if value["entity-type"] == "item" then
    						if kategori[value["numeric-id"]] then
    							return "[[Kategori:Artikler hvor bilde er hentet fra Wikidata - " .. kategori[value["numeric-id"]] .. "]]"
    						end
						end
					end
				end
			end
		end
	end

    -- failed to find correct type
	return resten
end

-- Return bilde til artikkelen
function p.wikidatabilde(frame)
    if not mw.wikibase then
        return ""
    end
    local artikkel = mw.wikibase.getEntityObject()
    if not artikkel then
        return ""
    end
    local claims = artikkel:getBestStatements( 'P18' )
    if not claims then
        return ""
    end
    for _,v in ipairs( claims ) do
    	if v.type == 'statement' then
    		local snak = v.mainsnak
    		if snak.snaktype == 'value' then
    			if snak.datatype == 'commonsMedia' then
    				local data = snak.datavalue
    				if data.type == 'string' then
    					return data.value
					end
				end
			end
		end
	end
	
    -- failed to find correct type
    return ""
end

function p.framebilde(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['bilde'] then
        return args['bilde']
     end
     return ""
end

function p.framekart(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['kart'] then
        return args['kart']
     end
     return ""
end

function p.velgbilde(frame)
    local bilde = p.framebilde(frame)
    if bilde then
        if bilde == "" then
--            return ""
        elseif bilde == "uten" then
    	   return ""
        else
           return bilde
        end
    else
        return ""
    end
    local frawikidata = p.wikidatabilde(frame)
    local framekart = p.framekart(frame)
    if framekart == frawikidata then
    	return ""
    end

    return frawikidata
end

function p.bildetekst(frame)
    
    if not mw.wikibase then
        return ''
    end
    local artikkel = mw.wikibase.getEntityObject()
    if not artikkel then
        return ''
    end
    local claims = artikkel:getBestStatements( 'P18' )
    if not claims then
        return ''
    end
    for _,v in ipairs( claims ) do
    	if v.type == 'statement' then
    		local snak = v.mainsnak
    		if snak.snaktype == 'value' then
    			if snak.datatype == 'commonsMedia' then
    				local data = snak.datavalue
    				if data.type == 'string' then
						local q	= v.qualifiers
						if q then
							wdcaptions = q['P2096']
						end
						if wdcaptions then
							for k, l in pairs(wdcaptions) do
								if l.datavalue.value and l.datavalue.value.text and l.datavalue.value.language == 'nb' then
									return l.datavalue.value.text
								end
							end
						end
					end
				end
			end
		end
	end
	
    -- failed to find correct type
    return ''

end
 
function p.sammenlignbilde(frame)
    local fraframe = p.framebilde(frame)
    local frawikidata = p.wikidatabilde(frame)
    if fraframe == frawikidata then
        if fraframe == "" then
            return ""
        else
            return "[[Kategori:Artikler hvor bilde er samme som på Wikidata]]"
        end
    else
        if frawikidata == "" then
            return "[[Kategori:Artikler hvor bilde mangler på Wikidata]]"
        end
        if fraframe == "" then
            return "[[Kategori:Artikler uten bilde i infoboks med bilde på Wikidata]]"
        end
        return "[[Kategori:Artikler med bilde forskjellig fra Wikidata]]"
    end
end

function p.sammenlignMedWikidataValgtBilde(frame)
    local fraframe = p.framebilde(frame)
    local frawikidata = p.wikidatabilde(frame)
    local framekart = p.framekart(frame)
    if fraframe == frawikidata then
        if fraframe == "" then
            return ""
        else
            return 
        end
    else 
        if frawikidata == "" then
            return "[[Kategori:Artikler hvor bilde mangler på Wikidata]]"
        end
    	if framekart == frawikidata then
    		return "[[Kategori:Artikler hvor kart er samme som bilde på Wikidata]]"
    	end
        if fraframe == "" then
            return finnKategori(frame)
        end
        return "[[Kategori:Artikler med bilde forskjellig fra Wikidata]]"
    end
end

return p

This module "WikidataBilde" is from Wikipedia if otherwise notified