Module:AVDevice: Difference between revisions

Fix Parts section: capitalize IC, remove description from link, add "Add a part" button (via update-page on MediaWiki MCP Server)
Add Accessories section to AV device infobox (matching CRT model pattern, using Has related AV device) (via update-page on MediaWiki MCP Server)
Line 520: Line 520:
end
end
end
end
end
end
end
-- Accessories section: Query for non-remote accessories linked via Has related AV device
local accessoriesCountWikitext =
'{{#ask:\n' ..
' [[Category:Accessories]]\n' ..
' [[Has related AV device::' .. fullPageName .. ']]\n' ..
' [[Has accessory type::!Remote control]]\n' ..
' |format=count\n' ..
'}}'
local accessoryCount = frame:preprocess(accessoriesCountWikitext)
local hasAccessories = accessoryCount and tonumber(trim(accessoryCount)) and tonumber(trim(accessoryCount)) > 0
if hasAccessories then
addSectionRow(container, 'Accessories')
-- Query accessories and display grouped by type
local accessoriesQueryWikitext =
'{{#ask:\n' ..
' [[Category:Accessories]]\n' ..
' [[Has related AV device::' .. fullPageName .. ']]\n' ..
' [[Has accessory type::!Remote control]]\n' ..
' |?Has accessory type=type\n' ..
' |?Has model code=model\n' ..
' |format=broadtable\n' ..
' |headers=hide\n' ..
' |link=none\n' ..
'}}'
local accessoriesResult = frame:preprocess(accessoriesQueryWikitext)
-- Parse accessories from broadtable result and group by type
local accessoriesByType = {}
local typeOrder = {}
if accessoriesResult then
for rowContent in accessoriesResult: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] = type, cells[3] = model code
if #cells >= 2 then
local accPageName = cells[1]
local accType = cells[2] or 'Accessory'
if accPageName then
-- Track type order for consistent display
if not accessoriesByType[accType] then
accessoriesByType[accType] = {}
table.insert(typeOrder, accType)
end
table.insert(accessoriesByType[accType], {
page = accPageName
})
end
end
end
end
-- Display as label/value rows grouped by type (like Archival Links)
for _, accType in ipairs(typeOrder) do
local accs = accessoriesByType[accType]
if accs and #accs > 0 then
local accLinks = {}
for _, acc in ipairs(accs) do
-- Show just "Brand Model" as the link text (the page name)
table.insert(accLinks, '[[' .. acc.page .. ']]')
end
addRow(container, accType, table.concat(accLinks, '<br>'), true)
end
end
end
end
MediaWiki Appliance - Powered by TurnKey Linux