Module:Accessory: Difference between revisions
Add Dimensions section (H × W × D and Weight) to infobox, matching CRT model pattern (via update-page on MediaWiki MCP Server) |
Refactor Compatible AV Devices section to group by device type (like Archival Links) instead of showing a full table (via update-page on MediaWiki MCP Server) |
||
| Line 227: | Line 227: | ||
local av_devices = trim(args.av_devices) | local av_devices = trim(args.av_devices) | ||
if av_devices and av_devices ~= '' then | if av_devices and av_devices ~= '' then | ||
-- Parse av_devices and create OR conditions | -- Parse av_devices and create OR conditions | ||
local avNames = {} | |||
local avConditions = {} | local avConditions = {} | ||
for av in av_devices:gmatch('[^,]+') do | for av in av_devices:gmatch('[^,]+') do | ||
local a = trim(av) | local a = trim(av) | ||
if a then | if a then | ||
table.insert(avNames, a) | |||
table.insert(avConditions, '[[' .. a .. ']]') | table.insert(avConditions, '[[' .. a .. ']]') | ||
end | end | ||
| Line 242: | Line 239: | ||
if #avConditions > 0 then | if #avConditions > 0 then | ||
-- Query for device types | |||
local avQueryWikitext = | local avQueryWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
' [[Category:AV devices]]\n' .. | ' [[Category:AV devices]]\n' .. | ||
' <q>' .. table.concat(avConditions, ' OR ') .. '</q>\n' .. | ' <q>' .. table.concat(avConditions, ' OR ') .. '</q>\n' .. | ||
' |?Has device type\n' .. | |||
' |format=broadtable\n' .. | |||
' |?Has device type | ' |headers=hide\n' .. | ||
' |format= | ' |link=none\n' .. | ||
' | | |||
' |link= | |||
'}}' | '}}' | ||
local | local avResult = frame:preprocess(avQueryWikitext) | ||
-- Parse results into a lookup of page name -> device type | |||
local deviceTypes = {} | |||
if avResult then | |||
for rowContent in avResult:gmatch('<tr[^>]*>(.-)</tr>') do | |||
local cells = {} | |||
for cellContent in rowContent:gmatch('<td[^>]*>(.-)</td>') do | |||
local cleanContent = cellContent:gsub('<[^>]+>', '') | |||
table.insert(cells, trim(cleanContent)) | |||
end | |||
-- cells[1] = page name, cells[2] = device type | |||
if #cells >= 2 and cells[1] and cells[2] then | |||
deviceTypes[cells[1]] = cells[2] | |||
end | |||
end | |||
end | |||
-- Group device names by type | |||
local byType = {} | |||
local typeOrder = {} | |||
local typeSeen = {} | |||
for _, avName in ipairs(avNames) do | |||
local dtype = deviceTypes[avName] or 'Unknown' | |||
if not typeSeen[dtype] then | |||
typeSeen[dtype] = true | |||
table.insert(typeOrder, dtype) | |||
byType[dtype] = {} | |||
end | |||
table.insert(byType[dtype], avName) | |||
end | |||
if #typeOrder > 0 then | |||
addSectionRow(container, 'Compatible AV Devices') | |||
for _, dtype in ipairs(typeOrder) do | |||
local deviceLinks = {} | |||
for _, avName in ipairs(byType[dtype]) do | |||
table.insert(deviceLinks, '[[' .. avName .. ']]') | |||
end | |||
addRow(container, dtype, table.concat(deviceLinks, '<br>'), true) | |||
end | |||
end | |||
end | end | ||
end | end | ||