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
addSectionRow(container, 'Compatible AV Devices')
local avDiv = container:tag('div')
css(avDiv, 'grid-column: 1 / -1; padding:0.2em 0.4em;')
-- 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 image#70px;x70px=Photo\n' ..
' |?Has device type\n' ..
' |?Has model code=Model\n' ..
' |format=broadtable\n' ..
' |?Has device type=Type\n' ..
' |headers=hide\n' ..
' |format=table\n' ..
' |link=none\n' ..
' |class=wikitable\n' ..
' |mainlabel=AV device\n' ..
' |link=subject\n' ..
'}}'
'}}'
local avHtml = frame:preprocess(avQueryWikitext)
local avResult = frame:preprocess(avQueryWikitext)
avDiv:wikitext(avHtml)
-- 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
MediaWiki Appliance - Powered by TurnKey Linux