Module:AVBrandList: Difference between revisions

Create module to dynamically generate AV device brand list from semantic query (via create-page on MediaWiki MCP Server)
 
Revert to category-based approach for consistency with CRT brands - requires brand category pages but is more reliable and scalable (via update-page on MediaWiki MCP Server)
Tag: Manual revert
 
(6 intermediate revisions by 2 users not shown)
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
-- all unique brands from the AV devices category.
-- pre-computed brand category pages with semantic properties.
-- Much faster than scanning all AV device pages.


local p = {}
local p = {}
Line 14: Line 15:


function p.list(frame)
function p.list(frame)
-- Query all AV devices and get their brands
local args = frame.args
-- Using broadtable format for easier parsing
local linkType = trim(args.link)
 
-- Query brand category pages (fast - only queries category pages, not all AV devices)
local queryWikitext =
local queryWikitext =
'{{#ask:\n' ..
'{{#ask:\n' ..
' [[Category:AV devices]]\n' ..
' [[Is AV brand category::Yes]]\n' ..
' |?Has brand\n' ..
' |?Brand name\n' ..
' |format=broadtable\n' ..
' |format=broadtable\n' ..
' |headers=hide\n' ..
' |headers=hide\n' ..
Line 25: Line 28:
' |mainlabel=-\n' ..
' |mainlabel=-\n' ..
' |limit=500\n' ..
' |limit=500\n' ..
' |searchlabel=\n' ..
'}}'
'}}'
local queryResult = frame:preprocess(queryWikitext)
local queryResult = frame:preprocess(queryWikitext)
-- Extract unique brands from the result
-- Extract brand names from result
local brandsSet = {}
local brandsList = {}
local brandsList = {}
if queryResult then
if queryResult then
-- Parse each row from the broadtable
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 ~= '' and not brandsSet[brand] then
if brand and brand ~= '' then
brandsSet[brand] = true
table.insert(brandsList, brand)
table.insert(brandsList, brand)
end
end
Line 47: Line 48:
table.sort(brandsList)
table.sort(brandsList)
-- If no brands found, return a message
if #brandsList == 0 then
if #brandsList == 0 then
return '<p><em>No AV device brands found.</em></p>'
return '<p><em>No AV device brands found.</em></p>'
Line 55: 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
MediaWiki Appliance - Powered by TurnKey Linux