Module:CRTModel: Difference between revisions

No edit summary
No edit summary
Line 207: Line 207:
end
end


-- Mods section: use count query to check if there are any mods
-- Mods section: Query for mod subobjects and display
local modsCountWikitext =
local modsQueryWikitext =
'{{#ask:\n' ..
'{{#ask:\n' ..
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
' [[Has mod URL::+]]\n' ..
' [[Has mod URL::+]]\n' ..
' |format=count\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 modCount = frame:preprocess(modsCountWikitext)
local modsResult = frame:preprocess(modsQueryWikitext)
local hasMods = modCount and tonumber(trim(modCount)) and tonumber(trim(modCount)) > 0
if hasMods then
-- Parse mods from broadtable result
local modsQueryWikitext =
local mods = {}
'{{#ask:\n' ..
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
if modsResult then
' [[Has mod URL::+]]\n' ..
for rowContent in modsResult:gmatch('<tr[^>]*>(.-)</tr>') do
' |?Has mod type=type\n' ..
local cells = {}
' |?Has mod description=description\n' ..
for cellContent in rowContent:gmatch('<td[^>]*>(.-)</td>') do
' |?Has mod feasible=feasible\n' ..
local cleanContent = cellContent:gsub('<[^>]+>', '')
' |?Has mod URL=url\n' ..
table.insert(cells, trim(cleanContent))
' |format=ul\n' ..
end
' |template=CRT mod inline\n' ..
' |named args=yes\n' ..
-- With broadtable, empty columns are omitted, so we need to identify columns by content
' |searchlabel=\n' ..
-- We know: first cell is subobject name, last cell should be URL (starts with http)
'}}'
-- We need to find: type, description (optional), feasible, url
local modsResult = frame:preprocess(modsQueryWikitext)
if #cells >= 3 then
local modData = {
type = nil,
description = nil,
feasible = nil,
url = nil
}
-- First cell is always the subobject identifier, skip it
-- Find URL (starts with http)
-- Find feasible (Yes or No)
-- Find type (RGB, S-video, or Other)
-- Anything else is description
for i = 2, #cells do
local cell = cells[i]
if cell then
if cell:match('^https?://') then
modData.url = cell
elseif cell == 'Yes' or cell == 'No' then
modData.feasible = cell
elseif cell == 'RGB' or cell == 'S-video' or cell == 'Other' then
modData.type = cell
else
-- Must be description
modData.description = cell
end
end
end
if modData.url and modData.type then
table.insert(mods, modData)
end
end
end
end
-- Display mods section if there are any
if #mods > 0 then
addSectionRow(container, 'Mods')
addSectionRow(container, 'Mods')
local modsDiv = container:tag('div')
addFullRow(container, modsResult, 'padding:0.2em 0.4em;', true)
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: use description if available, otherwise type
local displayText = mod.description or mod.type
-- Check if mod is not feasible
local isFeasible = mod.feasible ~= 'No'
if isFeasible then
-- Normal link for feasible mods using HTML anchor
local link = mw.html.create('a')
link:attr('href', mod.url)
link:attr('rel', 'nofollow')
link:addClass('external')
link:wikitext(displayText)
li:node(link)
else
-- Red styling with X for impossible mods
local wrapper = mw.html.create('span')
wrapper:css('color', '#dc2626')
wrapper:wikitext('✗ ')
local link = mw.html.create('a')
link:attr('href', mod.url)
link:attr('rel', 'nofollow')
link:addClass('external')
link:css('color', '#dc2626')
link:wikitext(displayText)
wrapper:node(link)
local notPossible = mw.html.create('i')
notPossible:css('font-size', '0.9em')
notPossible:wikitext(' (not possible)')
wrapper:node(notPossible)
li:node(wrapper)
end
end
modsDiv:node(ul)
end
end


MediaWiki Appliance - Powered by TurnKey Linux