Module:StaffCorrection

local p = {} local StaffNames = mw.loadData('Module:StaffCorrection/data') local h = require("Module:HF") local exceptions_list = mw.loadData('Module:StaffCorrection/exceptions') local pseudonyms_list = mw.loadData('Module:StaffCorrection/pseudonyms') local getArgs = require('Dev:Arguments').getArgs

function p.lua_get_corrected_name(name) local function in_list(list, value) -- normal "h.in_list" function doesn't work then list is loaded from another page local output = false for i, v in ipairs(list) do			if v == value then output = true break end end return output end local exception = false local output = '' if not h.isempty(name) then output = StaffNames[ string.lower( mw.text.trim(name) ) ] or mw.text.trim(name) if in_list(exceptions_list, output) or in_list(pseudonyms_list, name) then exception = true end end return output, exception end

function p.get_corrected_name(frame) local exception local output output, exception = p.lua_get_corrected_name(frame.args[1]) return output end

function p.lua_get_staff_link_and_category(name, subcategory) local exception local corrected_name = '' local s = '' local category = '' local output = '' if not h.isempty(name) then name = mw.text.trim(name) name = h.break_link(name, 1) s = string.lower(name) if h.in_list( {'uncredited', 'n/a'}, s ) then output = 'Uncredited' else corrected_name, exception = p.lua_get_corrected_name(name) if corrected_name ~= name and exception == true then if subcategory == 'Creator' then output = h.Link(corrected_name, corrected_name) else output = h.Link(corrected_name, corrected_name)..' (credited under different name)' end else output = h.Link(corrected_name, name) end if not h.isempty(subcategory) then category = corrected_name..'/'..subcategory end end end return output, category end

-- takes a list of names (several names could be separated by ";") and returns links and categories function p.lua_get_list_of_staff(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_staff_link_and_category(list[i], subcategory) table.insert(output, link) table.insert(output_categories, category) end output = mw.text.listToText(output, ', ', ', ') end return output, output_categories end

function p.get_list_of_staff(frame) local args = getArgs(frame) local value = args[1] local subcategory = args[2] local output_categories local output output, output_categories = p.lua_get_list_of_staff(value, subcategory)

return output..h.add_categories(output_categories) end

-- takes list of similarly named firelds (args) with "field_name" and returns links and categories function p.lua_get_list_of_staff_from_args(args, field_name, subcategory) local i = 1 local link local category local output_categories = {} local output = {}

if not h.isempty(args[field_name..i]) then for i = 1, 100 do				link, category = p.lua_get_staff_link_and_category(args[field_name..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_list_of_staff_from_args(frame) local args = getArgs(frame) local field_name = args[1] local subcategory = args[2] local output_categories local output output, output_categories = p.lua_get_list_of_staff_from_args(args, field_name, subcategory)

return mw.text.listToText(output, ', ', ', ')..h.add_categories(output_categories) end

function p.lua_get_creators(list) local links = '' local categories = ''

if not h.isempty(list) then links, categories = p.lua_get_list_of_staff(list, 'Creator') end return links, categories end

return p