Module:AVBrandList: Difference between revisions

Add link parameter support (pass through to Template:AV brand entry) (via update-page on MediaWiki MCP Server)
Update to query brands directly from AV device pages (like AVDeviceTypeList does for types) instead of requiring brand category pages - this ensures all brands appear including Victor (via update-page on MediaWiki MCP Server)
Tag: Reverted
Line 1: Line 1:
-- Module:AVBrandList
-- Module:AVBrandList
-- Dynamically generates a list of AV device brand buttons by querying
-- Dynamically generates a list of AV device brand buttons by querying
-- pre-computed brand category pages with semantic properties.
-- distinct brands from actual AV device pages.
-- Much faster than scanning all AV device pages.
-- This approach ensures all brands with at least one AV device appear,
-- even if they don't have a dedicated brand category page.


local p = {}
local p = {}
Line 18: Line 19:
local linkType = trim(args.link)
local linkType = trim(args.link)


-- Query brand category pages (fast - only queries category pages, not all AV devices)
-- Query distinct brands from actual AV device pages
local queryWikitext =
local queryWikitext =
'{{#ask:\n' ..
'{{#ask:\n' ..
' [[Is AV brand category::Yes]]\n' ..
' [[Category:AV devices]]\n' ..
' |?Brand name\n' ..
' [[Has brand::+]]\n' ..
' |?Has brand\n' ..
' |format=broadtable\n' ..
' |format=broadtable\n' ..
' |headers=hide\n' ..
' |headers=hide\n' ..
' |link=none\n' ..
' |link=none\n' ..
' |mainlabel=-\n' ..
' |mainlabel=-\n' ..
' |limit=500\n' ..
' |limit=5000\n' ..
' |searchlabel=\n' ..
' |searchlabel=\n' ..
'}}'
'}}'
Line 33: Line 35:
local queryResult = frame:preprocess(queryWikitext)
local queryResult = frame:preprocess(queryWikitext)
-- Extract brand names from result
-- Extract and deduplicate brand names from result
local seen = {}
local brandsList = {}
local brandsList = {}
Line 39: Line 42:
for cellContent in queryResult:gmatch('<td[^>]*>(.-)</td>') do
for cellContent in queryResult:gmatch('<td[^>]*>(.-)</td>') do
local brand = trim(cellContent:gsub('<[^>]+>', ''))
local brand = trim(cellContent:gsub('<[^>]+>', ''))
if brand and brand ~= '' then
if brand and brand ~= '' and not seen[brand] then
seen[brand] = true
table.insert(brandsList, brand)
table.insert(brandsList, brand)
end
end
MediaWiki Appliance - Powered by TurnKey Linux