Module:Check for unknown parameters and Module:Check for unknown parameters/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
per edit request (permalink); + require ('strict'); |
No edit summary |
||
Line 2: | Line 2: | ||
-- with a list of arguments, returning a specified result if an argument is |
-- with a list of arguments, returning a specified result if an argument is |
||
-- not on the list |
-- not on the list |
||
require ('strict'); |
|||
local p = {} |
local p = {} |
||
Line 18: | Line 15: | ||
-- Return text cleaned for display and truncated if too long. |
-- Return text cleaned for display and truncated if too long. |
||
-- Strip markers are replaced with dummy text representing the original wikitext. |
-- Strip markers are replaced with dummy text representing the original wikitext. |
||
local |
local truncated |
||
local function truncate(text) |
local function truncate(text) |
||
if truncated then |
if truncated then |
||
Line 30: | Line 27: | ||
end |
end |
||
local parts = {} |
local parts = {} |
||
local pos |
|||
for before, tag, remainder in text:gmatch('([^\127]*)\127[^\127]*%-(%l+)%-[^\127]*\127()') do |
for before, tag, remainder in text:gmatch('([^\127]*)\127[^\127]*%-(%l+)%-[^\127]*\127()') do |
||
pos = remainder |
pos = remainder |
||
Line 38: | Line 36: | ||
end |
end |
||
function |
local function get_values(args, pargs) |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
-- create the list of known args, regular expressions, and the return string |
-- create the list of known args, regular expressions, and the return string |
||
local knownargs = {} |
local knownargs = {} |
||
Line 55: | Line 48: | ||
end |
end |
||
end |
end |
||
-- loop over the parent args, and make sure they are on the list |
-- loop over the parent args, and make sure they are on the list |
||
local ignoreblank = isnotempty(args['ignoreblank']) |
local ignoreblank = isnotempty(args['ignoreblank']) |
||
Line 85: | Line 77: | ||
end |
end |
||
end |
end |
||
return values |
|||
end |
|||
function p._check(args, pargs) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local values = get_values(args, pargs) |
|||
-- add results to the output tables |
-- add results to the output tables |
||
local |
local previews = {} |
||
local categories = {} |
|||
local unknown_category = args['unknown'] |
|||
⚫ | |||
if #values > 0 then |
if #values > 0 then |
||
⚫ | |||
⚫ | |||
if mw.getCurrentFrame():preprocess( "{{REVISIONID}}" ) == "" then |
|||
local preview_text = args['preview'] |
|||
if isnotempty(preview_text) then |
|||
⚫ | |||
elseif preview_text == nil then |
|||
preview_text = unknown_text |
|||
⚫ | |||
unknown_text = preview_text |
|||
end |
|||
for _, v in pairs(values) do |
for _, v in pairs(values) do |
||
-- Fix odd bug for | = which gets stripped to the empty string and |
-- Fix odd bug for | = which gets stripped to the empty string and |
||
Line 106: | Line 102: | ||
-- avoid error with v = 'example%2' ("invalid capture index") |
-- avoid error with v = 'example%2' ("invalid capture index") |
||
local |
local category = unknown_category:gsub('_VALUE_', {_VALUE_ = v}) |
||
local preview = preview_text:gsub('_VALUE_', {_VALUE_ = v}) |
|||
⚫ | |||
table.insert(categories, category) |
|||
⚫ | |||
end |
end |
||
end |
end |
||
return table.concat( |
return table.concat(previews) .. "\n" .. table.concat(categories) |
||
end |
end |
||