Module:CRTModel: Difference between revisions

No edit summary
No edit summary
Line 196: Line 196:
addSectionRow(container, 'Standards')
addSectionRow(container, 'Standards')
addFullRow(container, standards_semantic, 'padding:0.2em 0.4em;', false)
addFullRow(container, standards_semantic, 'padding:0.2em 0.4em;', false)
end
-- Mods section: Query for mod subobjects and display
local modsQueryWikitext =
'{{#ask:\n' ..
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
' [[Has mod type::+]]\n' ..
' |?Has mod type=type\n' ..
' |?Has mod description=description\n' ..
' |?Has mod feasible=feasible\n' ..
' |?Has mod URL=url\n' ..
' |format=broadtable\n' ..
' |headers=hide\n' ..
' |link=none\n' ..
'}}'
local modsResult = frame:preprocess(modsQueryWikitext)
-- Parse mods and build display
local mods = {}
local hasMods = false
if modsResult then
-- Match each table row
for rowContent in modsResult: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] = subobject, cells[2] = type, cells[3] = description, cells[4] = feasible, cells[5] = url
if #cells >= 5 then
local modType = cells[2]
local modDescription = cells[3]
local modFeasible = cells[4]
local modUrl = cells[5]
if modType and modUrl then
table.insert(mods, {
type = modType,
description = modDescription,
feasible = modFeasible,
url = modUrl
})
hasMods = true
end
end
end
end
-- Display mods section if there are any mods
if hasMods then
addSectionRow(container, 'Mods')
local modsDiv = container:tag('div')
css(modsDiv, 'grid-column: 1 / -1; padding:0.2em 0.4em;')
local ul = mw.html.create('ul')
ul:css('margin', '0'):css('padding-left', '1.5em')
for _, mod in ipairs(mods) do
local li = ul:tag('li')
-- Determine display text
local displayText = mod.type
if mod.type == 'Other' and mod.description then
displayText = mod.description
elseif mod.description then
displayText = mod.type .. ' – ' .. mod.description
end
-- Check if mod is not feasible
local isFeasible = mod.feasible ~= 'No'
if isFeasible then
-- Normal link for feasible mods
li:wikitext('[' .. mod.url .. ' ' .. displayText .. ']')
else
-- Red styling with X for impossible mods
local notFeasibleSpan = mw.html.create('span')
notFeasibleSpan:css('color', '#dc2626')  -- Red color
notFeasibleSpan:wikitext('✗ ')
local linkSpan = mw.html.create('span')
linkSpan:css('color', '#dc2626')
linkSpan:wikitext('[' .. mod.url .. ' ' .. displayText .. ']')
local notPossibleLabel = mw.html.create('span')
notPossibleLabel:css('color', '#dc2626')
notPossibleLabel:css('font-style', 'italic')
notPossibleLabel:css('font-size', '0.9em')
notPossibleLabel:wikitext(' (not possible)')
li:node(notFeasibleSpan)
li:node(linkSpan)
li:node(notPossibleLabel)
end
end
modsDiv:node(ul)
end
end


MediaWiki Appliance - Powered by TurnKey Linux