Module:WikidataRéférence

 Documentation[créer] [purger]
function p.setRef( args )
	local str = ''
    if args.name and args.name ~= '' then
    	str = str .. '|nom = ' .. args.name
    elseif args.date and args.date ~= '' then
    	str = str .. '|date = '	.. args.date
    end
end

function p.extractData( ref, data)
	
    for prop, content in pairs(ref) do
	    if prop == 'p304' and not data.passage or data.passage == '' then
	    	data.passage = p.getDataValue( ref.p304 )
	    elseif prop == 'p792' or data.chapter == '' then
	    	data.chapter = p.getDataValue( ref.p792 )
	    elseif prop == 'p433' or data.issue == '' then
	    	data.issue = p.getDataValue( ref.p433 )
	    elseif prop == 'p478' or data.volume == '' then
	    	data.volume = p.getDataValue( ref.p478 )
	    elseif prop == 'p393' or data.editionNumber == '' then
	    	data.editionNumber = p.getDataValue( ref.p393 )
	    elseif prop == 'p356' or data.DOI == '' then
	    	data.DOI = p.getDataValue( ref.p356 )
	    end
    end
	return data
end

function p.getDataValue( snak )

    if snak.snaktype ~= 'value' then 
	    return nil
	end
	
	datatype = snak.datavalue.type
 
	if datatype == 'wikibase-entityid' then
	    if formatting == 'raw' then 
		    return "Q" .. tostring(snak.datavalue.value['numeric-id'])
	    else
		    return p.formatEntityId("Q" .. tostring(snak.datavalue.value['numeric-id']), formatting)
	    end
	elseif datatype == 'string' then
	    return snak.datavalue.value
	elseif datatype == 'time' then -- format example: +00000001809-02-12T00:00:00Z
	    return p.formatTimevalue(snak.datavalue.value, formatting)
	elseif datatype == 'url' then
        return snak.datavalue.value['url']
	elseif datatype == 'quantity' then
	    return snak.datavalue.value['amount']
	end

end

local p = {}

data = {}



return p