Module:CRTModel: Difference between revisions

No edit summary
Tag: Manual revert
No edit summary
Line 78: Line 78:
local weight = trim(args.weight)
local weight = trim(args.weight)
local standards_semantic = trim(args.standards_semantic)
local standards_semantic = trim(args.standards_semantic)
local crtdatabase = trim(args.crtdatabase)
local consolemods = trim(args.consolemods)


local tbl = mw.html.create('table')
local tbl = mw.html.create('table')
Line 288: Line 286:
end
end


-- Other Databases section: only display if there are links
-- Links section: Query for link subobjects and display by type
if crtdatabase or consolemods then
local linksQueryWikitext =
addSectionRow(tbl, 'Other Databases')
'{{#ask:\n' ..
local links = {}
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
if crtdatabase then
' |?Has link type\n' ..
table.insert(links, '<li>[' .. crtdatabase .. ' CRT Database]</li>')
' |?Has link source\n' ..
' |?Has link URL\n' ..
' |format=broadtable\n' ..
' |headers=hide\n' ..
' |link=none\n' ..
'}}'
local linksResult = frame:preprocess(linksQueryWikitext)
-- Parse links and organize by type
local linksByType = {
Manufacturer = {},
Retailer = {},
Database = {}
}
local hasLinks = false
if linksResult then
-- Match each table row
for rowContent in linksResult:gmatch('<tr[^>]*>(.-)</tr>') do
local cells = {}
-- Extract content from each <td>
for cellContent in rowContent:gmatch('<td[^>]*>(.-)</td>') do
-- Strip any remaining HTML tags and get just the text
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 consolemods then
end
table.insert(links, '<li>[' .. consolemods .. ' Console Mods Wiki]</li>')
-- Display links section if there are any links
if hasLinks then
addSectionRow(tbl, 'Links')
local tr = tbl:tag('tr')
local td = tr:tag('td'):attr('colspan', '2')
css(td, 'padding:0.2em 0.4em;')
-- Create UL element
local ul = mw.html.create('ul')
ul:css('margin', '0'):css('padding-left', '1.5em')
-- Add links in order: Manufacturer, Retailer, Database
local typeOrder = {'Manufacturer', 'Retailer', 'Database'}
for _, linkType in ipairs(typeOrder) do
if #linksByType[linkType] > 0 then
for _, link in ipairs(linksByType[linkType]) do
local li = ul:tag('li')
li:wikitext('[' .. link.url .. ' ' .. link.source .. ']')
end
end
end
end
local linksHtml = '<ul style="margin:0; padding-left:1.5em;">' .. table.concat(links, '') .. '</ul>'
addFullRow(tbl, linksHtml, 'padding:0.2em 0.4em;', true)
td:node(ul)
end
end


MediaWiki Appliance - Powered by TurnKey Linux