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' ) }

local has_missing_categories = false local missing_categories = {} local missing_category_fields = {} local invalid_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) local categories = add_array(features,versions) categories[#categories+1] = get_categories(parent.args, "persistance", 1)[1] categories[#categories+1] = get_categories(parent.args, "observability", 1)[1] local warning = "" if has_missing_categories then categories[#categories+1] = "Missing Categories" local warning_text = "" if #invalid_categories > 0 then warning_text = warning_text .. "\nThe following categories are invalid: " .. table.concat(invalid_categories, ", ") end if #missing_category_fields > 0 then warning_text = warning_text .. "\nThe following categories fields are missing: " .. table.concat(missing_category_fields, ", ") end warning = frame:expandTemplate{ title = 'Missing Categories', args = {text = warning_text}} end return parse_categories(categories) .. warning end

function get_category(str, _type) name = str local category = data[_type][string.gsub(string.gsub(str,"[%s%-]", "_"),"['%:]","")] 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.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(list, _type, lim) local cat = list[_type] if not cat then has_missing_categories = true missing_category_fields[#missing_category_fields+1] = _type return {} end local categories = get_category(list[_type],_type) for i=2,lim do           cat = list[_type .. i]           if cat then categories = add_array(categories, get_category(cat,_type)) end end return categories end

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

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

return p