Module:Check for unknown parameters: Difference between revisions
m
1 revision imported from wikipedia:Module:Check_for_unknown_parameters
m (1 revision imported from wikipedia:Module:Check_for_unknown_parameters) |
|||
(9 intermediate revisions by 8 users not shown) | |||
Line 9:
local function isnotempty(s)
return s and
end
local function clean(text)
function p.check (frame)▼
-- Return text cleaned for display and truncated if too long.
local args = frame.args▼
-- Strip markers are replaced with dummy text representing the original wikitext.
local pargs = frame:getParent().args▼
local pos, truncated
local ignoreblank = isnotempty(frame.args['ignoreblank'])▼
local function truncate(text)
local showblankpos = isnotempty(frame.args['showblankpositional'])▼
if truncated then
local knownargs = {}▼
return ''
local unknown = frame.args['unknown'] or 'Found _VALUE_, '▼
end▼
local preview = frame.args['preview']▼
truncated = true
return mw.text.nowiki(text)
end
for before, tag, remainder in text:gmatch('([^\127]*)\127[^\127]*%-(%l+)%-[^\127]*\127()') do
pos = remainder
table.insert(parts, truncate(before) .. '<' .. tag .. '>...</' .. tag .. '>')
end
table.insert(parts, truncate(text:sub(pos or 1)))
return table.concat(parts)
end
function p._check(args, pargs)
local values = {}▼
if type(args) ~= "table" or type(pargs) ~= "table" then
▲ local res = {}
-- TODO: error handling
local regexps = {}▼
return
end
-- create the list of known args, regular expressions, and the return string
▲ local knownargs = {}
▲ local regexps = {}
for k, v in pairs(args) do
if type(k) == 'number' then
Line 33 ⟶ 51:
table.insert(regexps, '^' .. v .. '$')
end
▲ end
elseif preview == nil then▼
end
-- loop over the parent args, and make sure they are on the list
▲ local values = {}
for k, v in pairs(pargs) do
if type(k) == 'string' and knownargs[k] == nil then
local knownflag = false
for
if mw.ustring.match(k, regexp) then
knownflag = true
Line 51 ⟶ 67:
end
if not knownflag and ( not ignoreblank or isnotempty(v) ) then
table.insert(values, clean(k))▼
end
▲ table.insert(values, k)
elseif type(k) == 'number' and knownargs[tostring(k)] == nil then▼
local knownflag = false
if mw.ustring.match(tostring(k), regexp) then
knownflag = true
break
end
end
if not knownflag and ( showblankpos or isnotempty(v) ) then▼
end
▲ elseif type(k) == 'number' and
▲ ( showblankpos or isnotempty(v) )
▲ local vlen = mw.ustring.len(v)
▲ v = mw.ustring.sub(v, 1, (vlen < 25) and vlen or 25)
▲ table.insert(values, k .. ' = ' .. v .. ((vlen >= 25) and ' ...' or ''))
end
end
-- add
local res = {}
if #values > 0 then
if frame:preprocess( "{{REVISIONID}}" ) == "" then▼
▲ end
▲ for k, v in pairs(values) do
if
preview_text = require('Module:If preview')._warning({preview_text})
-- Fix odd bug for | = which gets stripped to the empty string and▼
-- breaks category links▼
end
unknown_text = preview_text
end
for _, v in pairs(values) do
if v == '' then v = ' ' end
-- avoid error with v = 'example%2' ("invalid capture index")
local r =
table.insert(res, r)
end
Line 83 ⟶ 109:
return table.concat(res)
end
▲ local args = frame.args
▲ local pargs = frame:getParent().args
return p._check(args, pargs)
end
|