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 | -- 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 | local args = frame.args | ||
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' .. | ||
' [[ | ' [[Is AV brand category::Yes]]\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 | -- Extract brand names from result | ||
local brandsList = {} | local brandsList = {} | ||
if queryResult then | if queryResult then | ||
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 ~= '' | if brand and brand ~= '' then | ||
table.insert(brandsList, brand) | table.insert(brandsList, brand) | ||
end | end | ||
| Line 47: | Line 48: | ||
table.sort(brandsList) | table.sort(brandsList) | ||
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 | ||