Module:File

-- local p = {}

local data = mw.loadData('Module:File/data') local cData = mw.loadData('Module:Cite/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 :done end

local template_map = { artwork = function(subject, info, ext, args) local t = args[1] local author local source if t == 'twitter' then local handle = args[2] if cData.twitter[handle] then author = cData.twitter[handle] else author = handle end source = table.concat({               'handle,                '/status/',                args[3,                ' Twitter]'            }) end return { author = author, description = args.description or { 'Artwork of ',               subject,                '.' },           source = source }   end, attack = function(subject, info, ext, args) local name = '' if ext == 'gif' then name = 'animation' elseif ext == 'png' then name = 'screenshot' end return { description = args.description or { '',               subject,                '\'s ', info, ' attack ', name, '.'           },            license     = 'fairuse' }   end, battle = function(subject, info, ext, args) return { description = args.description or { '',               subject,                '\'s ', info, (info ==  and  or ' '), 'battle ', (ext == 'gif' and 'animation' or 'sprite'), '.'           },            filename    = args[1] or args.filename, license    = 'fairuse' }   end, face = function(subject, info, _, args) local desc = { '',           subject,            '\'s ' }       if info == 'shop' then table.insert(desc, 'shop graphic') elseif info == 'partymenu' then table.insert(desc, 'party menu graphic') elseif info == 'battlemenu' then table.insert(desc, 'battle menu graphic') else if info ~= '' then table.insert(desc, info) table.insert(desc, ' ') end table.insert(desc, 'face graphic') end table.insert(desc, '.') return { description = args.description or desc, filename   = args[1] or args.filename, license    = 'fairuse' }   end, item = function(subject, info, _, args) return { description = args.description or { '',               subject,                '\'s ', info, (info ==  and  or ' '), 'item sprite/location.' },           filename    = args[1] or args.filename, license    = 'fairuse' }   end, location = function(subject, _, __, args) return { description = args.description or { 'Screenshot depicting ',               subject,                '.' },           license     = 'fairuse' }   end, map = function(subject, info, _, args) return { description = args.description or { 'Map of ',               subject,                '', (info ==  and  or '\'s '), info, '.'           }        }    end, overworld = function(subject, info, ext, args) local desc = { '',           subject,            '\'s ' }       if info == 'darkworld' then table.insert(desc, 'Dark World') else if info ~= '' then table.insert(desc, info) table.insert(desc, ' ') end table.insert(desc, 'overworld') end table.insert(desc, ' ') table.insert(desc, ext == 'gif' and 'animation' or 'sprite') table.insert(desc, '.') return { description = args.description or desc, filename   = args[1] or args.filename, license    = 'fairuse' }   end, screenshot = function(subject, _, __, args) return { description = args[1] or args.description or {'Screenshot of ', subject, '.'}, license    = 'fairuse' }   end }

local function template(args) local ext local noext = {} for _, v in ipairs(mw.text.split(title.text, '.', true)) do       if ext then if noext[1] then table.insert(noext, '.') end table.insert(noext, ext) end ext = v   end noext = table.concat(noext) for t, dt in pairs(data.types) do       local spl = mw.text.split(noext, table.concat({'%s', t})) if spl[2] then -- Found file type args.type = t           if template_map[t] then local mapped = template_map[t](mw.text.trim(spl[1]), mw.text.trim(spl[2]), ext, args) for k, v in pairs(mapped) do                   args[k] = v                end end if type(args.description) == 'table' then args.description = table.concat(args.description) end break end end return args end

function p.main(frame) local args = template(frame:getParent.args) local t = args.type or 'misc' local isfile = title.namespace == 6 local html = mw.html.create('table') :attr('class', 'wikitable') :attr('data-template', 'file') if args.description then makeRow(html, 'Description', args.description) end if args.notes then makeRow(html, 'Notes', args.notes) end local res = {} for _, value in ipairs(mw.text.split(t, ',', true)) do       local typedata = data.types[mw.text.trim(value)] if typedata then table.insert(res, '\n* ') table.insert(res, typedata.name) if isfile and typedata.category then table.insert(res, '[[Category:')               table.insert(res, typedata.category)                table.insert(res, ']]') end end end if isfile and args.interface then table.insert(res, '[[Media:')       table.insert(res, title.text)        table.insert(res, '| ]]') end makeRow(html, 'Type', table.concat(res)) makeRow(html, 'Source', args.source or '\'\'Deltarune\'\'') if args.filename then makeRow(html, 'In-game name', args.filename) end makeRow(html, 'Author', args.author or 'Toby Fox') makeRow(html, 'Licensing', table.concat({ 'This file ', data.license[args.license or 'default'] or data.license.default, '.'   }))    if args.issues then makeRow(html, 'Quality issues', table.concat({ 'This file ', args.issues or 'has bad quality', '. You can help the ', mw.site.siteName, ' by uploading a new version.', title.namespace == 6 and  or  }))   end return tostring(html) end

return p