Module:File

-- local p = {}

local data = mw.loadData('Module:File/data')

local title = mw.title.getCurrentTitle

local function makeRow(html, title, content) html:tag('tr') :tag('th') :wikitext(title) :done :tag('td') :wikitext(content) :done end

local function category(name) if title.namespace == 6 then return '' else return '' end end

local function template(args) local t = mw.ustring.lower(args[1]) local name = mw.text.split(mw.text.split(title.text, '.', true)[1], ' ', true)[1] if t == 'e-s' or t == 'example-screenshot' then args.author = nil args.description = 'This file is used as an example screenshot for the ' .. name .. ' article.' if args[2] then args.description = args.description .. ' ' .. args[2] end args.license = 'fscreen' if args[3] then args.source = args[3] end args.type = 'example, screenshot' end return args end

function p.main(frame) local args = frame:getParent.args if args[1] then args = template(args) end local html = mw.html.create('table'):attr('class', 'wikitable') if args.description then makeRow(html, 'Description', args.description) end if args.notes then makeRow(html, 'Notes', args.notes) end if args.type then local res = '' for key, value in ipairs(mw.text.split(args.type, ',')) do           value = mw.text.trim(value) local filetype = data.types[value] local cat = data.categories[value] if filetype and category then res = res .. '\n* ' .. filetype .. category(cat) end if value == 'important' then res = '[[Media:' .. title.text .. '| ]]' .. res end end makeRow(html, 'Type', res) end makeRow(html, 'Source', args.source or '\'\'Unknown\'\'') if args.author then makeRow(html, 'Author', args.author) end makeRow(html, 'Licensing', 'This file ' .. (data.license[args.license or 'default'] or data.license.default) .. '.') return tostring(html) end

return p