Módulo:File
Erro em Lua em package.lua na linha 80: module 'Dev:Docbunto' not found.
--- Our file description formatter and autocategorization dispatcher.
-- It attempts to determine the file type from the file's title and deduces
-- a bunch of other stuff from it. Depending on the file type, file description
-- fields are autogenerated but may be overriden by template arguments.
-- @module file
-- @alias p
-- @require Module:Yesno
-- @require Module:Cite/data
-- @author [[User:KockaAdmiralac|KockaAdmiralac]]
-- @author [[User:Jacky720|Jacky720]]
-- <nowiki>
local p = {}
-- Module dependencies.
local yesno = require('Module:Yesno')
local data = mw.loadData('Module:File/data')
local cData = mw.loadData('Module:Cite/data')
-- Module variables.
local title = mw.title.getCurrentTitle()
-- Private logic.
--- Makes a table row with one <th> and one <td>.
-- @function makeRow
-- @param {mw.html} html HTML to append the row to
-- @param {string} title Contents of the <th>
-- @param {string} content Contents of the <td>
-- @param {string|nil} id ID on the <th> (for metadata)
-- @returns {mw.html} HTML with appended row
-- @local
local function makeRow(html, title, content, id)
local tr = html:tag('tr')
local th = tr:tag('th'):wikitext(title)
if id ~= nil then
th:attr('id', id)
end
th:done()
tr:tag('td')
:wikitext(content)
:done()
:done()
end
--- Turns "<number>" or "<description> <number>" into "<position>" or
-- "<position> <description>" (e.g. "shattered 2" → "second shattered").
-- @function number
-- @param {string} info String to convert
-- @returns {string} String converted in the above manner
-- @local
local function number(info)
local numberedinfo = {''}
if info ~= '' then
-- shattered 2 => second shattered
local number_match = mw.ustring.match(info, '%d+$')
if number_match then
local number = tonumber(number_match)
table.insert(numberedinfo, data.numbering[number])
table.insert(numberedinfo, ' ')
local replaced_info = mw.ustring.gsub(info, ' ?%d+$', '')
table.insert(numberedinfo, replaced_info)
else
table.insert(numberedinfo, info)
end
table.insert(numberedinfo, ' ')
end
return table.concat(numberedinfo)
end
--- Maps file types into functions that deduce their descriptions based on
-- a variety of arguments.
-- @table template_map
local template_map = {}
--- Formats an artwork file's description.
-- First expected argument is the source type. Currently supported types are:
-- * <code>twitter</code>: the artwork is from Twitter
-- Expected arguments (after the first) for the <code>twitter</code> type are:
-- # Artist's Twitter handle
-- # Twitter snowflake
--
-- Expected arguments (after the first) for the <code>artbook</code> type are:
-- # Artist's page on the wiki (artist's name)
-- # Page in the artbook
-- # Name of the file in the artbook.
--
-- No matter the file type, the last argument is always the description of the
-- file, if the autogenerated description does not suffice.
-- @function template_map.artwork
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.artwork(subject, info, __, args)
local author
local source
local filename
local description
if args[1] == 'twitter' then
local handle = args[2]
if cData.twitter[handle] then
author = cData.twitter[handle]
else
author = handle
end
source = table.concat({
'[https://twitter.com/',
handle,
'/status/',
args[3],
' Twitter]'
})
description = args[4]
elseif args[1] == 'artbook' then
source = table.concat({
'\'\'[[',
data.game,
']]\'\' artbook, page ',
args[3]
})
author = args[2]
filename = args[4]
description = args[5]
end
return {
author = author,
description = description or {
'[[',
subject,
']]\'s ',
number(info),
' artwork.'
},
source = source,
filename = filename,
license = 'fairuse'
}
end
--- Formats an attack file's description.
-- @function template_map.attack
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.attack(subject, info, ext, args)
return {
description = {
'[[',
subject,
']]\'s ',
info,
' attack ',
(ext == 'gif' and 'animation' or 'screenshot'),
'.'
},
filename = args[1],
license = 'fairuse'
}
end
--- Formats an avatar's description.
-- Expected arguments are:
-- # Source of the avatar
-- # Artist behind the avatar
-- @function template_map.avatar
-- @param {string} subject Part of the filename before the type
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.avatar(subject, _, _, args)
return {
author = args[2],
description = {
'[[Developers#',
subject,
'|',
subject,
']]\'s avatar.'
},
source = args[1]
}
end
--- Formats a battle sprite file's description.
-- Expected arguments are:
-- # In-game filename of the sprite file
-- @function template_map.battle
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.battle(subject, info, ext, args)
return {
description = {
'[[',
subject,
']]\'s ',
number(info),
(info == '' and '' or ' '),
'battle ',
(ext == 'gif' and 'animation' or 'sprite'),
'.'
},
filename = args[1],
license = 'fairuse'
}
end
--- Formats a cover artwork file's description.
-- Expected arguments are:
-- # Source of the file
-- # Author of the file
-- @function template_map.cover
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.cover(subject, info, _, args)
return {
description = {
'\'\'[[',
subject,
']]\'\'\'s ',
info,
(info == '' and '' or ' '),
'cover.'
},
source = args[1],
author = args[2],
license = 'fairuse'
}
end
--- Formats a face graphic file's description.
-- Expected arguments are:
-- # In-game filename of the face graphic
-- @function template_map.face
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.face(subject, info, _, args)
local desc = {
'[[',
subject,
']]\'s '
}
if info == 'shop' then
table.insert(desc, 'shop')
elseif info == 'partymenu' then
table.insert(desc, 'party menu')
elseif info == 'battlemenu' then
table.insert(desc, 'battle menu')
else
table.insert(desc, number(info))
table.insert(desc, 'face')
end
table.insert(desc, ' graphic.')
return {
description = desc,
filename = args[1],
license = 'fairuse'
}
end
--- Formats an icon file's description.
-- @function template_map.icon
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.icon(subject, info)
return {
description = {
'An icon of [[',
subject,
']]',
(info == '' and '' or ', '),
info,
'.'
},
license = 'fairuse'
}
end
--- Formats an item sprite file's description.
-- Expected arguments are:
-- # In-game filename of the item sprite
-- @function template_map.item
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.item(subject, info, _, args)
return {
description = {
'[[',
subject,
']]\'s ',
info,
(info == '' and '' or ' '),
'item sprite/location.'
},
filename = args[1],
license = 'fairuse'
}
end
--- Formats a leitmotif file's description.
-- @function template_map.leitmotif
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.leitmotif(subject, info)
return {
description = {
'Sheet music for [[',
subject,
']]\'s',
(info == '' and '' or ' '),
info,
' [[Leitmotifs#',
subject,
'|leitmotif]].'
},
license = 'ccbysa'
}
end
--- Formats a location file's description.
-- Expected arguments are:
-- # File description if the autogenerated one isn't fitting
-- @function template_map.location
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.location(subject, _, __, args)
return {
description = args[1] or {
'Screenshot depicting [[',
subject,
']].'
},
license = 'fairuse'
}
end
--- Formats a logo file's description.
-- Expected arguments are:
-- # File description if the autogenerated one isn't fitting
-- # Source for the logo.
-- # Author of the logo.
-- @function template_map.location
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.logo(subject, _, __, args)
return {
description = args[1] or {
'Logo of ',
subject,
'.'
},
source = args[2],
author = args[3] or '[[Toby Fox]]',
license = 'fairuse'
}
end
--- Formats a map file's description.
-- Expected arguments are:
-- # File description if the autogenerated one isn't fitting
-- @function template_map.map
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.map(subject, info, _, args)
return {
description = args[1] or {
'Map of [[',
subject,
']]',
(info == '' and '' or '\'s '),
info,
'.'
},
license = 'fairuse'
}
end
--- Formats a music file's description.
-- Expected arguments are:
-- # In-game filename of the track
-- # Author of the track
-- @function template_map.music
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.music(subject, info, _, args)
return {
author = args[2],
description = {
'The ',
number(info),
'audio file of [[',
subject,
']].'
},
filename = args[1],
license = 'fairuse'
}
end
--- Formats an overworld sprite file's description.
-- Expected arguments are:
-- # In-game filename of the overworld sprite
-- @function template_map.overworld
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.overworld(subject, info, ext, args)
local desc = {
'[[',
subject,
']]\'s '
}
if info == 'darkworld' then
table.insert(desc, '[[Dark World]]')
else
table.insert(desc, number(info))
table.insert(desc, 'overworld')
end
table.insert(desc, ' ')
table.insert(desc, ext == 'gif' and 'animation' or 'sprite')
table.insert(desc, '.')
return {
description = desc,
filename = args[1],
license = 'fairuse'
}
end
--- Formats a photograph's description.
-- Expected arguments are:
-- # File description if the autogenerated one isn't fitting
-- @function template_map.photograph
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.photograph(subject, info, _, args)
return {
description = args[1] or {
'Photograph of [[',
subject,
']]',
(info == '' and '' or '\'s '),
info,
'.'
},
license = 'fairuse'
}
end
--- Formats a screenshot's description.
-- Expected arguments are:
-- # File description if the autogenerated one isn't fitting
-- @function template_map.screenshot
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.screenshot(subject, info, _, args)
return {
description = args[1] or {
'Screenshot of [[',
subject,
']]',
(info == '' and '' or '\'s '),
info,
'.'
},
license = 'fairuse'
}
end
--- Formats a sprite file's description.
-- Expected arguments are:
-- # In-game filename of the sprite
-- @function template_map.screenshot
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.sprite(subject, info, ext, args)
return {
description = {
'[[',
subject,
']]\'s ',
info,
(info == '' and '' or ' '),
(ext == 'gif' and 'animation' or 'sprite'),
'.'
},
filename = args[1],
license = 'fairuse'
}
end
--- Formats a tarot file's description.
-- @function template_map.tarot
-- @param {string} subject Part of the filename before the type
-- @param {string} info Part of the filename after the type
-- @param {string} ext File extension
-- @param {table} args Arguments of the file description template
-- @return {table} Inferred file template arguments
function template_map.tarot(subject, info)
return {
description = {
'[[',
subject,
']]\'s',
(info == '' and '' or ' '),
info,
' tarot card.'
},
license = 'fairuse',
source = '[https://www.fangamer.com/collections/undertale/products/undertale-tarot-cards Fangamer Undertale Tarot Cards]',
author = '[https://dogbomber.tumblr.com/ Dogbomber]'
}
end
template_map.soundtrack = template_map.screenshot
--- Fills existing template arguments with new arguments depending on the type.
-- @function mapper
-- @param {string} type File type
-- @param {table} spl Parts of the page title before and after the
-- file type
-- @param {string} ext File extension
-- @param {table} args Existing template arguments
-- @returns {table} New template arguments
-- @local
local function mapper(t, spl, ext, args)
if template_map[t] then
if not args.type then
args.type = t
end
local mapped = template_map[t](mw.text.trim(spl[1]), mw.text.trim(spl[2]), ext, args)
for k, v in pairs(mapped) do
if not args[k] then
args[k] = v
end
end
if type(args.description) == 'table' then
args.description = table.concat(args.description)
end
end
return args
end
--- Combines passed arguments with arguments deduced from the filename and file
-- type.
-- @function template
-- @param {table} args Arguments passed through a template
-- @returns {table} New arguments
-- @local
local function template(args)
local ext
local noext = {}
local mapped
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 in ipairs(data.typeorder) do
local spl = mw.text.split(noext, table.concat({'%s', t}))
if spl[2] then
-- Found file type
mapped = mapper(t, spl, ext, args)
break
end
end
if not mapped then
local t = args.type or 'misc'
t = mw.text.split(t, ',', true)[1]
t = mw.text.trim(t)
mapped = mapper(t, {'',''}, ext, args)
end
return mapped
end
--- Formats the issues parameter.
-- @function p.issues
-- @param {string} issues Issues to format
-- @returns {string} Formatted issues
function p.issues(issues)
if issues.args then
issues = issues.args[1]
end
return yesno(issues, false) and 'has bad quality' or issues
end
--- Template entrypoint for [[Template:File]].
-- @function p.main
-- @param {table} frame Scribunto frame object
-- @returns {string} Table with file information and categories
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, 'fileinfotpl_desc')
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
makeRow(html, 'Type', table.concat(res))
makeRow(html, 'Source', args.source or table.concat({
'\'\'[[',
data.game,
']]\'\''
}), 'fileinfotpl_src')
if args.filename then
makeRow(html, 'In-game name', args.filename)
end
makeRow(html, 'Author', type(args.author) == 'string' and args.author ~= '' and
data.authors[args.author] and
data.authors[args.author] or
args.author or
data.authors.default,
'fileinfotpl_aut'
)
makeRow(html, 'Licensing', table.concat({
'This file ',
data.license[args.license or args.licensing or 'default'] or data.license.default,
'.'
}), 'fileinfotpl_perm')
if args.issues then
makeRow(html, 'Quality issues', table.concat({
'This file ',
p.issues(args.issues),
'. You can help the ',
mw.site.siteName,
' by uploading a new version.',
isfile and '[[Category:Faulty images]]' or ''
}))
end
return tostring(html)
end
return p
-- </nowiki>