Module:AVBrandList: Difference between revisions

Implement pagination for consistency and future-proofing (via update-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
 
(3 intermediate revisions by the same user 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.
-- Uses pagination to work around server-side SMW query limits.
-- Much faster than scanning all AV device pages.


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


local function extractBrandsFromResult(queryResult, brandsSet, brandsList)
function p.list(frame)
if not queryResult then return end
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)
for cellContent in queryResult:gmatch('<td[^>]*>(.-)</td>') do
-- Extract brand names from result
local brand = trim(cellContent:gsub('<[^>]+>', ''))
if brand and brand ~= '' and not brandsSet[brand] then
brandsSet[brand] = true
table.insert(brandsList, brand)
end
end
end
 
function p.list(frame)
local brandsSet = {}
local brandsList = {}
local brandsList = {}
-- Query in batches to work around server-side limits
if queryResult then
local batchSize = 500
for cellContent in queryResult:gmatch('<td[^>]*>(.-)</td>') do
local maxBatches = 20  -- Safety limit
local brand = trim(cellContent:gsub('<[^>]+>', ''))
if brand and brand ~= '' then
for batch = 0, maxBatches - 1 do
table.insert(brandsList, brand)
local offset = batch * batchSize
local queryWikitext =
'{{#ask:\n' ..
' [[Category:AV devices]]\n' ..
' |?Has brand\n' ..
' |format=broadtable\n' ..
' |headers=hide\n' ..
' |link=none\n' ..
' |mainlabel=-\n' ..
' |limit=' .. batchSize .. '\n' ..
' |offset=' .. offset .. '\n' ..
' |searchlabel=\n' ..
'}}'
local queryResult = frame:preprocess(queryWikitext)
extractBrandsFromResult(queryResult, brandsSet, brandsList)
-- Count cells to check if we got a full batch
local cellCount = 0
if queryResult then
for _ in queryResult:gmatch('<td[^>]*>') do
cellCount = cellCount + 1
end
end
end
-- If we got fewer results than batch size, we're done
if cellCount < batchSize then
break
end
end
end
end
Line 78: 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