Modul:Commons
Ausgesinn
local p={}
function p.getTab(frame)
local s=""
local object=frame.args.object
if object then
if string.sub(object,-4)~=".tab"then
object=object..".tab"
end
local lang=frame.args.lang
local t=lang and mw.ext.data.get(object,lang)or mw.ext.data.get(object)
if t and type(t)==type({})then
local info=string.lower(frame.args.info or"")
local fields=string.lower(frame.args.fields or"")
if info~="" then
if info=="license"then
s=t.license and t.license[fields] or""
elseif info=="description"then
s=t.description or""
elseif info=="sources"then
s=t.sources or""
end
elseif fields~="" and t.schema and t.schema.fields then
if fields=="type"then
s="{| class=\"wikitable\"\n|-\n"
for i,v in ipairs(t.schema.fields)do
s=s.."! "..v.type.."\n"
end
s=s.."|}"
elseif({["name"]=t,["title"]=t})[fields]then
local index=tonumber(frame.args.index)
local tName=mw.text.split(
frame.args.fieldnames or""," ",true
)
local tField={}
for i,s in ipairs(tName)do
for i,t in ipairs(t.schema.fields)do
if t.name==s then
tField[#tField+1]=i
break
end
end
end
if #tField<1 then
for i,t in ipairs(t.schema.fields)do
tField[i]=i
end
end
s="{| class=\"wikitable\"\n|-\n"
for i,v in ipairs(tField)do
s=s.."! "..t.schema.fields[v][fields].."\n"
end
if t.data then
for i,v in ipairs(t.data)do
if(not index)or index==i then
s=s.."|-\n"
for i,n in ipairs(tField)do
s=s.."| "..v[n].."\n"
end
end
end
end
s=s.."|}"
end
end
end
end
return s
end
function p.testData(frame)
local s=""
local object=frame.args.object
local lang=frame.args.lang
local t=object and(lang and mw.ext.data.get(object,lang)or mw.ext.data.get(object))
for i,v in ipairs(frame.args)do
if type(t)~=type({})then
break
end
t=t[v]or t[tonumber(v)]
end
if type(t)==type({})then
for i,v in pairs(t)do
s=s.."* "..tostring(i)..": "..tostring(v).."\n"
end
elseif type(t)==type("")then
s=string.format("%q",t)
else
s=tostring(t)
end
return s
end
function p.testMwExt(frame)
local s=""
local t=mw.ext
for i,v in ipairs(frame.args)do
if type(t)~=type({})then
break
end
t=t[v]or t[tonumber(v)]
end
if type(t)==type({})then
for i,v in pairs(t)do
s=s.."* "..tostring(i)..": "..tostring(v).."\n"
end
elseif type(t)==type("")then
s=string.format("%q",t)
else
s=tostring(t)
end
return s
end
return p