Module:CRTModel: Difference between revisions

Add support for non-standard location values (e.g. "rear/front") by querying for "Other" locations that don't match front/rear/side exactly (via update-page on MediaWiki MCP Server)
Simplify input/output display - show all inputs/outputs with inline location instead of grouping (fixes non-standard location values like rear/front) (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 (or non-standard locations)
local function queryInputsByLocation(frame, fullPageName, location, isOther)
local locationFilter = ''
if isOther then
-- Query for inputs that don't have standard locations
locationFilter = ' [[Has input location::!front]]\n' ..
' [[Has input location::!rear]]\n' ..
' [[Has input location::!side]]\n'
elseif 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' ..
' |?Has input location=location\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 (or non-standard locations)
local function countInputsByLocation(frame, fullPageName, location, isOther)
local locationFilter = ''
if isOther then
-- Count inputs that don't have standard locations
locationFilter = ' [[Has input location::!front]]\n' ..
' [[Has input location::!rear]]\n' ..
' [[Has input location::!side]]\n'
elseif 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 (or non-standard locations)
local function queryOutputsByLocation(frame, fullPageName, location, isOther)
local locationFilter = ''
if isOther then
-- Query for outputs that don't have standard locations
locationFilter = ' [[Has output location::!front]]\n' ..
' [[Has output location::!rear]]\n' ..
' [[Has output location::!side]]\n'
elseif 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' ..
' |?Has output location=location\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 (or non-standard locations)
local function countOutputsByLocation(frame, fullPageName, location, isOther)
local locationFilter = ''
if isOther then
-- Count outputs that don't have standard locations
locationFilter = ' [[Has output location::!front]]\n' ..
' [[Has output location::!rear]]\n' ..
' [[Has output location::!side]]\n'
elseif 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 585: Line 466:
end
end


-- Inputs section: grouped by location (front, rear, side, other)
-- Inputs section: query ALL inputs with location shown inline
local locations = {'front', 'rear', 'side'}
local inputsCountWikitext =
local locationLabels = {front = 'Front', rear = 'Rear', side = 'Side'}
'{{#ask:\n' ..
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
-- Count total inputs across all standard locations plus "other"
' [[Has video signal format::+]]\n' ..
local totalInputs = 0
' |format=count\n' ..
for _, loc in ipairs(locations) do
'}}'
totalInputs = totalInputs + countInputsByLocation(frame, fullPageName, loc, false)
local inputCount = frame:preprocess(inputsCountWikitext)
end
local hasInputs = inputCount and tonumber(trim(inputCount)) and tonumber(trim(inputCount)) > 0
-- Also count inputs with non-standard locations
local otherInputCount = countInputsByLocation(frame, fullPageName, nil, true)
totalInputs = totalInputs + otherInputCount
local hasInputs = totalInputs > 0
if hasInputs then
if hasInputs then
local askWikitext =
'{{#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' ..
' |?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 askHtml = frame:preprocess(askWikitext)
addSectionRow(container, 'Inputs')
addSectionRow(container, 'Inputs')
addFullRow(container, askHtml, 'padding:0.2em 0.4em;', true)
local inputsContent = ''
-- Standard locations
for _, loc in ipairs(locations) do
local count = countInputsByLocation(frame, fullPageName, loc, false)
if count > 0 then
local locInputs = queryInputsByLocation(frame, fullPageName, loc, false)
if locInputs and locInputs ~= '' then
inputsContent = inputsContent .. "<div style='margin-bottom:0.3em;'><strong>" .. locationLabels[loc] .. "</strong><br/>" .. locInputs .. "</div>"
end
end
end
-- Non-standard locations (e.g., "rear/front", "multiple", etc.)
if otherInputCount > 0 then
local otherInputs = queryInputsByLocation(frame, fullPageName, nil, true)
if otherInputs and otherInputs ~= '' then
inputsContent = inputsContent .. "<div style='margin-bottom:0.3em;'><strong>Multiple</strong><br/>" .. otherInputs .. "</div>"
end
end
if inputsContent ~= '' then
addFullRow(container, inputsContent, 'padding:0.2em 0.4em;', true)
end
end
end


-- Outputs section: grouped by location
-- Outputs section: query ALL outputs with location shown inline
local totalOutputs = 0
local outputsCountWikitext =
for _, loc in ipairs(locations) do
'{{#ask:\n' ..
totalOutputs = totalOutputs + countOutputsByLocation(frame, fullPageName, loc, false)
' [[Has CRT model::' .. fullPageName .. ']]\n' ..
end
' [[Has output signal format::+]]\n' ..
-- Also count outputs with non-standard locations
' |format=count\n' ..
local otherOutputCount = countOutputsByLocation(frame, fullPageName, nil, true)
'}}'
totalOutputs = totalOutputs + otherOutputCount
local outputCount = frame:preprocess(outputsCountWikitext)
local hasOutputs = outputCount and tonumber(trim(outputCount)) and tonumber(trim(outputCount)) > 0
local hasOutputs = totalOutputs > 0
if hasOutputs then
if hasOutputs then
local outputsAskWikitext =
'{{#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')
addSectionRow(container, 'Outputs')
addFullRow(container, outputsHtml, 'padding:0.2em 0.4em;', true)
local outputsContent = ''
-- Standard locations
for _, loc in ipairs(locations) do
local count = countOutputsByLocation(frame, fullPageName, loc, false)
if count > 0 then
local locOutputs = queryOutputsByLocation(frame, fullPageName, loc, false)
if locOutputs and locOutputs ~= '' then
outputsContent = outputsContent .. "<div style='margin-bottom:0.3em;'><strong>" .. locationLabels[loc] .. "</strong><br/>" .. locOutputs .. "</div>"
end
end
end
-- Non-standard locations
if otherOutputCount > 0 then
local otherOutputs = queryOutputsByLocation(frame, fullPageName, nil, true)
if otherOutputs and otherOutputs ~= '' then
outputsContent = outputsContent .. "<div style='margin-bottom:0.3em;'><strong>Multiple</strong><br/>" .. otherOutputs .. "</div>"
end
end
if outputsContent ~= '' then
addFullRow(container, outputsContent, 'padding:0.2em 0.4em;', true)
end
end
end


MediaWiki Appliance - Powered by TurnKey Linux