Moduł:Sprawdź
Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Sprawdź/opis
return {
["Porōwnej"] = function(frame)
local config = frame:getParent().args[""] or ""
local options = mw.text.split(config, "|")
local templateName = mw.text.trim(options[1])
if #templateName == 0 then
local title = mw.title.getCurrentTitle()
if title.namespace == 10 then
templateName = mw.ustring.match(title.text, "^(.-)/ôpis")
or mw.ustring.match(title.text, "^(.-)/test")
or mw.ustring.match(title.text, "^(.-)/brudnopis")
or title.text
end
if #templateName == 0 then
mw.log("brak miana mustra")
return
end
end
local templateTitle = mw.title.new(templateName, 10)
if templateTitle.id == 0 then
mw.log("szablon '"..templateName.."' niy istniyje")
return
end
local sandboxName = templateName.."/brudnopis"
local sandboxTitle = mw.title.new(sandboxName, 10)
if sandboxTitle.id == 0 then
mw.log("brudnopis '"..sandboxName.."' niy istniyje")
return
end
local i = 2
local showparams = true
local showinfo = true
local vertical = false
while i <= #options do
local option = mw.text.trim(options[i])
if option == "bez wikikodu" then
showparams = false
elseif option == "bez ôpisu" then
showinfo = false
elseif option == "piōnowo" then
vertical = true
end
i = i + 1
end
local templateParams = {}
local params = {}
for k, v in pairs(frame:getParent().args) do
if k ~= "" then
templateParams[k] = v
table.insert(params, k)
end
end
local result = {}
table.insert(result, '<table style="width: 100%;">')
if showparams and (#params > 0) then
local compare = function(a, b)
-- return a < b
if (type(a) == "number") and (type(b) == "number") then
return a < b
end
if (type(a) == "string") and (type(b) == "string") then
return a < b
end
if (type(a) == "number") and (type(b) == "string") then
return true
end
return false
end
table.sort(params, compare)
table.insert(result, "<caption><code>{{")
table.insert(result, templateName)
for i, k in ipairs(params) do
table.insert(result, " | ")
local p = mw.text.nowiki(tostring(k))
local v = mw.text.nowiki(templateParams[k])
table.insert(result, p)
table.insert(result, " = ")
table.insert(result, v)
end
table.insert(result, "}}</code></caption>")
end
local templateResult = frame:expandTemplate{ title=templateName, args=templateParams}
local sandboxResult = frame:expandTemplate{ title=sandboxName, args=templateParams}
if templateResult and string.match(templateResult, "^{|") then
templateResult = "\n"..templateResult
end
if sandboxResult and string.match(sandboxResult, "^{|") then
sandboxResult = "\n"..sandboxResult
end
if vertical and showinfo then
table.insert(result, '<tr><th style="width: 15em">[[Muster:')
table.insert(result, templateName)
table.insert(result, '|Muster]]</th><td>')
table.insert(result, templateResult)
table.insert(result, '</td></tr><tr><th>[[Muster:')
table.insert(result, sandboxName)
table.insert(result, '|Brudnopis mustra]]</th><td>')
table.insert(result, sandboxResult)
table.insert(result, '</td></tr>')
elseif vertical then
table.insert(result, '<tr><td>')
table.insert(result, templateResult)
table.insert(result, '</td></tr><tr><td>')
table.insert(result, sandboxResult)
table.insert(result, '</td></tr>')
else
if showinfo then
table.insert(result, '<tr><th style="width: 50%;">[[Muster:')
table.insert(result, templateName)
table.insert(result, '|Muster]]</th><th style="width: 50%;">[[Muster:')
table.insert(result, sandboxName)
table.insert(result, '|Brudnopis mustra]]</th></tr>')
end
table.insert(result, '<tr style="vertical-align: top;"><td>')
table.insert(result, templateResult)
table.insert(result, '</td><td>')
table.insert(result, sandboxResult)
table.insert(result, '</td></tr>')
end
table.insert(result, "</table>")
return table.concat(result)
end,
["Parametry"] = function(frame)
local unknown = {}
local invalid = {}
local deprecated = {}
local config = frame.args[""]
local class, space, category = string.match(config or "", "^%s*(%S+)(%s+)(.-)%s*$")
local nl = space and string.match(space, "\n") or ""
class = class or config
local function argName(arg)
return type(arg) ~= "string" and tostring(arg) or ('"'..arg..'"')
end
local emptyArg = false
for k, v in pairs(frame:getParent().args) do
local kind = frame.args[k]
if k == "" then
emptyArg = v
elseif not kind then
table.insert(unknown, argName(k))
elseif kind == "num" then
local n = tonumber(v)
if not n then table.insert(invalid, argName(k)) end
elseif kind == "num?" then
local n = (#v == 0) or tonumber(v)
if not n then table.insert(invalid, argName(k)) end
elseif kind == "txt" then
if #v == 0 then table.insert(invalid, argName(k)) end
elseif kind == "old" then
table.insert(deprecated, argName(k))
end
end
if (#unknown == 0) and (#invalid == 0) and (#deprecated == 0) then
return nil
end
local result = mw.html.create("span")
if class then
result:addClass(class)
end
if mw.title.getCurrentTitle().namespace == 0 then
result:css("display", "none")
else
result:css("color", "red")
end
if emptyArg then
result:wikitext("|=", emptyArg, "| ")
end
if #invalid > 0 then
result:wikitext("Niynŏleżne pola: ", mw.text.listToText(invalid), ". ")
end
if #unknown > 0 then
result:wikitext("Niyznōme pola: ", mw.text.listToText(unknown), ". ")
end
if #deprecated > 0 then
result:wikitext("Przestarzałe pola: ", mw.text.listToText(deprecated), ". ")
end
if category then
result:wikitext(category)
end
return nl..tostring(result)
end,
["odn"] = function(frame)
local pf = frame:getParent()
local i = 1
local problems = false
local yeardetected = false
while true do
local arg = pf.args[i]
if not arg then
problems = i == 1 and "brak argumyntōw" or false
break
end
if (i > 5) or yeardetected then
problems = "za moc argumyntōw pozycyjnych"
break
end
if #arg == 0 then
problems = "prōzny argumynt"
break
end
if arg ~= mw.text.trim(arg) then
problems = "niyôczekowane spacyje na poczōntku abo kōńcu argumyntu"
break
end
if string.match(arg, "^%d+%l?$") then
yeardetected = true
if i == 1 then
problems = "rok musi być ôstatnim parametrym po nazwiskach autorōw"
break
end
elseif string.match(arg, "^s[%-%.:]%s*%d+") then
problems = "pewnikym niynŏleznie podany numer strōny"
break
elseif string.match(arg, "%s%s") then
problems = "tuplowane spacyje"
break
elseif mw.ustring.match(arg, "^%a+%d") then
if not mw.ustring.match(arg, "^[%u%d]+$") then
problems = "pewnikym zlepiōne argumynta (brak piōnowyj kryski)"
break
end
elseif mw.ustring.match(arg, "^OdeB ") then
-- [[Ordre de Bataille]]
elseif mw.ustring.match(arg, "^%u%l+%u") then
local justification = {
["De"] = true,
["Del"] = true,
["Di"] = true,
["Le"] = true,
["Mac"] = true,
["Mc"] = true,
["Te"] = true, -- TeSelle
["Sar"] = true, -- SarDesai
["Van"] = true, -- VanBuren
}
if not justification[mw.ustring.match(arg, "^%u%l+")] then
problems = "pewnikym zlepiōne argumynta (brak piōnowyj kryski)"
break
end
end
i = i + 1
end
if not problems then
local odn = pf.args.odn
if odn and ((#odn ~= 1) or (odn < "a") or (odn > "z")) then
problems = "niyôczekowany parameter odn"
end
end
if not problems then
local s = pf.args.s
if s and string.match(s, "&[a-z]+;") then
problems = "użyto yncyje HTML w numerze strōny"
end
end
if not problems then
if pf.args.strona or pf.args.ss or pf.args.strony or pf.args.p or pf.args.page or pf.args.pp or pf.args.pages then
problems = "przestarzały parameter z numerym strōny"
end
end
if not problems then
return nil
end
local result = mw.html.create("span"):addClass("problemy-w-odn")
if mw.title.getCurrentTitle().namespace == 0 then
result:css("display", "none")
result:wikitext("[[Kategoryjo:Muster odn do zweryfikowaniŏ]]")
else
result:css("color", "red")
end
result:wikitext("ODN: ", problems)
return tostring(result)
end,
["Wikidane"] = function(frame)
local property = frame.args.cecha
local field = frame.args.pole
local value = frame.args[1]
if not property or not field then
return
end
if not value then
value = frame:getParent().args[field]
if not value or (#value == 0) then
return
end
end
local entity = mw.wikibase.getEntity()
if not entity or not entity.claims or not entity.claims[property] then
return
end
for i, v in ipairs(entity.claims[property]) do
if v.mainsnak.snaktype == "value" then
if value == v.mainsnak.datavalue.value then
return
end
end
end
local template = frame:getParent():getTitle()
local infobox = mw.ustring.match(template, "^Szablon:(.- infobox)$")
return mw.ustring.format("[[Kategoryjo:%s – niyzgodliwość we Wikidanych – %s – %s]]", infobox and "Infoboksy" or "Mustry", infobox or template, field)
end,
}