A documentação para este módulo pode ser criada em Módulo:Correção de Funcionários/doc
local p = {}
local NomesDeFuncionarios = mw.loadData('Módulo:Correção de Funcionários/dados')
local h = require("Módulo:HF")
local excecoes_list = mw.loadData('Módulo:Correção de Funcionários/exceções')
local pseudonimos_list = mw.loadData('Módulo:Correção de Funcionários/pseudônimos')
local getArgs = require('Dev:Arguments').getArgs
--------------------------------------------------------------------------------
function p.lua_get_nome_correto(nome)
local function in_list(list, value) -- a função normal "h.in_list" não funciona, então a lista é carregada de outra página
local output = false
for i, v in ipairs(list) do
if v == value
then
output = true
break
end
end
return output
end
local excecao = false
local output = ''
if not h.isempty(nome)
then
output = NomesDeFuncionarios[ string.lower( mw.text.trim(nome) ) ] or mw.text.trim(nome)
if in_list(excecoes_list, output) or in_list(pseudonimos_list, nome)
then excecao = true
end
end
return output, excecao
end
--------------------------------------------------------------------------------
function p.get_nome_correto(frame)
local excecao
local output
output, excecao = p.lua_get_nome_correto(frame.args[1])
return output
end
--------------------------------------------------------------------------------
function p.lua_get_link_de_funcionario_e_categoria(nome, subcategory)
local excecao
local nome_correto = ''
local s = ''
local category = ''
local output = ''
if not h.isempty(nome)
then
nome = mw.text.trim(nome)
nome = h.break_link(nome, 1)
s = string.lower(nome)
if h.in_list( {'Não creditado', 'n/a'}, s )
then output = 'Não creditado'
else
nome_correto, excecao = p.lua_get_nome_correto(nome)
if nome_correto ~= nome and excecao == true
then
if subcategory == 'Criador'
then output = h.Link(nome_correto, nome_correto)
else output = h.Link(nome_correto, nome_correto..' (creditado com outro nome')
end
else output = h.Link(nome_correto, nome)
end
if not h.isempty(subcategory)
then category = nome_correto..'/'..subcategory
end
end
end
return output, category
end
--------------------------------------------------------------------------------
-- takes a list of nomes (several nomes could be separated by ";") and returns links and categorys
function p.lua_get_lista_de_funcionarios(list, subcategory)
local i
local link
local category
local output_categories = ''
local output = ''
if not h.isempty(list)
then
output = {}
output_categories = {}
list = mw.text.split(list, ';')
for i = 1, #list do
link, category = p.lua_get_link_de_funcionario_e_categoria(list[i], subcategory)
table.insert(output, link)
table.insert(output_categories, category)
end
output = mw.text.listToText(output, ', ', ', ')
end
return output, output_categories
end
--------------------------------------------------------------------------------
-- pega uma lista de campos com nomes semelhantes (args) com "nome_do_campo" e retorna links e categorias
function p.lua_get_lista_de_funcionarios_de_args(args, nome_do_campo, subcategory)
local i = 1
local link
local category
local output_categories = {}
local output = {}
if not h.isempty(args[nome_do_campo..i])
then
for i = 1, 100 do
link, category = p.lua_get_link_de_funcionario_e_categoria(args[nome_do_campo..i], subcategory)
if link ~= ''
then
table.insert(output, link)
table.insert(output_categories, category)
end
end
--output = mw.text.listToText(output, ', ', ', ')
end
return output, output_categories
end
function p.get_lista_de_funcionarios_de_args(frame)
local args = getArgs(frame)
local nome_do_campo = args[1]
local subcategory = args[2]
local output_categories
local output
output, output_categories = p.lua_get_lista_de_funcionarios_de_args(args, nome_do_campo, subcategory)
return mw.text.listToText(output, ', ', ', ')..h.add_categories(output_categories)
end
--------------------------------------------------------------------------------
function p.lua_get_criadores(list)
local links = ''
local categorys = ''
if not h.isempty(list)
then links, categorys = p.lua_get_lista_de_funcionarios(list, 'Criador')
end
return links, categorys
end
--------------------------------------------------------------------------------
function p.get_criadores(frame)
local getArgs = require('Dev:Arguments').getArgs
local args = getArgs (frame)
local list = args[1]
local links
local categorys
links, categorys = p.lua_get_criadores(list)
return links..h.add_categorys(categorys)
end
return p