Module:CRTBrandList: Difference between revisions
Update to query brands directly from CRT model pages (like AVBrandList) instead of requiring brand category pages - ensures all CRT brands appear (via update-page on MediaWiki MCP Server) Tag: Reverted |
Fix: Use format=plainlist instead of broadtable to handle large result sets efficiently - broadtable was causing truncation with 2000+ CRT models (via update-page on MediaWiki MCP Server) Tag: Reverted |
||
| Line 4: | Line 4: | ||
-- This approach ensures all brands with at least one CRT model appear, | -- This approach ensures all brands with at least one CRT model appear, | ||
-- even if they don't have a dedicated brand category page. | -- even if they don't have a dedicated brand category page. | ||
-- | |||
-- Uses format=plainlist for efficiency with large datasets (2000+ CRTs). | |||
local p = {} | local p = {} | ||
| Line 20: | Line 22: | ||
-- Query distinct brands from actual CRT model pages | -- Query distinct brands from actual CRT model pages | ||
-- Using plainlist format with custom separator for efficient parsing | |||
local queryWikitext = | local queryWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
| Line 25: | Line 28: | ||
' [[Has brand::+]]\n' .. | ' [[Has brand::+]]\n' .. | ||
' |?Has brand\n' .. | ' |?Has brand\n' .. | ||
' |format= | ' |format=plainlist\n' .. | ||
' | | ' |sep=@@SEP@@\n' .. | ||
' |valuesep=@@VAL@@\n' .. | |||
' |link=none\n' .. | ' |link=none\n' .. | ||
' |mainlabel=-\n' .. | ' |mainlabel=-\n' .. | ||
| Line 40: | Line 44: | ||
if queryResult then | if queryResult then | ||
for | -- Split by our custom separator | ||
for entry in (queryResult .. '@@SEP@@'):gmatch('(.-)@@SEP@@') do | |||
-- Each entry might have multiple values separated by @@VAL@@ | |||
for brand in (entry .. '@@VAL@@'):gmatch('(.-)@@VAL@@') do | |||
brand = trim(brand) | |||
if brand and brand ~= '' and not seen[brand] then | |||
seen[brand] = true | |||
table.insert(brandsList, brand) | |||
end | |||
end | end | ||
end | end | ||
Revision as of 20:21, 27 February 2026
Documentation for this module may be created at Module:CRTBrandList/doc
-- Module:CRTBrandList
-- Dynamically generates a list of CRT brand buttons by querying
-- distinct brands from actual CRT model pages.
-- This approach ensures all brands with at least one CRT model appear,
-- even if they don't have a dedicated brand category page.
--
-- Uses format=plainlist for efficiency with large datasets (2000+ CRTs).
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 distinct brands from actual CRT model pages
-- Using plainlist format with custom separator for efficient parsing
local queryWikitext =
'{{#ask:\n' ..
' [[Category:CRT models]]\n' ..
' [[Has brand::+]]\n' ..
' |?Has brand\n' ..
' |format=plainlist\n' ..
' |sep=@@SEP@@\n' ..
' |valuesep=@@VAL@@\n' ..
' |link=none\n' ..
' |mainlabel=-\n' ..
' |limit=5000\n' ..
' |searchlabel=\n' ..
'}}'
local queryResult = frame:preprocess(queryWikitext)
-- Extract and deduplicate brand names from result
local seen = {}
local brandsList = {}
if queryResult then
-- Split by our custom separator
for entry in (queryResult .. '@@SEP@@'):gmatch('(.-)@@SEP@@') do
-- Each entry might have multiple values separated by @@VAL@@
for brand in (entry .. '@@VAL@@'):gmatch('(.-)@@VAL@@') do
brand = trim(brand)
if brand and brand ~= '' and not seen[brand] then
seen[brand] = true
table.insert(brandsList, brand)
end
end
end
end
-- Sort alphabetically
table.sort(brandsList)
if #brandsList == 0 then
return '<p><em>No CRT brands found.</em></p>'
end
-- Build the output: render each brand using Template:Brand entry
local output = {}
for _, brand in ipairs(brandsList) do
local templateCall
if linkType then
templateCall = '{{Brand entry|brand=' .. brand .. '|link=' .. linkType .. '}}'
else
templateCall = '{{Brand entry|brand=' .. brand .. '}}'
end
table.insert(output, frame:preprocess(templateCall))
end
return table.concat(output, '\n')
end
return p