Moduł:Łatki: Różnice pomiędzy wersjami
[wersja przejrzana] | [wersja przejrzana] |
przenosiny do Moduł:Sprawdź |
włączam śledzenie wywołań funkcji mechanizmem linkujących |
||
Linia 2: | Linia 2: | ||
function m.Plik(frame) |
function m.Plik(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Plik").id |
|||
if not frame then |
if not frame then |
||
return nil |
return nil |
||
Linia 50: | Linia 52: | ||
m.Join = function(frame) |
m.Join = function(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Join").id |
|||
local result = {} |
local result = {} |
||
local pf = frame:getParent() |
local pf = frame:getParent() |
||
Linia 78: | Linia 82: | ||
m.PoliczLinki = function(frame) |
m.PoliczLinki = function(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/PoliczLinki").id |
|||
local pf = frame:getParent() |
local pf = frame:getParent() |
||
local text = frame.args[1] or pf.args[1] |
local text = frame.args[1] or pf.args[1] |
||
Linia 96: | Linia 102: | ||
m["Liczba artykułów"] = function(frame) |
m["Liczba artykułów"] = function(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Liczba artykułów").id |
|||
local text = frame.args[1] or frame:getParent().args[1] or "" |
local text = frame.args[1] or frame:getParent().args[1] or "" |
||
local _, count = mw.ustring.gsub(text, "(%[%[[^%[%]]-%]%])", "%1") |
local _, count = mw.ustring.gsub(text, "(%[%[[^%[%]]-%]%])", "%1") |
||
Linia 107: | Linia 115: | ||
m["Liczba artykułów między"] = function(frame) |
m["Liczba artykułów między"] = function(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Liczba artykułów między").id |
|||
local pf = frame:getParent() |
local pf = frame:getParent() |
||
local start = frame.args[1] or pf.args[1] |
local start = frame.args[1] or pf.args[1] |
||
Linia 161: | Linia 171: | ||
m["Numerowanie w tabeli"] = function(frame) |
m["Numerowanie w tabeli"] = function(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Numerowanie w tabeli").id |
|||
local counter = 0 |
local counter = 0 |
||
local result = {} |
local result = {} |
||
Linia 200: | Linia 212: | ||
m["są interwiki"] = function(frame) |
m["są interwiki"] = function(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/są interwiki").id |
|||
local count = 0 |
local count = 0 |
||
local entity = mw.wikibase.getEntityObject() |
local entity = mw.wikibase.getEntityObject() |
||
Linia 214: | Linia 228: | ||
function m.contentMatch(frame) |
function m.contentMatch(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/contentMatch").id |
|||
local content = mw.title.getCurrentTitle():getContent() |
local content = mw.title.getCurrentTitle():getContent() |
||
if not content then |
if not content then |
||
Linia 240: | Linia 256: | ||
function m.match(frame) |
function m.match(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/match").id |
|||
local s = frame.args[1] |
local s = frame.args[1] |
||
if not s or (#s==0) then |
if not s or (#s==0) then |
||
Linia 254: | Linia 272: | ||
function m.replace(frame) |
function m.replace(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/replace").id |
|||
local text = frame.args[1] |
local text = frame.args[1] |
||
if not text or (#text == 0) then |
if not text or (#text == 0) then |
||
Linia 268: | Linia 288: | ||
function m.Sumuj(frame) |
function m.Sumuj(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Sumuj").id |
|||
local pf = frame:getParent() |
local pf = frame:getParent() |
||
if not pf then |
if not pf then |
||
Linia 315: | Linia 337: | ||
function m.Interwiki(frame) |
function m.Interwiki(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Interwiki").id |
|||
local qid = frame.args.id |
local qid = frame.args.id |
||
local data = mw.wikibase.getEntityObject(qid) |
local data = mw.wikibase.getEntityObject(qid) |
||
Linia 374: | Linia 398: | ||
function m.Z(frame) |
function m.Z(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Z").id |
|||
local ze = { |
local ze = { |
||
"^%s*[Mm][Nn][Ii][Ee]$", |
"^%s*[Mm][Nn][Ii][Ee]$", |
||
Linia 399: | Linia 425: | ||
function m.TEMPLATENAME(frame) |
function m.TEMPLATENAME(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/TEMPLATENAME").id |
|||
local templateTitle = mw.title.new(frame:getParent():getTitle()) |
local templateTitle = mw.title.new(frame:getParent():getTitle()) |
||
return (templateTitle and (templateTitle.namespace == 10)) and templateTitle.text or nil |
return (templateTitle and (templateTitle.namespace == 10)) and templateTitle.text or nil |
||
Linia 404: | Linia 432: | ||
function m.SUBST(frame) |
function m.SUBST(frame) |
||
mw.logObject(frame:getParent():getTitle(), "parent:title") |
|||
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/SUBST").id |
|||
local title = mw.title.getCurrentTitle() |
local title = mw.title.getCurrentTitle() |
||
mw.logObject(title.text, "title.text") |
mw.logObject(title.text, "title.text") |
Wersja z 23:33, 27 lut 2016
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)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Plik").id
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)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Join").id
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)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/PoliczLinki").id
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)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Liczba artykułów").id
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)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Liczba artykułów między").id
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["Numerowanie w tabeli"] = function(frame)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Numerowanie w tabeli").id
local counter = 0
local result = {}
local pf = frame:getParent()
local i = 1
table.insert(result, "{")
while true do
local object = pf:getArgument(i)
if object then
object = object:expand()
else
break
end
if object then
table.insert(result, "|")
local length = #object
if length > 0 then
if string.byte(object,1) == 35 then
counter = counter + 1
local counterText = counter..". "
local userText = length > 1 and string.sub(object, 2, length) or ""
object = counterText..userText
end
end
table.insert(result, object)
i = i + 1
else
break
end
end
table.insert(result, "|}")
return table.concat(result, "")
end
m["są interwiki"] = function(frame)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/są interwiki").id
local count = 0
local entity = mw.wikibase.getEntityObject()
if entity and entity.sitelinks then
for k, v in pairs(entity.sitelinks) do
if k ~= "plwiki" then
count = count + 1
end
end
end
return count > 0 and count or ""
end
function m.contentMatch(frame)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/contentMatch").id
local content = mw.title.getCurrentTitle():getContent()
if not content then
mw.log("no content")
return
end
local i = 1
while true do
local p = frame.args[i]
if not p or (#p==0) then
mw.log("no pattern "..i)
return
end
local result = mw.ustring.match(content, p)
if result then
mw.log("match "..result)
return result
end
mw.log("no match "..p)
i = i + 1
end
end
function m.match(frame)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/match").id
local s = frame.args[1]
if not s or (#s==0) then
return nil
end
local p = frame.args[2]
if not p or (#p == 0) then
return nil
end
return mw.ustring.match(s, p)
end
function m.replace(frame)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/replace").id
local text = frame.args[1]
if not text or (#text == 0) then
return nil
end
local pattern = frame.args[2]
if not pattern or (#pattern == 0) then
return text
end
local replacement = frame.args[3] or ""
local result, _ = mw.ustring.gsub(text, pattern, replacement)
return result
end
function m.Sumuj(frame)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Sumuj").id
local pf = frame:getParent()
if not pf then
return
end
local name = pf.args[1]
if not name or (#name == 0) then
return
end
local value = pf.args[2]
if not value then
return
end
local lang = mw.getContentLanguage()
local number = lang:parseFormattedNumber(value)
if number then
return lang:formatNum(number)
end
if value ~= "RAZEM" then
return value
end
local pattern = "{{%s*[Ss]umuj%s*|"..mw.ustring.gsub( name, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" ).."|%s*([^}]-)%s*}}";
local total = 0
local items = 0
local sum = function(value)
local number = lang:parseFormattedNumber(value)
if number then
total = total + number
items = items + 1
end
return false
end
local content = mw.title.getCurrentTitle():getContent()
mw.ustring.gsub(content, pattern, sum)
if items ~= 0 then
return lang:formatNum(total)
end
end
function m.Interwiki(frame)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Interwiki").id
local qid = frame.args.id
local data = mw.wikibase.getEntityObject(qid)
if not data then
return -- brak danych -> kategoria?
end
local links = {}
local appendLink = function(lang, title)
if not links[lang] then
links[lang] = { title }
else
table.insert(links[lang], title)
end
end
local knownLanguages = mw.loadData("Module:Lang/data")
local extractLinks = function(data)
if data.sitelinks then
for k, v in pairs(data.sitelinks) do
local lang = string.sub(k, 1, -5)
local project = string.sub(k, -4)
if (project == "wiki") and knownLanguages[lang] then
appendLink(lang, v.title)
end
end
end
end
extractLinks(data)
if data.claims and data.claims.P460 then
for _, v in ipairs(data.claims.P460) do
if v.mainsnak.snaktype == "value" then
local seeid = "Q"..tostring(v.mainsnak.datavalue.value["numeric-id"])
local seedata = mw.wikibase.getEntityObject(seeid)
if seedata then
extractLinks(seedata)
end
end
end
end
local result = {}
local content = mw.title.getCurrentTitle():getContent()
for k, v in pairs(links) do
local pattern = "%[%["..mw.ustring.gsub( k, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" )..":[^%[%]|]+%]%]"
local interwiki = mw.ustring.match(content, pattern)
if not interwiki and not data.sitelinks[k.."wiki"] then
table.insert(result, "[[")
table.insert(result, k)
table.insert(result, ":")
table.insert(result, v[1])
table.insert(result, "]]")
end
end
return table.concat(result, "")
end
function m.Z(frame)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/Z").id
local ze = {
"^%s*[Mm][Nn][Ii][Ee]$",
"^%s*[Mm][Nn][Ii][Ee]%s",
"^%s*[Mm][Nn][Ąą]$",
"^%s*[Mm][Nn][Ąą]%s",
"^%s*[Ss][Oo][Bb][Ąą]$",
"^%s*[Ss][Oo][Bb][Ąą]%s",
"^%s*[Ss][Zz][BbCcĆćDdFfGgHhJjKkLlŁłMmNnŃńPpRrSsŚśTtWwZzŹźŻż]",
"^%s*[Ss][BbCcĆćDdFfGgHhJjKkLlŁłMmNnŃńPpRrSsŚśTtWwŹźŻż]",
"^%s*[ŚśZz][BbCcĆćDdFfGgHhJjKkLlŁłMmNnŃńPpRrSsŚśTtWwZzŹźŻż]",
}
local text = frame.args[1]
if text then
for _, regex in ipairs(ze) do
if mw.ustring.match(text, regex) then
return "ze"
end
end
end
return "z"
end
function m.TEMPLATENAME(frame)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/TEMPLATENAME").id
local templateTitle = mw.title.new(frame:getParent():getTitle())
return (templateTitle and (templateTitle.namespace == 10)) and templateTitle.text or nil
end
function m.SUBST(frame)
mw.logObject(frame:getParent():getTitle(), "parent:title")
_ = mw.title.new("Module:Łatki/Wywołanie funkcji/SUBST").id
local title = mw.title.getCurrentTitle()
mw.logObject(title.text, "title.text")
local prefixedTitleName = mw.ustring.match(title.prefixedText, "^(.-)/opis")
or mw.ustring.match(title.prefixedText, "^(.-)/test")
or mw.ustring.match(title.prefixedText, "^(.-)/brudnopis")
or title.prefixedText
if mw.isSubsting() or (prefixedTitleName == frame:getParent():getTitle()) or (frame:getParent().args["usprawiedliwienie na brak 'subst:'"] == "przykład wywołania szablonu przez transkluzję poza stronami testowymi") then
return frame.args[1]
end
mw.log("Brak 'subst:' w wywołaniu '"..frame:getParent():getTitle().."'")
return "[[Kategoria:Brak 'subst:' w wywołaniu szablonu]]"
end
return m