Module:BrandSeries: Difference between revisions
Remove Unassigned row - handled by template italicized line instead (via update-page on MediaWiki MCP Server) |
Add clickable Unassigned row linking to Special:Ask query (via update-page on MediaWiki MCP Server) |
||
| Line 10: | Line 10: | ||
s = s:gsub('^%s+', ''):gsub('%s+$', '') | s = s:gsub('^%s+', ''):gsub('%s+$', '') | ||
if s == '' then return nil end | if s == '' then return nil end | ||
return s | |||
end | |||
-- Encode a string for use in Special:Ask URL path | |||
local function encodeForAsk(s) | |||
-- Special:Ask uses a custom encoding: [ = -5B, ] = -5D, space = _ | |||
s = s:gsub('%[', '-5B') | |||
s = s:gsub('%]', '-5D') | |||
s = s:gsub(' ', '_') | |||
s = s:gsub('%+', '-2B') | |||
return s | return s | ||
end | end | ||
| Line 57: | Line 67: | ||
end | end | ||
end | end | ||
-- Query count of models with NO series assigned | |||
local unassignedQuery = string.format( | |||
'{{#ask:[[Category:CRT models]][[Has brand::%s]][[Has series::!+]]|format=count}}', | |||
brand | |||
) | |||
local unassignedResult = frame:preprocess(unassignedQuery) | |||
local unassignedCount = tonumber(trim(unassignedResult)) or 0 | |||
-- Convert to sorted array | -- Convert to sorted array | ||
| Line 70: | Line 88: | ||
table.sort(rows, function(a, b) return a.series < b.series end) | table.sort(rows, function(a, b) return a.series < b.series end) | ||
-- If no series found, return nothing | -- If no series found and no unassigned, return nothing | ||
if #rows == 0 then | if #rows == 0 and unassignedCount == 0 then | ||
return "" | return "" | ||
end | end | ||
| Line 85: | Line 103: | ||
table.insert(lines, '|-') | table.insert(lines, '|-') | ||
table.insert(lines, '| ' .. seriesLink .. ' || ' .. tostring(row.count)) | table.insert(lines, '| ' .. seriesLink .. ' || ' .. tostring(row.count)) | ||
end | |||
-- Unassigned row (if any) with link to Special:Ask | |||
if unassignedCount > 0 then | |||
-- Build Special:Ask URL for unassigned models | |||
local askQuery = string.format('[[Category:CRT models]][[Has brand::%s]][[Has series::!+]]', brand) | |||
local askUrl = '/wiki/Special:Ask/' .. encodeForAsk(askQuery) | |||
local unassignedLink = string.format("[%s ''(Unassigned)'']", askUrl) | |||
table.insert(lines, '|-') | |||
table.insert(lines, '| ' .. unassignedLink .. ' || ' .. tostring(unassignedCount)) | |||
end | end | ||