Module:BrandSeries: Difference between revisions

Fix: preprocess final wikitext output to render links and table (via update-page on MediaWiki MCP Server)
Rewrite using HTML builder like CRTModel; fix count parsing (via update-page on MediaWiki MCP Server)
Line 31: Line 31:
if not seriesResult or seriesResult == '' then
if not seriesResult or seriesResult == '' then
return "''No series found.''"
return "<i>No series found.</i>"
end
end
Line 57: Line 57:
if count > 0 then
if count > 0 then
-- Build browse link and preprocess it
local browseLink = string.format(
'{{#queryformlink:form=CRT query|query string=CRT query[brand]=%s&CRT query[series]=%s&_run|link text=Browse}}',
brand, series
)
local browseHtml = frame:preprocess(browseLink)
table.insert(rows, {
table.insert(rows, {
series = series,
series = series,
count = count
count = count,
browse = browseHtml
})
})
end
end
Line 66: Line 74:
-- If no series found for this brand
-- If no series found for this brand
if #rows == 0 then
if #rows == 0 then
return "''No series-assigned models for this brand.''"
return "<i>No series-assigned models for this brand.</i>"
end
end
-- Build the table as wikitext
-- Build the table as HTML
local output = {}
local tbl = mw.html.create('table')
table.insert(output, '{| class="wikitable"')
tbl:addClass('wikitable')
table.insert(output, '|-')
table.insert(output, '! Series !! Count !! Browse')
-- Header row
local headerRow = tbl:tag('tr')
headerRow:tag('th'):wikitext('Series')
headerRow:tag('th'):wikitext('Count')
headerRow:tag('th'):wikitext('Browse')
-- Data rows
for _, row in ipairs(rows) do
for _, row in ipairs(rows) do
table.insert(output, '|-')
local tr = tbl:tag('tr')
-- Build browse link inline
tr:tag('td'):wikitext('[[' .. row.series .. ']]')
local browseLink = string.format(
tr:tag('td'):wikitext(tostring(row.count))
'{{#queryformlink:form=CRT query|query string=CRT query[brand]=%s&CRT query[series]=%s&_run|link text=Browse}}',
tr:tag('td'):wikitext(row.browse)
brand, row.series
)
table.insert(output, string.format('| [[%s]] || %d || %s', row.series, row.count, browseLink))
end
end
table.insert(output, '|}')
return tostring(tbl)
-- Preprocess the entire output to render wikitext
return frame:preprocess(table.concat(output, '\n'))
end
end


return p
return p
MediaWiki Appliance - Powered by TurnKey Linux