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 tbl = mw.html.create('table') | local tbl = mw.html.create('table') | ||
| Line 288: | Line 286: | ||
end | end | ||
-- | -- Links section: Query for link subobjects and display by type | ||
local linksQueryWikitext = | |||
'{{#ask:\n' .. | |||
local links = {} | ' [[Has CRT model::' .. fullPageName .. ']]\n' .. | ||
if | ' |?Has link type\n' .. | ||
' |?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 | ||
end | |||
-- 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 | ||
td:node(ul) | |||
end | end | ||