Module:SMWUtils: Difference between revisions
Add mainlabel support to include subject/page name column in output (via update-page on MediaWiki MCP Server) |
Fix deduplication: key on printout columns instead of subject (subobject subjects are unique per-input) (via update-page on MediaWiki MCP Server) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 40: | Line 40: | ||
if not s then return nil end | if not s then return nil end | ||
return trim(s:gsub('<[^>]+>', ''):gsub('&[^;]+;', '')) | return trim(s:gsub('<[^>]+>', ''):gsub('&[^;]+;', '')) | ||
end | |||
-- Deduplicate rows by printout columns, keeping the first occurrence | |||
-- Uses stripped text of printout columns (2..n+1) as the dedup key, | |||
-- since subobject queries produce unique subjects (e.g. Page#sub1, Page#sub2) | |||
-- but identical printout values for the same parent page | |||
local function deduplicateRows(rows, numPrintouts) | |||
local seen = {} | |||
local deduped = {} | |||
for _, row in ipairs(rows) do | |||
local keyParts = {} | |||
for j = 2, numPrintouts + 1 do | |||
table.insert(keyParts, stripHtml(row[j]) or '') | |||
end | |||
local key = table.concat(keyParts, '|') | |||
if not seen[key] then | |||
seen[key] = true | |||
table.insert(deduped, row) | |||
end | |||
end | |||
return deduped | |||
end | end | ||
| Line 176: | Line 197: | ||
end | end | ||
end | end | ||
-- Deduplicate (multiple subobjects on same page produce duplicate rows) | |||
filtered = deduplicateRows(filtered, #printoutProps) | |||
-- Build headers list | -- Build headers list | ||
| Line 254: | Line 278: | ||
end | end | ||
end | end | ||
-- Deduplicate (multiple subobjects on same page produce duplicate rows) | |||
filtered = deduplicateRows(filtered, #printoutProps) | |||
-- Build headers list | -- Build headers list | ||