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 | -- Archival Links section: Query for link subobjects and display by type | ||
local | local linksQueryWikitext = | ||
'{{#ask:\n' .. | '{{#ask:\n' .. | ||
' [[AV device::' .. fullPageName .. ']]\n' .. | ' [[AV device::' .. fullPageName .. ']]\n' .. | ||
' | ' |?Model link type\n' .. | ||
' |format= | ' |?Model link source\n' .. | ||
' |?Model link URL\n' .. | |||
' |format=broadtable\n' .. | |||
' |headers=hide\n' .. | |||
' |link=none\n' .. | |||
'}}' | '}}' | ||
local | local linksResult = frame:preprocess(linksQueryWikitext) | ||
local hasLinks = | |||
-- 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 | local linkTypeOrder = {'Database', 'Manufacturer', 'Retailer'} | ||
for _, linkType in ipairs(linkTypeOrder) do | |||
if #linksByType[linkType] > 0 then | |||
local linksHtml = {} | |||
for _, link in ipairs(linksByType[linkType]) do | |||
table.insert(linksHtml, '[' .. link.url .. ' ' .. link.source .. ']') | |||
end | |||
addRow(container, linkType, table.concat(linksHtml, '<br>'), true) | |||
end | |||
end | |||
end | end | ||