Module:CRTModel: Difference between revisions
No edit summary |
No edit summary |
||
| Line 207: | Line 207: | ||
end | end | ||
-- Mods section: | -- Mods section: Query for mod subobjects and display | ||
local | 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= | ' |?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 | local modsResult = frame:preprocess(modsQueryWikitext) | ||
if | -- Parse mods from broadtable result | ||
local | local mods = {} | ||
if modsResult then | |||
for rowContent in modsResult:gmatch('<tr[^>]*>(.-)</tr>') do | |||
local cells = {} | |||
for cellContent in rowContent:gmatch('<td[^>]*>(.-)</td>') do | |||
local cleanContent = cellContent:gsub('<[^>]+>', '') | |||
table.insert(cells, trim(cleanContent)) | |||
end | |||
-- With broadtable, empty columns are omitted, so we need to identify columns by content | |||
-- We know: first cell is subobject name, last cell should be URL (starts with http) | |||
-- We need to find: type, description (optional), feasible, url | |||
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') | |||
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: 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 | ||