Module:AVDeviceTypeList

Revision as of 21:20, 4 February 2026 by Arclight-MCP-Bot (talk | contribs) (Create module to dynamically generate AV device type list from semantic query (via create-page on MediaWiki MCP Server))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:AVDeviceTypeList/doc

-- Module:AVDeviceTypeList
-- Dynamically generates a list of AV device type buttons by querying
-- all unique types from the AV devices category.

local p = {}

local function trim(s)
	if s == nil then return nil end
	s = tostring(s)
	s = s:gsub('^%s+', ''):gsub('%s+$', '')
	if s == '' then return nil end
	return s
end

function p.list(frame)
	-- Query all AV devices and get their types
	local queryWikitext =
		'{{#ask:\n' ..
		' [[Category:AV devices]]\n' ..
		' |?Has device type\n' ..
		' |format=broadtable\n' ..
		' |headers=hide\n' ..
		' |link=none\n' ..
		' |mainlabel=-\n' ..
		' |limit=500\n' ..
		'}}'
	
	local queryResult = frame:preprocess(queryWikitext)
	
	-- Extract unique types from the result
	local typesSet = {}
	local typesList = {}
	
	if queryResult then
		for cellContent in queryResult:gmatch('<td[^>]*>(.-)</td>') do
			local deviceType = trim(cellContent:gsub('<[^>]+>', ''))
			if deviceType and deviceType ~= '' and not typesSet[deviceType] then
				typesSet[deviceType] = true
				table.insert(typesList, deviceType)
			end
		end
	end
	
	-- Sort alphabetically
	table.sort(typesList)
	
	if #typesList == 0 then
		return '<p><em>No AV device types found.</em></p>'
	end
	
	-- Build the output: render each type using Template:AV device type entry
	local output = {}
	for _, deviceType in ipairs(typesList) do
		local templateCall = '{{AV device type entry|type=' .. deviceType .. '}}'
		table.insert(output, frame:preprocess(templateCall))
	end
	
	return table.concat(output, '\n')
end

return p
MediaWiki Appliance - Powered by TurnKey Linux