Aller au contenu

Module:Commons tab

Une page de Wikipédia, l'encyclopédie libre.

 Documentation[créer] [purger]
local p = {}

function p.getData(frame)
	local args = frame.args
	
	local filename =  args[1]
	local datatable = mw.ext.data.get(filename)
	if not datatable then return nil end
	
	local selectname, selectvalue, selectindex, resultindex, resultname, resultvalue
	selectname = args[2]
	selectvalue = args[3]
	resultname = args[4]
	
	for j,field in ipairs(datatable.schema.fields) do
		if field.name == selectname then
			selectindex = j
			if resultindex then break end
		end
		if field.name == resultname then
			resultindex = j
			if selectindex then break end
		end
	end
	
	if selectindex and resultindex then
		for i,row in ipairs(datatable.data) do
			if tostring(row[selectindex]) == selectvalue then
				resultvalue = tostring(row[resultindex])
				break
			end
		end
	end
	
	return resultvalue
end
 
return p