Moduł:Łatki
Moduł techniczny do obsługi różnorakich wysokospecjalistycznych funkcji lub szablonów.
Plik
Funkcja poprawiająca niestandardowe wywołania grafiki w infoboksach.
PoliczLinki
Funkcja implementująca szablon {{Policz linki}}.
Liczba artykułów między
Funkcja obliczająca liczbę wikilinków między zadanymi znacznikami. Nazwy znaczników podaje się w pierwszym i drugim parametrze. W kodzie strony znaczniki muszą być umieszczone w komentarzu HTML.
Numerowanie w tabeli
Funkcja implementująca szablon {{Numerowanie w tabeli}}.
są interwiki
Funkcja zwracająca liczbę interwiki do projektów siostrzanych i innych wersji językowych. Wykorzystanie w {{EK}} do generowania dodatkowego ostrzeżenia.
contentMatch
Funkcja zwracająca wynik pierwszego wyrażenia regularnego Lua w treści źródłowej strony.
- Wyszukiwarka szablonów, które jej używają jest tutaj.
Interwiki
Funkcja do generowania większej liczby interwiki przez wykorzystanie cechy „uważa się za to samo co”.
- Wykorzystanie w {{imiona}} i {{więcej interwiki}}.
Z
Funkcja generująca przyimek „z” lub „ze” zależnie od podanego i następującego po nim słowa. Zastosowana w {{przekierowanie}}.
TEMPLATENAME
Funkcja zwracająca nazwę szablonu, w którym jest wywołana.
SUBST
Funkcja sprawdzająca czy szablon jest wywołany przez subst:
.
FormatPluralNum
Funkcja wspomagająca generowanie formatowanie liczby naturalnej z opisem w połączeniu z opcjonalnym dodaniem odpowiedniej formy rzeczownika.
{{#invoke:Łatki|FormatPluralNum|liczba|forma 1|forma 2|forma 3|forma 4}}
Przykłady:
{{#invoke:Łatki|FormatPluralNum|chyba 1 |skarpetka|skarpetki|skarpetek}}
→ Błąd skryptu: nie ma takiej funkcji „FormatPluralNum”.{{#invoke:Łatki|FormatPluralNum|mam 2002 |skarpetka|skarpetki|skarpetek}}
→ Błąd skryptu: nie ma takiej funkcji „FormatPluralNum”.{{#invoke:Łatki|FormatPluralNum|około 50000 |skarpetka|skarpetki|skarpetek}}
→ Błąd skryptu: nie ma takiej funkcji „FormatPluralNum”.
Powyższy opis jest dołączany ze strony Moduł:Łatki/opis. (edytuj | historia)
Edytorzy mogą eksperymentować w brudnopisie (edytuj | różnice) tego modułu. Zobacz podstrony tego modułu. |
local m = {}
function m.Plik(frame)
if not frame then
return nil
end
local args = frame.args
if not args then
mw.log("brak argumentów")
return nil
end
local file = args[1]
if not file then
mw.log("brak pliku")
return nil
end
local multipleFiles = ""
if string.match(file, "%]%s*%[") then
multipleFiles = "[[Kategoria:Łatki - Kilka plików]]"
end
if string.match(file, "^%s*%[%[") then
mw.log("to jest link: "..file)
return file .. "[[Kategoria:Łatki - Plik]]"..multipleFiles
end
if string.match(file, "^%s*%[") then
mw.log("to jest link zewnętrzny: "..file)
return file .. "[[Kategoria:Łatki - Plik zewnętrzny]]"..multipleFiles
end
local builder = {}
table.insert(builder, "[[Plik:")
for i, v in ipairs(args) do
if i > 1 then
table.insert(builder,"|")
end
table.insert(builder,v)
end
table.insert(builder, "]]")
local result = table.concat(builder, "")
mw.log("wynik: "..result)
return result
end
m.Join = function(frame)
local result = {}
local pf = frame:getParent()
local i = 1
while true do
local object = pf:getArgument(i)
if object then
object = object:expand()
else
break
end
if object then
if i > 1 then
table.insert(result, "|")
end
table.insert(result, object)
i = i + 1
else
break
end
end
return table.concat(result, "")
end
m.PoliczLinki = function(frame)
local pf = frame:getParent()
local text = frame.args[1] or pf.args[1]
local threshold = tonumber(frame.args["próg"] or pf.args["próg"]) or 1
if text then
text = mw.text.trim(text)
local _, count = mw.ustring.gsub(text, "(%[%[[^%[%]]-%]%])", "%1")
if count >= threshold then
local lang = mw.getContentLanguage()
local number = lang:formatNum(count)
local articles = lang:convertPlural(count, { "artykuł", "artykuły", "artykułów" })
return text .. "<small> ("..number.." "..articles..")</small>"
else
return text
end
end
end
m["Liczba artykułów"] = function(frame)
local text = frame.args[1] or frame:getParent().args[1] or ""
local _, count = mw.ustring.gsub(text, "(%[%[[^%[%]]-%]%])", "%1")
local _, files = mw.ustring.gsub(text, "(%[%[Plik:[^%[%]]-%]%])", "%1")
count = count - files
local lang = mw.getContentLanguage()
local number = lang:formatNum(count)
local articles = lang:convertPlural(count, { "artykuł", "artykuły", "artykułów" })
return number.." "..articles
end
m["Liczba artykułów między"] = function(frame)
local pf = frame:getParent()
local start = frame.args[1] or pf.args[1]
if not start then
return
end
local stop = frame.args[2] or pf.args[2]
if not stop then
return
end
local content = mw.title.getCurrentTitle():getContent()
if not content then
return
end
local startPattern = "<!--"..start.."-->"
local startPosition = string.find(content, startPattern, 1, true)
if not startPosition then
return
end
startPosition = startPosition + #startPattern
local stopPattern = "<!--"..stop.."-->"
local stopPosition = string.find(content, stopPattern, startPosition, true)
if not stopPosition then
return
end
stopPosition = stopPosition - 1
if startPosition >= stopPosition then
return
end
local text = string.sub(content, startPosition, stopPosition)
local _, count = mw.ustring.gsub(text, "(%[%[[^%[%]]-%]%])", "%1")
local _, files = mw.ustring.gsub(text, "(%[%[Plik:[^%[%]]-%]%])", "%1")
count = count - files
local threshold = tonumber(frame.args["próg"] or pf.args["próg"]) or 1
if count < threshold then
return
end
local lang = mw.getContentLanguage()
local number = lang:formatNum(count)
local articles = lang:convertPlural(count, { frame.args[4] or pf.args[4] or "artykuł", frame.args[5] or pf.args[6] or "artykuły", frame.args[6] or pf.args[6] or "artykułów" })
local result, _ = string.gsub(frame.args[3] or pf.args[3] or "<small>($1)</small>", "$1", number.." "..articles)
return result
end
m["Sprawdzenie argumentów 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 "missing arguments" or false
break
end
if (i > 5) or yeardetected then
problems = "too many positional arguments"
break
end
if #arg == 0 then
problems = "empty argument"
break
end
if arg ~= mw.text.trim(arg) then
problems = "unexpected leading or trailing spaces"
break
end
if string.match(arg, "^%d+%l?$") then
yeardetected = true
if i == 1 then
problems = "year must be the last argument after author lastnames"
break
end
elseif string.match(arg, "^s[%-%.:]%s*%d+") then
problems = "potentially incorrectly provided page number"
break
elseif string.match(arg, "%s%s") then
problems = "consecutive spaces"
break
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 = "unexpected odn parameter"
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 = "obsolete argument for page number"
end
end
return problems and ("<span class=\"problemy-w-odn\" style=\"display:none\">ODN: "..problems.."</span>[[Kategoria:Szablon odn do sprawdzenia]]") or ""
end
return m