Moduł:Sprawdź
Przejdź do nawigacji
Przejdź do wyszukiwania
Ten moduł zapewnia platformę programistyczną dla tworzenia szablonów budujących przypadki testowe szablonów Wikibooksa. Przypadki testowe mogą być tworzone ręcznie, aczkolwiek te tworzone za pomocą szablonów opartych na module Lua, takim jak niniejszy moduł, mają taką zaletę, że argumenty szablonu muszą być wprowadzone jedynie jednokrotnie, co zmniejsza nakład pracy konieczny do tworzenia testów, a także zmniejsza ryzyko występowania błędów w danych wejściowych.
Porównaj[edytuj]
Ta funkcja jest obecnie wykorzystywana przez szablon {{Przypadek testowy}}.
Parametry[edytuj]
Funkcja do wykrywania wywołań szablonów z nierozpoznanymi, pustymi lub przestarzałymi parametrami. Należy ją wywołać ze wszystkimi możliwymi parametrami jakie przyjmuje szablon podlegający sprawdzaniu.
- Opis parametrów
pole | opis | status | uwagi |
---|---|---|---|
bez nazwy | konfiguracja działania | wymagany | klasa lub klasa odstęp suffix |
inny | deklaracja pola obsługiwanego w szablonie | opcjonalny | txt, num, num?, uri, uri?, old, ^…$ lub pusty |
- Konfiguracja
- klasa – ciąg znaków bez spacji umieszczany jako wartość atrybutu class w tagu <span> z wygenerowanym raportem
- odstęp – ciąg znaków odstępu oddzielający pozostałą treść konfiguracji, jeśli zawiera znak nowej linii to przed wygenerowanym raportem jest również umieszczany znak nowej linii
- suffix – treść dołączana po wygenerowanym raporcie, zwykle deklaracja technicznej kategorii
- Sprawdzanie parametrów
- pusty – parametr jest opcjonalny, jest to najczęściej stosowany sposób użycia
- txt – oczekiwany jest dowolna niepusta wartość pola
- num – sprawdzanie czy przekazana wartość jest liczbą
- num? – sprawdzanie czy przekazana wartość jest pusta lub jest liczbą
- uri – sprawdzanie czy przekazana wartość jest linkiem obsługiwanym przez MediaWiki
- uri? – sprawdzanie czy przekazana wartość jest pusta lub jest linkiem
- old – informuje, że przekazywany parametr jest przestarzały
- ^…$ – tekst rozpoczynający się znakiem
^
i zakończony na$
w całości traktowany jest jako wyrażenie regularne Lua wskazującego prawidłowy parametr
- Przykład
- {{#invoke:Sprawdź|Parametry|=problemy-w-szablonie [[Kategoria:Błędy wywołań w szablonie]]|argument1=|argument2=}}
odn[edytuj]
Funkcja sprawdzająca prawidłowość parametrów w {{odn}}.
Powyższy opis jest dołączany ze strony Moduł:Sprawdź/opis. (edytuj | historia)
Zobacz podstrony tego modułu. |
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
return {
["SprawdźURL"]=function(uri)
return checkUri(uri);
end,
["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, '<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">[[Szablon:')
table.insert(result, templateName)
table.insert(result, '|Szablon]]</th><td>')
table.insert(result, templateResult)
table.insert(result, '</td></tr><tr><th>[[Szablon:')
table.insert(result, sandboxName)
table.insert(result, '|Brudnopis szablonu]]</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%;">[[Szablon:')
table.insert(result, templateName)
table.insert(result, '|Szablon]]</th><th style="width: 50%;">[[Szablon:')
table.insert(result, sandboxName)
table.insert(result, '|Brudnopis szablonu]]</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 pf=frame:getParent();
local unknown = {}
local invalid = {}
local deprecated = {}
local templateName;
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 ramka_modul=require("Module:Ramka");
local tabelka1=ramka_modul.RozpakujArgumenty(frame.args["bez argumentów szablonu"]);
local tabelka2=ramka_modul.RozpakujArgumenty(pf.args["bez argumentów szablonu"]);
local parametry_modul=require("Module:Parametry");
local tabelka_bez_argumentow=parametry_modul["ŁączDwieTabele"](tabelka1,tabelka2)
local required = {}
local repeated = {}
local tabelka_argumentow_systemowych_funkcji={
["nazwa przestrzeni nazw"]="",
["nazwa jednostki"]="txt",
["typ jednostki"]="txt",
["strona główna dla dzieci"]="txt",
["strona główna projektu"]="txt",
["usuń dodatkowe informacje"]="",
["usuń ostrzeżenie"]="",
["usuń linkowanie"]="",
["bez dodatkowych sprawdzeń"]="",--parametr systemowy szablonu do nieuruchamiania tej funkcji
};--tabelka powyższa jest tabelką argumentów systemowych tej funkcji tego modułu
local tabelka_argumentow_dodatkowych_funkcji={
["bez argumentów szablonu"]="", --zawiera w sobie argumenty szablonu i ich wartości
["dodaj parametry pudełka"]="", --dodaje parametry funkcji: Ogólne pudełko, modułu Pudełko
};
local tabelka_argumentow_systemowych_szablonu={
["bez kategorii"]="",--parametr systemowy szablonu, by kategorie się nie pojawiały
["nazwij jednostką"]="",--parametr systemowy funkcji mówiący, czy dowolną jednostkę nazwać po prostu jednostką
};--tabelka powyższa jest tabelką argumentów systemowych szablonu wywołującego tę funkcję tego modułu
local czy_dodaj_parametry_pudelka=parametry_modul.CzyTakFun(frame.args["dodaj parametry pudełka"]);
if(czy_dodaj_parametry_pudelka)then--dodaje parametry pudełka
tabelka_argumentow_systemowych_szablonu["parametry pudełka"]="";
tabelka_argumentow_systemowych_szablonu["bez błędu"]="";
tabelka_argumentow_systemowych_szablonu["dwuparametrowa"]="";
--dodaje parametry nienazwane i dla parametru: 1, którego ewentualną pierwszą nazwą jest: cel--
local maksimum=p.MaksymalnaLiczbaParametruNienazwanegoTablicy(tabelka_parametrow_rodzica);
for i=1,maksimum,1 do
if(i>1)then
tabelka_argumentow_systemowych_szablonu[i]="txt!";
else
tabelka_argumentow_systemowych_szablonu[1]="txt!;cel";
end;
end;
tabelka_argumentow_systemowych_szablonu["cel"]="txt!;1"
--parametry dokumentacji pudełka--
tabelka_argumentow_systemowych_szablonu["dokumentacja"]="";--parametr włączający parametry pudełka
tabelka_argumentow_systemowych_szablonu["obsługiwana przestrzeń nazw"]="";
tabelka_argumentow_systemowych_szablonu["pierwsza nieobsługiwana przestrzeń nazw"]="";
tabelka_argumentow_systemowych_szablonu["pierwsza obsługiwana przestrzeń nazw"]="";
tabelka_argumentow_systemowych_szablonu["pierwsza obsługiwana niegłówna przestrzeń nazw"]="";
tabelka_argumentow_systemowych_szablonu["pierwsza obsługiwana użytkowa niegłówna przedmiotowa przestrzeń nazw"]="";
tabelka_argumentow_systemowych_szablonu["nieobsługiwana strona główna projektu"]="";
tabelka_argumentow_systemowych_szablonu["nieobsługiwana strona główna dla dzieci"]="";
tabelka_argumentow_systemowych_szablonu["nieobsługiwane strony główne użytkowników"]="";
tabelka_argumentow_systemowych_szablonu["obsługiwany brudnopis projektu"]="";
tabelka_argumentow_systemowych_szablonu["obsługiwany brudnopis szablonu"]="";
tabelka_argumentow_systemowych_szablonu["obsługiwany brudnopis modułu"]="";
tabelka_argumentow_systemowych_szablonu["nieobsługiwane strony brudnopisu szablonów"]="";
tabelka_argumentow_systemowych_szablonu["nieobsługiwane strony brudnopisu opisu szablonów"]="";
tabelka_argumentow_systemowych_szablonu["nieobsługiwane strony brudnopisu modułów"]="";
tabelka_argumentow_systemowych_szablonu["nieobsługiwane strony brudnopisu opisu modułów"]="";
tabelka_argumentow_systemowych_szablonu["nieobsługiwane strony szablonów"]="";
tabelka_argumentow_systemowych_szablonu["nieobsługiwane strony opisu szablonów"]="";
tabelka_argumentow_systemowych_szablonu["nieobsługiwane strony modułów"]="";
tabelka_argumentow_systemowych_szablonu["nieobsługiwane strony opisu modułów"]="";
tabelka_argumentow_systemowych_szablonu["nazwy jednostki numerowane"]="";
tabelka_argumentow_systemowych_szablonu["maksymalny numer argumentu nienazwanego"]="";
tabelka_argumentow_systemowych_szablonu["zwracane kategorie błędu"]="";
tabelka_argumentow_systemowych_szablonu["parametry"]="";
tabelka_argumentow_systemowych_szablonu["dodatkowa informacja"]="";
tabelka_argumentow_systemowych_szablonu["najniższy numer dodatkowego warunku"]="";
tabelka_argumentow_systemowych_szablonu["parametry dodatkowego warunku"]="";
tabelka_argumentow_systemowych_szablonu["numer parametru dodatkowego"]="";--parametr używany przy innych parametrach
tabelka_argumentow_systemowych_szablonu["kategorie parametrów dodatkowych"]="";
tabelka_argumentow_systemowych_szablonu["czy istnieje taki parametr dodatkowego warunku"]="";
end;
local tablica_mikroszablonow={
["{{!}}"]="",
["{{+}}"]=";",
["{{-}}"]="=",
["{{@}}"]="^",
["{{#}}"]="$",
};
tabelka_bez_argumentow=parametry_modul["UsuńElementyTabeli"](tabelka_bez_argumentow,tabelka_argumentow_systemowych_funkcji);
tabelka_bez_argumentow=parametry_modul["UsuńElementyTabeli"](tabelka_bez_argumentow,tabelka_argumentow_systemowych_szablonu);
local zmienna_sprawdzania_parametrow=pf.args["zmienna sprawdzania parametrów"];
local zmienne_dodane={};
if(zmienna_sprawdzania_parametrow)then
local tabelka_zmiennych=mw.text.split(zmienna_sprawdzania_parametrow,";;",false);
for poz,war in ipairs(tabelka_zmiennych)do
local zmienna,wartosc=mw.ustring.match(war,"^%s*(.+)%s*=%s*(.*)%s*$")
if((zmienna)and(wartosc))then
zmienna=mw.text.trim(zmienna);
wartosc=mw.text.trim(wartosc);
zmienne_dodane[tonumber(zmienna) or mw.ustring.gsub(zmienna,"{{[^{}]+}}",tablica_mikroszablonow)]=wartosc;
end;
end;
end;
local zmienne_konieczne=function(tab,czy_odjete)
for k, v in pairs(tab)do
if(czy_odjete
or ((not tabelka_argumentow_systemowych_funkcji[k])
and (not tabelka_argumentow_systemowych_szablonu[k])
and (not tabelka_bez_argumentow[k])
)
)then
local wydziel=mw.ustring.match(v,"^%s*(^.*$%s*%??%s*!?)%s*");
if wydziel and mw.ustring.match(wydziel, "!%s*$") then
required[k] = true
elseif mw.ustring.match(mw.ustring.match(v,"^([^;]*!?)%s*"), "!%s*$") then
required[k] = true
end
end;
end;
end;
zmienne_konieczne(frame.args,false);
zmienne_konieczne(zmienne_dodane,true);
zmienne_konieczne(tabelka_argumentow_systemowych_funkcji,true);
zmienne_konieczne(tabelka_argumentow_systemowych_szablonu,true);
local emptyArg = false
local tabelka_parametrow_rodzica={};
local parametry_rodzica=parametry_modul.CzyTakFun(pf.args["potomek"])and pf.args["parametry rodzica"];
local techniczne_modul=require("Module:Techniczne");
if(parametry_rodzica)then
tabelka_parametrow_rodzica=ramka_modul.RozpakujParametry(parametry_rodzica);
templateName=pf.args["nazwa szablonu rodzica"] or techniczne_modul.NazwaSzablonu(pf:getTitle());
else
tabelka_parametrow_rodzica=pf.args;
templateName=techniczne_modul.NazwaSzablonu(pf:getTitle());
end;
local obslugiwane=function(k)
local kind=(not tabelka_argumentow_dodatkowych_funkcji[k]) and ((not tabelka_bez_argumentow[k])
and (tabelka_argumentow_systemowych_funkcji[k]
or tabelka_argumentow_systemowych_szablonu[k]
or zmienne_dodane[k]
or frame.args[k]));
return kind;
end;
local tab={};
local function inny_element(k)
local element=tab[k]
if(element)then
for name2,_ in pairs(element)do
if(name2~=k)then
if(tabelka_parametrow_rodzica[name2] and obslugiwane(name2))then
return true;
end;
end;
end;
end;
return false;
end;
for k, v in pairs(tabelka_parametrow_rodzica) do
required[k] = false
local kind=obslugiwane(k);
if (kind) then
local kind2,zmienne=mw.ustring.match(kind,"^%s*(!?^.*$%s*%??)%s*!?%s*;%s*(.-)%s*$");
if((not kind2)or(not zmienne))then
kind2,zmienne=mw.ustring.match(kind,"^%s*([^;]*)%s*!?%s*;%s*(.-)%s*$");
end;
if((kind2)and(zmienne))then
local tab2=mw.text.split(mw.text.trim(zmienne),"%s*;%s*",false);
tab[k]={};
for _,value in ipairs(tab2) do
value=mw.text.trim(value);
tab[k][tonumber(value) or mw.ustring.gsub(value,"{{[^{}]+}}",tablica_mikroszablonow)]=true;
end;
kind=mw.ustring.gsub(kind2,"{{[^{}]+}}",tablica_mikroszablonow);
else
kind2=mw.ustring.match(kind,"^%s*(!?%s*^.*$%s*%??)%s*!?%s*$");
if(not kind2)then
kind2=mw.ustring.match(kind,"^%s*(.-)%s*!?%s*$");
end;
kind=mw.ustring.gsub(kind2,"{{[^{}]+}}",tablica_mikroszablonow);
end;
end;
kind=kind and mw.text.trim(kind);
if k == "" then
emptyArg = v
elseif not kind then
table.insert(unknown, argName(k))
elseif inny_element(k) then
table.insert(repeated, 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?") or (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?") or (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)) end
elseif (kind == "old") or (kind == "old!") then
table.insert(deprecated, argName(k))
elseif(kind~="")then
local function regex(kind)
local tabpattern={};
local pattern;
local pattern2=kind;
repeat
local pattern22=pattern2;
pattern,pattern2=mw.ustring.match(pattern2,"^%s*(!?%s*^.-$%s*%??)%s*|%s*(.*)%s*$")
if((pattern)and(pattern2))then
table.insert(tabpattern,pattern);
elseif(mw.ustring.match(pattern22,"^%s*(!?%s*^.-$%s*%??)%s*$"))then
table.insert(tabpattern,pattern22);
end;
until not pattern2;
if(#tabpattern>0)then
local udane=false;
for _ , pattern in ipairs(tabpattern) do
local _pattern=mw.ustring.match(pattern,"^%s*!?%s*(^.-$)%s*$");
local zapytajnik=mw.ustring.match(pattern,"%s*(%?)%s*$");
local wykrzyknik=mw.ustring.match(pattern,"^%s*(!)");
if(_pattern)then
if ((zapytajnik and (mw.ustring.match(v,_pattern) or #v == 0))
or((not wykrzyknik and mw.ustring.match(v, _pattern))or(wykrzyknik and not mw.ustring.match(v, _pattern)))) then
udane=true;
break;
end;
end
end;
if(not udane)then table.insert(invalid, argName(k));end;
end;
end;
local czy_puste=mw.ustring.match(kind,"%?%s*!?$");
if(not czy_puste)then
local niepuste=mw.ustring.match(kind,"[^%?]?%s*!?$");
if(niepuste)then
regex(kind);
end;
else
if(v~="")then
regex(kind);
end;
end;
end
end;
local missing = {}
local function inny_element2(k)
local element=tab[k]
if(element)then
for name2,_ in pairs(element)do
if(k~=name2)then
if(tabelka_parametrow_rodzica[name2] and obslugiwane(name2))then
return true;
end;
end;
end;
end;
for name,value in pairs(tab)do
for name2,_ in pairs(value)do
if((name2==k)and(name2~=name))then
if((tabelka_parametrow_rodzica[name])and obslugiwane(name))then
return true;
end;
end;
end;
end;
return false;
end;
for k, v in pairs(required) do
local element=inny_element2(k)
if v and not element then
table.insert(missing, k)
end
end
if (#missing == 0) and (#unknown == 0) and (#invalid == 0) and (#deprecated == 0) and (#repeated == 0) then
return nil
end
local czy_informacje=not parametry_modul.CzyTakFun(tabelka_parametrow_rodzica["usuń dodatkowe informacje"]);
local result;
if(czy_informacje)then
result=mw.html.create("span")
result:addClass("problemy");
end;
local typ;
local typ_jednostki;
local czy_nazwij_jednostka=parametry_modul.CzyTakFun(tabelka_parametrow_rodzica["nazwij jednostką"]);
local czy_not_category=parametry_modul.CzyTakFun(tabelka_parametrow_rodzica["bez kategorii"]);
if(((czy_informacje)and(not czy_nazwij_jednostka))or((category)and((not czy_not_category)and(mw.ustring.match(category,"%%s.-%%s")))))then
local frame2=pf:newChild{args = {["obsługiwane jednostki jako nieopisowe strony"]="tak"}}
typ_jednostki=require("Module:Pudełko")["Typ jednostki 2"](frame2)
if(typ_jednostki=="artykuł")then
typ="(artykuły)";
elseif(typ_jednostki=="artykuł dla dzieci")then
typ="(artykuły dla dzieci)";
elseif(typ_jednostki=="strona użytkownika")then
typ="(strony użytkowników)";
elseif(typ_jednostki=="strona brudnopisu projektu")then
typ="(strony brudnopisu projektu)";
else
typ="(strony niepodręcznikowe)";
end;
else
typ=nil;
end;
if(czy_informacje)then
if(not czy_nazwij_jednostka)then
if typ_jednostki=="artykuł" or typ_jednostki=="artykuł dla dzieci" or typ_jednostki=="strona użytkownika" or typ_jednostki=="strona brudnopisu projektu" then
result:css("display", "none")
else
result:css("color", "red")
end
else
result:css("color", "red")
end;
end;
local czy_warning=not parametry_modul.CzyTakFun(tabelka_parametrow_rodzica["usuń ostrzeżenie"]);
local message;
if(czy_informacje or czy_warning)then
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 #repeated > 0 then
message:wikitext("Synonimy pól: ", mw.text.listToText(repeated), ". ")
end
end;
local warning;
if(czy_warning)then
warning = mw.html.create('span')
warning:css('color','red');
warning:addClass("problemy");
end;
if(templateName)then
mw.logObject(templateName, "templateName")
local dwukropek=mw.ustring.match(templateName,"^%s*:");
local nazwy_modul=require("Module:Nazwy");
local nazwa_przestrzeni_strony=nazwy_modul["NAZWAPRZESTRZENIFUN"](templateName);
local wywolanie;local wywolanie2;
local techniczne_modul=require("Module:Techniczne");
if dwukropek or nazwa_przestrzeni_strony~="" then
wywolanie=techniczne_modul["PokażSzablon"](templateName,tabelka_parametrow_rodzica);
wywolanie2="{{"..templateName.."}}";
if(parametry_modul.CzyTakFun(category))then
templateName=mw.ustring.gsub(templateName,"^%s*:","");
if(not czy_not_category)then
if(typ)then
category=mw.ustring.format(category,templateName,typ);
else
category=mw.ustring.format(category,templateName);
end;
category=pf:preprocess(category);
end;
class=mw.ustring.format(class,mw.ustring.gsub(templateName,"%s+","-"));
end;
else
wywolanie=techniczne_modul["PokażSzablon"](templateName,tabelka_parametrow_rodzica);
wywolanie2="{{"..templateName.."}}";
if(parametry_modul.CzyTakFun(category))then
local bez_pierwszej_litery=mw.ustring.match(templateName,"^.(.*)");
local czy_jest_wielka_litera=mw.ustring.match(bez_pierwszej_litery,"%u");
local szablon;
if(not czy_jest_wielka_litera)then szablon=mw.getContentLanguage():lcfirst(templateName);else szablon=templateName;end;
if(not czy_not_category)then
if(typ)then
category=mw.ustring.format(category,szablon,typ);
else
category=mw.ustring.format(category,szablon);
end;
category=pf:preprocess(category);
end;
class=mw.ustring.format(class,mw.ustring.gsub(szablon,"%s+","-"));
end;
end
if(czy_warning)then
warning:wikitext("Wywołanie "..wywolanie..": ")
end;
if(czy_informacje)then
result:wikitext("Szablon "..wywolanie2..": ");
end;
end;
local czy_usun_linkowanie=not parametry_modul.CzyTakFun(tabelka_parametrow_rodzica["usuń linkowanie"]);
if(czy_usun_linkowanie)then
local _ = mw.title.new("Module:Sprawdź/Wywołanie funkcji/Parametry").id;
end;
if(czy_informacje or czy_warning)then
message = tostring(message)
end;
if(czy_warning)then
warning:wikitext(message);
mw.addWarning(tostring(warning));
end;
if czy_informacje and class then
result:addClass(class)
end
if(czy_informacje)then result:wikitext(message);end;
local str_category;
if not czy_not_category and category then
str_category=category;
else
str_category="";
end
return nl..((czy_informacje)and tostring(result:allDone()) or "")..str_category;
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, "^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
["La"] = true, -- LaSalle
}
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")
local frame2=pf:newChild{args = {["obsługiwane jednostki jako nieopisowe strony"]="tak"}}
local typ_jednostki=require("Module:Pudełko")["Typ jednostki 2"](frame2)
if typ_jednostki=="artykuł" or typ_jednostki=="artykuł dla dzieci" or typ_jednostki=="strona użytkownika" or typ_jednostki=="strona brudnopisu projektu" then
result:css("display", "none")
result:wikitext("[[Kategoria:Szablon odn do sprawdzenia]]")
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("[[Kategoria:%s – niezgodność w Wikidanych – %s – %s]]", infobox and "Infoboksy" or "Szablony", infobox or template, field)
end,
["bez parametrów"] = function(frame)
for k, v in pairs(frame:getParent().args) do
return nil
end
return "tak"
end,
["pole z hostem"] = function (frame)
local host = frame.args.host
if host and (#host > 0) then
for k, v in pairs(frame:getParent().args) do
local link = string.match(v, "[hH][tT][tT][pP][sS]?://[%S]+")
if link then
local uri = mw.uri.new(link)
local valid, _ = mw.uri.validate(uri)
if valid and uri.host and (#uri.host > 0) then
if host == uri.host then
mw.logObject({k, link}, "cały")
return k
end
if #host < #uri.host then
local s1 = '.'..host
local s2 = string.sub(uri.host, -#s1)
if s1 == s2 then
mw.logObject({k, link}, "fragment")
return k
end
end
end
end
end
end
end,
["pola z gołymi linkami"] = function (frame)
local result = {}
for k, v in pairs(frame:getParent().args) do
local link = string.match(v, "^[hH][tT][tT][pP][sS]?://[%S]+")
if link then
local justified = frame.args[k]
if not justified then
mw.logObject(v,k)
table.insert(result, '"'..k..'"')
end
end
end
return mw.text.listToText(result)
end,
}