Модуль:Check for unknown parameters: відмінності між версіями

[перевірена версія][перевірена версія]
Вилучено вміст Додано вміст
Немає опису редагування
шо то було?
Рядок 2:
-- with a list of arguments, returning a specified result if an argument is
-- not on the list
-- modified at ukwiki
local p = {}
 
local function trim(s)
return s:match('^%s*(.-)%s*$')
end
 
local function isnotempty(s)
return s and s:matchtrim(s) ~= '%S')
end
 
local function cleanp.check (textframe)
local args = frame.args
-- Return text cleaned for display and truncated if too long.
local pargs = frame:getParent().args
-- Strip markers are replaced with dummy text representing the original wikitext.
local ignoreblank = isnotempty(frame.args['ignoreblank'])
local pos, truncated
local showblankpos = isnotempty(frame.args['showblankpositional'])
local function truncate(text)
local knownargs = {}
if truncated then
local unknown = frame.args['unknown'] or '<s>|_VALUE_=</s>, '-- якщо не задано
return ''
local preview = frame.args['preview'] or '<s>|_VALUE_=</s>, '-- завжди попередж. в прев'ю
end
local values = {}
if mw.ustring.len(text) > 25 then
local res = {}
truncated = true
local regexps = {}
text = mw.ustring.sub(text, 1, 25) .. '...'
local revisionid = isnotempty( frame:preprocess( "{{REVISIONID}}" ) )
end
local function nounderscore( pargs )
return mw.text.nowiki(text)
for k, v in pairs(pargs) do
end
k = mw.ustring.gsub(k, '[_]', ' ')
local parts = {}
end
for before, tag, remainder in text:gmatch('([^\127]*)\127[^\127]*%-(%l+)%-[^\127]*\127()') do
return pargs
pos = remainder
end
table.insert(parts, truncate(before) .. '&lt;' .. tag .. '&gt;...&lt;/' .. tag .. '&gt;')
-- create the list of known args, regular expressions, and the return string
end
for k, v in pairs(args) do
table.insert(parts, truncate(text:sub(pos or 1)))
if type(k) == 'number' then
return table.concat(parts)
v = trim(v)
end
knownargs[v] = 1
 
elseif k:find('^regexp[1-9][0-9]*$') then
function p._check(args, pargs)
table.insert(regexps, '^' .. v .. '$')
if type(args) ~= "table" or type(pargs) ~= "table" then
end
-- TODO: error handling
end
return
if not isnotempty(preview) then preview = unknown end
end
-- loop over the parent args, and make sure they are on the list
 
for k, v in pairs(pargs) do
local ignoreblank = isnotempty(args['ignoreblank'])
if type(k) == 'string' and knownargs[k] == nil then
local showblankpos = isnotempty(args['showblankpositional'])
local knownargsknownflag = {}false
for i, regexp in ipairs(regexps) do
local unknown = args['unknown'] or 'Found _VALUE_, '
if mw.ustring.match(k, regexp) then
local preview = args['preview']
knownflag = true
 
break
local values = {}
end
local res = {}
end
local regexps = {}
if not knownflag and ( not ignoreblank or isnotempty(v) ) then
 
k = mw.ustring.gsub(k, '[^%w\-_ ]', '?')
-- create the list of known args, regular expressions, and the return string
table.insert(values, k)
for k, v in pairs(args) do
end
if type(k) == 'number' then
elseif type(k) == 'number' and knownargs[tostring(k)] == nil and ( showblankpos or isnotempty(v) ) then
v = trim(v)
local vlen = mw.ustring.len(v)
knownargs[v] = 1
v = mw.ustring.sub(v, 1, (vlen < 25) and vlen or 25)
elseif k:find('^regexp[1-9][0-9]*$') then
v = mw.ustring.gsub(v, '[^%w\-_ ]', '?')
table.insert(regexps, '^' .. v .. '$')
table.insert(values, k .. ' = ' .. v .. ((vlen >= 25) and ' ...' or ''))
end
end
end
if isnotempty(preview) then
-- add resuls to the output tables
preview = '<div class="hatnote" style="color:red"><strong>Warning:</strong> ' .. preview .. ' (this message is shown only in preview).</div>'
elseif preview ==if nil#values > 0 then
if not revisionid then unknown = preview
preview = unknown
end
for k, v in pairs(values) do
 
-- loopFix overodd thebug parentfor args,| and= makewhich suregets theystripped are onto the listempty string and
-- breaks category links
for k, v in pairs(pargs) do
if type(k)v == 'string' andthen knownargs[k]v == nil' then' end
local r = unknown:gsub('_VALUE_', v)
local knownflag = false
table.insert(res, r)
for _, regexp in ipairs(regexps) do
end
if mw.ustring.match(k, regexp) then
if not revisionid then
knownflag = true
table.insert(res, 1, '<div class="hatnote" style="color:red; border:1px dashed pink; border-radius:10px;"><strong>Увага:</strong> {{[['
break
.. tostring(mw.getCurrentFrame():getParent():getTitle()) .. ']]}}: не розумію параметр(и):<br/><span style="font-color:black;font-size:85%;">')
end
table.insert(res, '</span><br/>(це повідомлення лише в попередперегляді). [[Вікіпедія:Проект:Шаблони#Параметри шаблонів|Докладніше]]</div>')
end
end
if not knownflag and ( not ignoreblank or isnotempty(v) ) then
end
table.insert(values, clean(k))
return table.concat(res)
end
elseif type(k) == 'number' and
knownargs[tostring(k)] == nil and
( showblankpos or isnotempty(v) )
then
table.insert(values, k .. ' = ' .. clean(v))
end
end
 
-- add results to the output tables
if #values > 0 then
if mw.getCurrentFrame():preprocess( "{{REVISIONID}}" ) == "" then
unknown = preview
end
for _, v in pairs(values) do
if v == '' then
-- Fix odd bug for | = which gets stripped to the empty string and
-- breaks category links
v = ' '
end
-- avoid error with v = 'example%2' ("invalid capture index")
local r = unknown:gsub('_VALUE_', {_VALUE_ = v})
table.insert(res, r)
end
end
 
return table.concat(res)
end
 
function p.check(frame)
local args = frame.args
local pargs = frame:getParent().args
return p._check(args, pargs)
end