Module:AVDevice: Difference between revisions

Add Accessories section to AV device infobox (matching CRT model pattern, using Has related AV device) (via update-page on MediaWiki MCP Server)
Refactor Archival Links to use broadtable + group-by-type (matching CRT model pattern) instead of template=AV device link row bullet list (via update-page on MediaWiki MCP Server)
Line 722: Line 722:
end
end


-- Archival Links section - query AV link subobjects
-- Archival Links section: Query for link subobjects and display by type
local linksCountWikitext =
local linksQueryWikitext =
'{{#ask:\n' ..
'{{#ask:\n' ..
' [[AV device::' .. fullPageName .. ']]\n' ..
' [[AV device::' .. fullPageName .. ']]\n' ..
' [[Model link URL::+]]\n' ..
' |?Model link type\n' ..
' |format=count\n' ..
' |?Model link source\n' ..
' |?Model link URL\n' ..
' |format=broadtable\n' ..
' |headers=hide\n' ..
' |link=none\n' ..
'}}'
'}}'
local linkCount = frame:preprocess(linksCountWikitext)
local linksResult = frame:preprocess(linksQueryWikitext)
local hasLinks = linkCount and tonumber(trim(linkCount)) and tonumber(trim(linkCount)) > 0
 
-- Parse links and organize by type
local linksByType = {
Manufacturer = {},
Retailer = {},
Database = {}
}
local hasLinks = false
if linksResult then
for rowContent in linksResult: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/subobject, cells[2] = type, cells[3] = source, cells[4] = URL
if #cells >= 4 then
local linkType = cells[2]
local linkSource = cells[3]
local linkUrl = cells[4]
if linkType and linkSource and linkUrl and linkUrl ~= '' then
if linksByType[linkType] then
table.insert(linksByType[linkType], {source = linkSource, url = linkUrl})
hasLinks = true
end
end
end
end
end
if hasLinks then
if hasLinks then
addSectionRow(container, 'Archival Links')
addSectionRow(container, 'Archival Links')
local linksListWikitext =
local linkTypeOrder = {'Database', 'Manufacturer', 'Retailer'}
'{{#ask:\n' ..
for _, linkType in ipairs(linkTypeOrder) do
' [[AV device::' .. fullPageName .. ']]\n' ..
if #linksByType[linkType] > 0 then
' [[Model link URL::+]]\n' ..
local linksHtml = {}
' |?Model link type=type\n' ..
for _, link in ipairs(linksByType[linkType]) do
' |?Model link source=source\n' ..
table.insert(linksHtml, '[' .. link.url .. ' ' .. link.source .. ']')
' |?Model link URL=url\n' ..
end
' |format=template\n' ..
addRow(container, linkType, table.concat(linksHtml, '<br>'), true)
' |template=AV device link row\n' ..
end
' |named args=yes\n' ..
end
' |link=none\n' ..
'}}'
local linksResult = frame:preprocess(linksListWikitext)
local linksDiv = container:tag('div')
css(linksDiv, 'grid-column: 1 / -1; padding:0.2em 0.4em;')
linksDiv:wikitext(linksResult)
end
end


MediaWiki Appliance - Powered by TurnKey Linux