Module:CRTModel: Difference between revisions

Add Control Ports section to infobox rendering (via update-page on MediaWiki MCP Server)
Add audio properties to input queries and group inputs/outputs by location (Front, Rear, Side) (via update-page on MediaWiki MCP Server)
Line 56: Line 56:
fullDiv:wikitext(valueHtmlOrWikitext)
fullDiv:wikitext(valueHtmlOrWikitext)
end
end
end
-- Helper to query inputs for a specific location
local function queryInputsByLocation(frame, fullPageName, location)
local locationFilter = ''
if location then
locationFilter = ' [[Has input location::' .. location .. ']]\n'
end
local queryWikitext =
'{{#ask:\n' ..
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
' [[Has video signal format::+]]\n' ..
locationFilter ..
' |?Has video signal format=signal\n' ..
' |?Has connector type=connector\n' ..
' |?Has input count=count\n' ..
' |?Has audio type=audio\n' ..
' |?Has audio connector=audio_connector\n' ..
' |?Has audio shared with=audio_shared\n' ..
' |format=ul\n' ..
' |template=CRT input inline\n' ..
' |named args=yes\n' ..
' |link=none\n' ..
' |searchlabel=\n' ..
'}}'
local result = frame:preprocess(queryWikitext)
return trim(result)
end
-- Helper to count inputs for a specific location
local function countInputsByLocation(frame, fullPageName, location)
local locationFilter = ''
if location then
locationFilter = ' [[Has input location::' .. location .. ']]\n'
end
local countWikitext =
'{{#ask:\n' ..
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
' [[Has video signal format::+]]\n' ..
locationFilter ..
' |format=count\n' ..
'}}'
local result = frame:preprocess(countWikitext)
local count = tonumber(trim(result)) or 0
return count
end
-- Helper to query outputs for a specific location
local function queryOutputsByLocation(frame, fullPageName, location)
local locationFilter = ''
if location then
locationFilter = ' [[Has output location::' .. location .. ']]\n'
end
local queryWikitext =
'{{#ask:\n' ..
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
' [[Has output signal format::+]]\n' ..
locationFilter ..
' |?Has output type=type\n' ..
' |?Has output signal format=signal\n' ..
' |?Has output connector=connector\n' ..
' |?Has output count=count\n' ..
' |?Has output label=label\n' ..
' |format=ul\n' ..
' |template=CRT output inline\n' ..
' |named args=yes\n' ..
' |link=none\n' ..
' |searchlabel=\n' ..
'}}'
local result = frame:preprocess(queryWikitext)
return trim(result)
end
-- Helper to count outputs for a specific location
local function countOutputsByLocation(frame, fullPageName, location)
local locationFilter = ''
if location then
locationFilter = ' [[Has output location::' .. location .. ']]\n'
end
local countWikitext =
'{{#ask:\n' ..
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
' [[Has output signal format::+]]\n' ..
locationFilter ..
' |format=count\n' ..
'}}'
local result = frame:preprocess(countWikitext)
local count = tonumber(trim(result)) or 0
return count
end
end


Line 466: Line 563:
end
end


-- Inputs section: use count query to check if there are any inputs
-- Inputs section: grouped by location
local inputsCountWikitext =
local locations = {'front', 'rear', 'side'}
'{{#ask:\n' ..
local locationLabels = {front = 'Front', rear = 'Rear', side = 'Side'}
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
' [[Has video signal format::+]]\n' ..
-- Count total inputs
' |format=count\n' ..
local totalInputs = 0
'}}'
for _, loc in ipairs(locations) do
local inputCount = frame:preprocess(inputsCountWikitext)
totalInputs = totalInputs + countInputsByLocation(frame, fullPageName, loc)
local hasInputs = inputCount and tonumber(trim(inputCount)) and tonumber(trim(inputCount)) > 0
end
local hasInputs = totalInputs > 0
if hasInputs then
if hasInputs then
local askWikitext =
addSectionRow(container, 'Inputs')
'{{#ask:\n' ..
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
' [[Has video signal format::+]]\n' ..
' |?Has video signal format=signal\n' ..
' |?Has connector type=connector\n' ..
' |?Has input count=count\n' ..
' |?Has input location=location\n' ..
' |format=ul\n' ..
' |template=CRT input inline\n' ..
' |named args=yes\n' ..
' |link=none\n' ..
' |searchlabel=\n' ..
'}}'
local askHtml = frame:preprocess(askWikitext)
addSectionRow(container, 'Inputs')
local inputsContent = ''
addFullRow(container, askHtml, 'padding:0.2em 0.4em;', true)
for _, loc in ipairs(locations) do
local count = countInputsByLocation(frame, fullPageName, loc)
if count > 0 then
local locInputs = queryInputsByLocation(frame, fullPageName, loc)
if locInputs and locInputs ~= '' then
inputsContent = inputsContent .. "<div style='margin-bottom:0.3em;'><strong>" .. locationLabels[loc] .. "</strong><br/>" .. locInputs .. "</div>"
end
end
end
if inputsContent ~= '' then
addFullRow(container, inputsContent, 'padding:0.2em 0.4em;', true)
end
end
end


-- Outputs section: use count query to check if there are any outputs
-- Outputs section: grouped by location
local outputsCountWikitext =
local totalOutputs = 0
'{{#ask:\n' ..
for _, loc in ipairs(locations) do
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
totalOutputs = totalOutputs + countOutputsByLocation(frame, fullPageName, loc)
' [[Has output signal format::+]]\n' ..
end
' |format=count\n' ..
local hasOutputs = totalOutputs > 0
'}}'
local outputCount = frame:preprocess(outputsCountWikitext)
local hasOutputs = outputCount and tonumber(trim(outputCount)) and tonumber(trim(outputCount)) > 0
if hasOutputs then
if hasOutputs then
local outputsAskWikitext =
addSectionRow(container, 'Outputs')
'{{#ask:\n' ..
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
' [[Has output signal format::+]]\n' ..
' |?Has output type=type\n' ..
' |?Has output signal format=signal\n' ..
' |?Has output connector=connector\n' ..
' |?Has output count=count\n' ..
' |?Has output label=label\n' ..
' |?Has output location=location\n' ..
' |format=ul\n' ..
' |template=CRT output inline\n' ..
' |named args=yes\n' ..
' |link=none\n' ..
' |searchlabel=\n' ..
'}}'
local outputsHtml = frame:preprocess(outputsAskWikitext)
addSectionRow(container, 'Outputs')
local outputsContent = ''
addFullRow(container, outputsHtml, 'padding:0.2em 0.4em;', true)
for _, loc in ipairs(locations) do
local count = countOutputsByLocation(frame, fullPageName, loc)
if count > 0 then
local locOutputs = queryOutputsByLocation(frame, fullPageName, loc)
if locOutputs and locOutputs ~= '' then
outputsContent = outputsContent .. "<div style='margin-bottom:0.3em;'><strong>" .. locationLabels[loc] .. "</strong><br/>" .. locOutputs .. "</div>"
end
end
end
if outputsContent ~= '' then
addFullRow(container, outputsContent, 'padding:0.2em 0.4em;', true)
end
end
end


MediaWiki Appliance - Powered by TurnKey Linux