Moduł:Brudnopis/MarMi wiki/Test
Przejdź do nawigacji
Przejdź do wyszukiwania
Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Brudnopis/MarMi wiki/Test/opis
local p = {} p["usuńDuplikaty"]=function(ramka) local tabela={} local sep = ramka.args.separator or ';' local regex="[^"..sep.."]+" local wynik = nil for tekst in mw.ustring.gmatch(ramka.args[1], regex) do tabela[tekst]=1 end for elem,jeden in pairs(tabela) do if wynik then wynik=elem..sep..wynik else wynik=elem end end return wynik end function p.testNil(ramka) local args =require('Module:Arguments').getArgs(ramka, {frameOnly = true}) local wart =require('Module:TableTools').compressSparseArray(args) return mw.text.listToText(wart, nil, nil) end function p.testPusty(ramka) local args =require('Module:Arguments').getArgs(ramka, {frameOnly = true}) local wart =require('Module:TableTools').compressSparseArray(args) return mw.text.listToText(wart, '', '') end function p.rawnum(ramka) local args =require('Module:Arguments').getArgs(ramka, {frameOnly = true}) local wart =require('Module:TableTools').compressSparseArray(args)[1] local lang = mw.getContentLanguage() wart=lang:parseFormattedNumber(wart) return wart end function p.preprocess(ramka) local args =require('Module:Arguments').getArgs(ramka, {frameOnly = true}) local wart =require('Module:TableTools').compressSparseArray(args)[1] mw.log(ramka:preprocess(wart)) end local function checkUri(uri) local urilen = #uri for _,v in ipairs(mw.loadData("Moduł:Cytuj/dane").supportedUriSchemas) do if (#v < urilen) and (string.lower(string.sub(uri,1, #v)) == v) then return not string.match(uri, '%s') end end end local function showTemplate(templateName, args) local result = {} local flags = {} table.insert(result, mw.text.nowiki("{{")) if mw.isSubsting() then table.insert(result, "subst:") end local title = mw.title.new(templateName) table.insert(result, '[['..title.nsText) table.insert(result, ":") --szablon if title.namespace == 10 then table.insert(result, title.text..'|') end table.insert(result, title.text..']]') if args then local i = 1 while args[i] do table.insert(result, "|") table.insert(result, mw.text.nowiki(args[i])) i = i + 1 end for k, v in pairs(args) do local index = tonumber(k) if (type(k) == "string") or (index and ((index < 1) or (index > i))) then table.insert(result, "|") table.insert(result, tostring(k)) table.insert(result, "=") table.insert(result, mw.text.nowiki(v)) end end end table.insert(result, mw.text.nowiki("}}")) return table.concat(result) end function p.Parametry(frame) local unknown = {} local invalid = {} local deprecated = {} local nakedurl = {} local templateName = frame:getParent():getTitle() 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 required = {} for k, v in pairs(frame.args) do if mw.ustring.match(v, 'class="error">') then --pominięcie pustego parametru (|=) if k ~= "" then table.insert(invalid, k) table.insert(unknown, v) end end if mw.ustring.match(v, "!$") then required[k] = true end end local emptyArg = false for k, v in pairs(frame:getParent().args) do required[k] = false local kind = frame.args[k] if k == "" then emptyArg = v elseif not kind then table.insert(unknown, argName(k)) elseif (kind == "num") or (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 == "uri") or (kind == "uri!") then local u = checkUri(v) if not u then table.insert(invalid, argName(k)) end elseif kind == "uri?" then local u = (#v == 0) or checkUri(v) if not u then table.insert(invalid, argName(k)) end elseif (kind == "txt") or (kind == "txt!") then if #v == 0 then table.insert(invalid, argName(k)) elseif checkUri(v) then local exception = ((templateName == "Szablon:Cytuj") and ((k == "tytuł") or (k == "url") or (k == "archiwum"))) or ((templateName == "Szablon:Cytuj stronę") and (k == "tytuł")) mw.logObject({v=v,k=k,e=exception},"checkUri: txt") if not exception then table.insert(nakedurl, argName(k)) end end elseif (kind == "text") or (kind == "text!") or (kind == "text?") then if ((kind ~= "text?") and (#v == 0)) or findFile(v) then table.insert(invalid, argName(k)) elseif checkUri(v) then local exception = ((templateName == "Szablon:Cytuj") and (k == "tytuł")) or ((templateName == "Szablon:Cytuj stronę") and (k == "tytuł")) mw.logObject({v=v,k=k,e=exception},"checkUri: txt") if not exception then table.insert(nakedurl, argName(k)) end end elseif kind == "old" then table.insert(deprecated, argName(k)) elseif kind == "uri*" then -- specjalny przpadek dla pola 'url' w [[Szablon:Cytuj]] local u = checkUri(v) or checkUri(mw.text.unstripNoWiki(v)) if not u then table.insert(invalid, argName(k)) end else local pattern = string.match(kind,"^(^.-$)!?$") if pattern and not mw.ustring.match(v, pattern) then table.insert(invalid, argName(k)) elseif (#v > 0) and checkUri(v) then table.insert(nakedurl, argName(k)) end end end local missing = {} for k, v in pairs(required) do if v then table.insert(missing, k) end end if (#missing == 0) and (#unknown == 0) and (#invalid == 0) and (#deprecated == 0) and (#nakedurl == 0) then return nil end if frame.args.nieznane == "wyłącz" then unknown = {} end local message = mw.html.create() if emptyArg then message:wikitext("|=", emptyArg, "| ") end if #missing > 0 then message:wikitext("Brakujące pola: ", mw.text.listToText(missing), ". ") end if #invalid > 0 then message:wikitext("Nieprawidłowe pola: ", mw.text.listToText(invalid), ". ") end if #unknown > 0 then message:wikitext("Nieznane pola: ", mw.text.listToText(unknown), ". ") end if #deprecated > 0 then message:wikitext("Przestarzałe pola: ", mw.text.listToText(deprecated), ". ") end if #nakedurl > 0 then message:wikitext("Gołe linki: ", mw.text.listToText(nakedurl), ". ") end --if templateName then -- showTemplate(templateName, frame:getParent().args) --end message = tostring(message) local result = mw.html.create("span") if class then result:addClass(class) end result:addClass("problemy") if message ~= "" and templateName then result:wikitext(showTemplate(templateName).." ") local warning = mw.html.create() warning:tag("code"):wikitext(showTemplate(templateName, frame:getParent().args)) warning:wikitext(" ") warning:tag("span"):addClass("problemy"):wikitext(message) mw.addWarning(tostring(warning)) end result:wikitext(message) if category then result:wikitext(category) end return nl..tostring(result) end return p