Module:CRTModel: Difference between revisions

Add Tube section to infobox: reads mask_type, pitch, phosphor_type, gun_type, deflection_angle, neck_diameter, visible_w, visible_h, visible_diag and displays them between ECID and Dimensions (via update-page on MediaWiki MCP Server)
Add Accessories section, smart remote display (strips redundant brand prefix) (via update-page on MediaWiki MCP Server)
Line 56: Line 56:
fullDiv:wikitext(valueHtmlOrWikitext)
fullDiv:wikitext(valueHtmlOrWikitext)
end
end
end
-- Helper function to extract model code from "Brand Model" format
-- If the accessory starts with the same brand as the CRT, strip it for cleaner display
local function getAccessoryDisplayText(accessoryName, crtBrand)
if not accessoryName then return nil end
if not crtBrand then return accessoryName end
-- Check if accessory name starts with the CRT brand followed by a space
local brandPrefix = crtBrand .. ' '
if accessoryName:sub(1, #brandPrefix) == brandPrefix then
-- Return just the model code portion
return accessoryName:sub(#brandPrefix + 1)
end
-- Otherwise return the full name
return accessoryName
end
end


Line 260: Line 277:
end
end


-- Remote control row: use Accessory form, strip brand prefix if it matches CRT brand
if remote_control then
if remote_control then
local displayText = getAccessoryDisplayText(remote_control, brand)
local remoteWikitext = string.format(
local remoteWikitext = string.format(
'{{#formredlink: target=%s |form=Remote control |existing page link text=%s }}',
'{{#formredlink: target=%s |form=Accessory |existing page link text=%s }}',
remote_control, remote_control
remote_control, displayText
)
)
local remoteHtml = frame:preprocess(remoteWikitext)
local remoteHtml = frame:preprocess(remoteWikitext)
Line 616: Line 635:
addSectionRow(container, 'Control Ports')
addSectionRow(container, 'Control Ports')
addFullRow(container, controlPortsHtml, 'padding:0.2em 0.4em;', true)
addFullRow(container, controlPortsHtml, 'padding:0.2em 0.4em;', true)
end
-- Accessories section: Query for non-remote accessories linked via Has related CRT model
local accessoriesCountWikitext =
'{{#ask:\n' ..
' [[Category:Accessories]]\n' ..
' [[Has related CRT model::' .. fullPageName .. ']]\n' ..
' [[Has accessory type::!Remote control]]\n' ..
' |format=count\n' ..
'}}'
local accessoryCount = frame:preprocess(accessoriesCountWikitext)
local hasAccessories = accessoryCount and tonumber(trim(accessoryCount)) and tonumber(trim(accessoryCount)) > 0
if hasAccessories then
addSectionRow(container, 'Accessories')
local accessoriesDiv = container:tag('div')
css(accessoriesDiv, 'grid-column: 1 / -1; padding:0.2em 0.4em;')
-- Query accessories and display as a list
local accessoriesQueryWikitext =
'{{#ask:\n' ..
' [[Category:Accessories]]\n' ..
' [[Has related CRT model::' .. fullPageName .. ']]\n' ..
' [[Has accessory type::!Remote control]]\n' ..
' |?Has accessory type=type\n' ..
' |?Has model code=model\n' ..
' |?Has description=desc\n' ..
' |format=broadtable\n' ..
' |headers=hide\n' ..
' |link=none\n' ..
'}}'
local accessoriesResult = frame:preprocess(accessoriesQueryWikitext)
-- Parse accessories from broadtable result
local accessories = {}
if accessoriesResult then
for rowContent in accessoriesResult:gmatch('<tr[^>]*>(.-)</tr>') do
local cells = {}
for cellContent in rowContent:gmatch('<td[^>]*>(.-)</td>') do
local cleanContent = cellContent:gsub('<[^>]+>', '')
table.insert(cells, trim(cleanContent))
end
-- cells[1] = page name, cells[2] = type, cells[3] = model code, cells[4] = description
if #cells >= 2 then
local accPageName = cells[1]
local accType = cells[2]
local accModel = cells[3]
local accDesc = cells[4]
if accPageName then
table.insert(accessories, {
page = accPageName,
type = accType,
model = accModel,
desc = accDesc
})
end
end
end
end
if #accessories > 0 then
local ul = accessoriesDiv:tag('ul')
ul:css('margin', '0'):css('padding-left', '1.5em')
for _, acc in ipairs(accessories) do
local li = ul:tag('li')
-- Get display text: strip brand prefix if it matches CRT brand
local displayText = getAccessoryDisplayText(acc.page, brand)
-- Build the display: model code (optionally with description)
local linkText = displayText
if acc.desc and acc.desc ~= '' then
linkText = displayText .. ' – ' .. acc.desc
end
-- Add type prefix in small text
if acc.type then
li:wikitext('<small>' .. acc.type .. ':</small> [[' .. acc.page .. '|' .. linkText .. ']]')
else
li:wikitext('[[' .. acc.page .. '|' .. linkText .. ']]')
end
end
end
end
end


MediaWiki Appliance - Powered by TurnKey Linux