Module:Commons tab
Apparence
La documentation de ce module est générée par le modèle {{Documentation module}}.
Les éditeurs peuvent travailler dans le bac à sable (créer).
Voir les statistiques d'appel depuis le wikicode sur l'outil wstat et les appels depuis d'autres modules.
local p = {}
function p.getData(frame)
local args = frame.args
local filename = args[1]
local datatable = mw.ext.data.get(filename)
local showerror = args.showerror and string.lower(args.showerror) ~= "false"
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
if selectindex then
if showerror then error('Table has several columns with the selection name') end
else
selectindex = j
if resultindex and not showerror then break end
end
end
if field.name == resultname then
if resultindex then
if showerror then error('Table has several columns with the result name') end
else
resultindex = j
if selectindex and not showerror then break end
end
end
end
if showerror and not selectindex then error('Table has no column with the selection name') end
if showerror and not resultindex then error('Table has no column with the result name') end
if selectindex and resultindex then
for i,row in ipairs(datatable.data) do
if tostring(row[selectindex]) == selectvalue then
if resultvalue then
if showerror then error('Table has several rows with the selection value') end
else
resultvalue = tostring(row[resultindex])
if not showerror then break end
end
end
end
if showerror and not resultvalue then error('Table has no row with the selection value') end
end
return resultvalue
end
return p