Module:CRTBrandList: Difference between revisions
Rewrite to query pre-computed category semantic properties instead of scanning all CRT pages (via update-page on MediaWiki MCP Server) |
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 |
||
| Line 1: | Line 1: | ||
-- Module:CRTBrandList | -- Module:CRTBrandList | ||
-- Dynamically generates a list of CRT brand buttons by querying | -- 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. | |||
local p = {} | local p = {} | ||
| Line 18: | Line 19: | ||
local linkType = trim(args.link) | local linkType = trim(args.link) | ||
-- Query | -- Query distinct brands from actual CRT model pages | ||
local queryWikitext = | local queryWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
' [[ | ' [[Category:CRT models]]\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= | ' |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 | ||