Rewrite to query pre-computed category semantic properties instead of scanning all AV device pages (via update-page on MediaWiki MCP Server)
Add link parameter support (pass through to Template:AV brand entry) (via update-page on MediaWiki MCP Server)
Line 15: Line 15:


function p.list(frame)
function p.list(frame)
local args = frame.args
local linkType = trim(args.link)
-- Query brand category pages (fast - only queries category pages, not all AV devices)
-- Query brand category pages (fast - only queries category pages, not all AV devices)
local queryWikitext =
local queryWikitext =
Line 52: Line 55:
local output = {}
local output = {}
for _, brand in ipairs(brandsList) do
for _, brand in ipairs(brandsList) do
local templateCall = '{{AV brand entry|brand=' .. brand .. '}}'
local templateCall
if linkType then
templateCall = '{{AV brand entry|brand=' .. brand .. '|link=' .. linkType .. '}}'
else
templateCall = '{{AV brand entry|brand=' .. brand .. '}}'
end
table.insert(output, frame:preprocess(templateCall))
table.insert(output, frame:preprocess(templateCall))
end
end

Revision as of 20:23, 5 February 2026

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

-- Module:AVBrandList
-- Dynamically generates a list of AV device brand buttons by querying
-- pre-computed brand category pages with semantic properties.
-- Much faster than scanning all AV device pages.

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)
	local args = frame.args
	local linkType = trim(args.link)

	-- Query brand category pages (fast - only queries category pages, not all AV devices)
	local queryWikitext =
		'{{#ask:\n' ..
		' [[Is AV brand category::Yes]]\n' ..
		' |?Brand name\n' ..
		' |format=broadtable\n' ..
		' |headers=hide\n' ..
		' |link=none\n' ..
		' |mainlabel=-\n' ..
		' |limit=500\n' ..
		' |searchlabel=\n' ..
		'}}'
	
	local queryResult = frame:preprocess(queryWikitext)
	
	-- Extract brand names from result
	local brandsList = {}
	
	if queryResult then
		for cellContent in queryResult:gmatch('<td[^>]*>(.-)</td>') do
			local brand = trim(cellContent:gsub('<[^>]+>', ''))
			if brand and brand ~= '' then
				table.insert(brandsList, brand)
			end
		end
	end
	
	-- Sort alphabetically
	table.sort(brandsList)
	
	if #brandsList == 0 then
		return '<p><em>No AV device brands found.</em></p>'
	end
	
	-- Build the output: render each brand using Template:AV brand entry
	local output = {}
	for _, brand in ipairs(brandsList) do
		local templateCall
		if linkType then
			templateCall = '{{AV brand entry|brand=' .. brand .. '|link=' .. linkType .. '}}'
		else
			templateCall = '{{AV brand entry|brand=' .. brand .. '}}'
		end
		table.insert(output, frame:preprocess(templateCall))
	end
	
	return table.concat(output, '\n')
end

return p
MediaWiki Appliance - Powered by TurnKey Linux