Module:Discontinued Feature Categories

local p = {} --p stands for package local data = { feature = mw.loadData( 'Module:Discontinued Feature Categories/Feature' ), version = mw.loadData( 'Module:Discontinued Feature Categories/Version' ), persistance = mw.loadData( 'Module:Discontinued Feature Categories/Persistance' ), observability = mw.loadData( 'Module:Discontinued Feature Categories/Observability' ), toggle = mw.loadData( 'Module:Discontinued Feature Categories/Toggle' ) }

local has_missing_categories = false local missing_categories = {} local missing_category_fields = {} local invalid_categories = {} local templates = {} local category_checks = {} local has_failed_check = false local failed_category_checks = {} local categories = {}

function p.parse(frame) local parent = frame:getParent local features = get_categories(parent.args, "feature", 5) local versions = get_categories(parent.args, "version", 3) categories = add_array(features,versions) categories = add_array(categories,get_categories(parent.args, "persistance", 1)) categories = add_array(categories,get_categories(parent.args, "observability", 1)) for field, v in pairs(data.toggle) do       if not parent.args[field] then has_missing_categories = true missing_category_fields[#missing_category_fields+1] = field else categories = add_array(categories,get_category(v[parent.args[field]], "feature")) end end for category, check in pairs(category_checks) do       if not category_check(check) then has_failed_check = true has_mssing_categories = true failed_category_checks[category] = check end end local template_text = "" for i=1,#templates do       template_text = template_text .. frame:expandTemplate{ title = templates[i]} end if has_missing_categories then categories[#categories+1] = "Missing Categories" local warning_args = {} if #invalid_categories > 0 then warning_args.invalidCategories = table.concat(invalid_categories," ") end if #missing_category_fields > 0 then warning_args.missingCategoryFields = table.concat(missing_category_fields," ") end if has_failed_check then local failed_checks = "" for category, check in pairs(category_checks) do               failed_checks = failed_checks .. " " .. category .. " needs one of the following categories: " .. table.concat(check, ", ") end warning_args.failedChecks = failed_checks end template_text = template_text .. frame:expandTemplate{ title = 'Missing Categories', args = warning_args} end return parse_categories(categories) .. template_text end

function get_category(str, _type) local name = str local category = data[_type][string.gsub(string.gsub(str,"[%s%-]", "_"),"[^%w_]","")] if not category then has_missing_categories = true invalid_categories[#invalid_categories+1] = str return {} end if category.name then name = category.name else name = name .. " Discontinued Feature" end list = {name} if category.template then templates[#templates+1] = category.template end if category.check_for_one then category_checks[name] = category.check_for_one end if category.parents then if type(category.parents) =="string" then list = add_array(list, get_category(category.parents, _type)) end if type(category.parents) =="table" then for i = 1, #category.parents do               list = add_array(list, get_category(category.parents[i], _type)) end end end return list end

function get_categories(args, _type, lim) if not args[_type] then has_missing_categories = true missing_category_fields[#missing_category_fields+1] = _type return {} end local categories = {} for cat in string.gmatch(args[_type]..",","(.-)".."%s*,%s*") do           categories = add_array(categories, get_category(cat,_type)) end return categories end

function parse_categories(list) if #list == 0 then return '' end return "" end

function category_check (vals) for i=1,#categories do       for j=1,#vals do            if categories[i] == vals[j] then return true end end end return false end

function add_array(arr1,arr2) for i=1,#arr2 do      arr1[#arr1+1] = arr2[i] end return arr1 end

return p