Moduł:Sprawdź

Z VatoWiki
Wersja z dnia 10:08, 22 cze 2016 autorstwa Admin (dyskusja | edycje) (1 wersja)
(różn.) ← poprzednia wersja | przejdź do aktualnej wersji (różn.) | następna wersja → (różn.)
Przejdź do nawigacji Przejdź do wyszukiwania

return { ["Porównaj"] = 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, "^(.-)/opis") 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 nazwy szablonu") return end end

local templateTitle = mw.title.new(templateName, 10) if templateTitle.id == 0 then mw.log("szablon '"..templateName.."' nie istnieje") return end

local sandboxName = templateName.."/brudnopis" local sandboxTitle = mw.title.new(sandboxName, 10) if sandboxTitle.id == 0 then mw.log("brudnopis '"..sandboxName.."' nie istnieje") 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 opisu" then showinfo = false elseif option == "pionowo" 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, '

') 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, "") 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, '') elseif vertical then table.insert(result, '') else if showinfo then table.insert(result, '') end table.insert(result, '') end table.insert(result, "
{{") 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, "}}
[[Szablon:')

table.insert(result, templateName)

table.insert(result, '|Szablon]]
')

table.insert(result, templateResult)

table.insert(result, '
[[Szablon:')

table.insert(result, sandboxName)

table.insert(result, '|Brudnopis szablonu]]
')

table.insert(result, sandboxResult)

table.insert(result, '
')

table.insert(result, templateResult)

table.insert(result, '
')

table.insert(result, sandboxResult)

table.insert(result, '
[[Szablon:')

table.insert(result, templateName)

table.insert(result, '|Szablon]]
[[Szablon:')

table.insert(result, sandboxName)

table.insert(result, '|Brudnopis szablonu]]
')

table.insert(result, templateResult)

table.insert(result, '
')

table.insert(result, sandboxResult)

table.insert(result, '

")

return table.concat(result) end,

["Parametry"] = function(frame) local unknown = {} local invalid = {} local deprecated = {} local config = frame.args[""] local class, category = string.match(frame.args[""] or "", "^%s*(%S+)%s+(.-)%s*$") if not class then class = config end

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("Nieprawidłowe pola: ", mw.text.listToText(invalid), ". ") end

if #unknown > 0 then result:wikitext("Nieznane 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 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 argumentów" or false break end

if (i > 5) or yeardetected then problems = "za dużo argumentów pozycyjnych" break end

if #arg == 0 then problems = "pusty argument" break end

if arg ~= mw.text.trim(arg) then problems = "nieoczekiwane odstępy na początku lub końcu argumentu" break end

if string.match(arg, "^%d+%l?$") then yeardetected = true if i == 1 then problems = "rok musi być ostatnim parametrem po nazwiskach autorów" break end elseif string.match(arg, "^s[%-%.:]%s*%d+") then problems = "prawdopodobnie nieprawidłowo podany numer strony" break elseif string.match(arg, "%s%s") then problems = "podwójne odstępy" break elseif mw.ustring.match(arg, "^%a+%d") then if not mw.ustring.match(arg, "^[%u%d]+$") then problems = "prawdopodobnie sklejone argumenty (brak pionowej kreski)" break end 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 } if not justification[mw.ustring.match(arg, "^%u%l+")] then problems = "prawdopodobnie sklejone argumenty (brak pionowej kreski)" 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 = "nieoczekiwany parametr odn" end end

if not problems then local s = pf.args.s if s and string.match(s, "&[a-z]+;") then problems = "użyto encji HTML w numerze strony" 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 parametr z numerem strony" 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("") else result:css("color", "red") end result:wikitext("ODN: ", problems) return tostring(result) end,

}