Moduł:Infoboksy: Różnice pomiędzy wersjami
Z Czarnobyl Wiki
m (wycięcie też przed i po obrazku) |
m (1 wersja) |
||
| (Nie pokazano 4 wersji utworzonych przez 2 użytkowników) | |||
| Linia 71: | Linia 71: | ||
local wiersznaglowek = wywolanie.args['wiersz nagłówek'] or "" | local wiersznaglowek = wywolanie.args['wiersz nagłówek'] or "" | ||
local wierszpodsumowanie = wywolanie.args['wiersz podsumowanie'] or "" | local wierszpodsumowanie = wywolanie.args['wiersz podsumowanie'] or "" | ||
| + | local wierszcenter = wywolanie.args['wiersz center'] or "style=\"background:#ddd; border-top:1px solid #aaa; text-align:center;\"" | ||
local separator = "*" | local separator = "*" | ||
local linia | local linia | ||
| Linia 76: | Linia 77: | ||
local kolumny = 0 | local kolumny = 0 | ||
local suma = {} | local suma = {} | ||
| + | local pokazsuma = {} | ||
| + | local format = {} | ||
| + | local kategoria = "Kategoria:Infoboksy – błędne dane – " .. (wywolanie.args['kategoria'] or "Moduł:Infoboksy") | ||
local i | local i | ||
| − | |||
if wywolanie.args['nagłówek'] then | if wywolanie.args['nagłówek'] then | ||
| Linia 92: | Linia 95: | ||
tabela = tabela .. "| " .. element .. "\n" | tabela = tabela .. "| " .. element .. "\n" | ||
suma[kolumny] = 0 | suma[kolumny] = 0 | ||
| + | pokazsuma[kolumny] = 1 | ||
| + | format[kolumny] = "" | ||
end | end | ||
end | end | ||
| + | if wywolanie.args['wiersz'] then | ||
| + | local wiersz = "!" .. wywolanie.args['wiersz'] | ||
| + | |||
| + | i = 0 | ||
| + | while (mw.ustring.match(wiersz, "![^!]*")) do | ||
| + | element = mw.ustring.match(wiersz, "![^!]*") | ||
| + | wiersz = mw.ustring.gsub(wiersz, p._escapePattern(element), "", 1) | ||
| + | element = mw.ustring.gsub(element, "!%s*", "") | ||
| + | |||
| + | i = i+1 | ||
| + | format[i] = element | ||
| + | end | ||
| + | end | ||
| + | |||
| + | local wiersze = 0 | ||
if wywolanie.args['tabela'] then | if wywolanie.args['tabela'] then | ||
local zawartosc = wywolanie.args['tabela'] .. "\n" | local zawartosc = wywolanie.args['tabela'] .. "\n" | ||
while (mw.ustring.match(zawartosc, "[^\n]*\n")) do | while (mw.ustring.match(zawartosc, "[^\n]*\n")) do | ||
| + | wiersze = wiersze + 1 | ||
linia = mw.ustring.match(zawartosc, "[^\n]*\n") | linia = mw.ustring.match(zawartosc, "[^\n]*\n") | ||
zawartosc = mw.ustring.gsub(zawartosc, p._escapePattern(linia), "", 1) | zawartosc = mw.ustring.gsub(zawartosc, p._escapePattern(linia), "", 1) | ||
| Linia 105: | Linia 126: | ||
i = 0 | i = 0 | ||
| + | if mw.ustring.match(linia, "!%+") then | ||
| + | linia = mw.ustring.gsub(linia, "!%+%s", "") | ||
| + | i = kolumny | ||
| + | tabela = tabela .. "! colspan=\"" .. kolumny .. "\" " .. wierszcenter .. " | " .. linia .. "\n" | ||
| + | linia = "" | ||
| + | end | ||
while (i<kolumny and mw.ustring.match(linia, "![^!]*")) do | while (i<kolumny and mw.ustring.match(linia, "![^!]*")) do | ||
element = mw.ustring.match(linia, "![^!]*") | element = mw.ustring.match(linia, "![^!]*") | ||
| Linia 111: | Linia 138: | ||
i = i+1 | i = i+1 | ||
| + | |||
| + | local liczba | ||
| + | liczba = mw.ustring.match(element, "^%d+") or "" | ||
| + | element = mw.ustring.gsub(element, p._escapePattern(liczba), "", 1) | ||
| + | |||
| + | if tonumber(liczba) == nil then | ||
| + | pokazsuma[i] = 0 | ||
| + | else | ||
| + | suma[i] = suma[i] + (tonumber(liczba) or 0) | ||
| + | end | ||
| + | element = liczba .. element | ||
| + | |||
| + | if element ~= "" then | ||
| + | if format[i] == "()" then | ||
| + | element = "(" .. element .. ")" | ||
| + | end | ||
| + | end | ||
| + | |||
if (wywolanie.args['kol'..i]) then | if (wywolanie.args['kol'..i]) then | ||
tabela = tabela .. "| " .. wywolanie.args['kol'..i] .. " | " .. element .. "\n" | tabela = tabela .. "| " .. wywolanie.args['kol'..i] .. " | " .. element .. "\n" | ||
| − | |||
| − | |||
else | else | ||
tabela = tabela .. "| " .. element .. "\n" | tabela = tabela .. "| " .. element .. "\n" | ||
end | end | ||
| − | + | ||
end | end | ||
| + | while (i<kolumny) do | ||
| + | i = i+1 | ||
| + | pokazsuma[i] = 0 | ||
| + | end | ||
if linia ~= "" then | if linia ~= "" then | ||
| − | tabela = tabela .. "|-\n! colspan=\"" .. kolumny .. "\" style=\"background:pink;\" | " .. mw.ustring.gsub(linia, "%n", "") .. "\n" | + | tabela = tabela .. "|-\n! colspan=\"" .. kolumny .. "\" style=\"background:pink;\" | [[" .. kategoria .. "]] BŁĄD: " .. mw.ustring.gsub(linia, "%n", "") .. "\n" |
end | end | ||
end | end | ||
if zawartosc ~= "" then | if zawartosc ~= "" then | ||
| − | tabela = tabela .. "|-\n! colspan=\"" .. kolumny .. "\" style=\"background:red;\" | " .. mw.ustring.gsub(zawartosc, "%n", "") .. "\n" | + | tabela = tabela .. "|-\n! colspan=\"" .. kolumny .. "\" style=\"background:red;\" | [[" .. kategoria .. "]] BŁĄD: " .. mw.ustring.gsub(zawartosc, "%n", "") .. "\n" |
end | end | ||
end | end | ||
| Linia 131: | Linia 178: | ||
if wywolanie.args['podsumowanie'] then | if wywolanie.args['podsumowanie'] then | ||
i = 0 | i = 0 | ||
| − | |||
tabela = tabela .. "|- " .. wierszpodsumowanie .. "\n" | tabela = tabela .. "|- " .. wierszpodsumowanie .. "\n" | ||
local podsumowanie = "!" .. wywolanie.args['podsumowanie'] | local podsumowanie = "!" .. wywolanie.args['podsumowanie'] | ||
| + | local pokazsumy = 1 | ||
| + | if wiersze < 2 then | ||
| + | pokazsumy = 0 | ||
| + | end | ||
| + | local sumy = "" | ||
while (i<kolumny and mw.ustring.match(podsumowanie, "![^!]*")) do | while (i<kolumny and mw.ustring.match(podsumowanie, "![^!]*")) do | ||
element = mw.ustring.match(podsumowanie, "![^!]*") | element = mw.ustring.match(podsumowanie, "![^!]*") | ||
| Linia 141: | Linia 192: | ||
i = i+1 | i = i+1 | ||
| − | if element == " | + | if element == "+" then |
| − | + | if pokazsuma[i]>0 then | |
| − | + | if format[i] == "()" then | |
| − | + | suma[i] = "(" .. suma[i] .. ")" | |
| − | + | end | |
| − | + | sumy = sumy .. "| style=\"text-align:right;\" | " .. suma[i] .. "\n" | |
| − | |||
| − | |||
else | else | ||
| − | + | sumy = sumy .. "| \n" | |
| + | pokazsumy = 0; | ||
end | end | ||
| − | + | else | |
| + | sumy = sumy .. "| style=\"text-align:right;\" | " .. element .. "\n" | ||
end | end | ||
end | end | ||
| − | if | + | if pokazsumy>0 then |
| − | tabela = tabela .. | + | tabela = tabela .. sumy |
end | end | ||
end | end | ||
| Linia 188: | Linia 239: | ||
local result, _ = string.gsub(text, "% %[%b[]%]", fileDetector) | local result, _ = string.gsub(text, "% %[%b[]%]", fileDetector) | ||
result, _ = string.gsub(result, "%[%b[]%]% ", fileDetector) | result, _ = string.gsub(result, "%[%b[]%]% ", fileDetector) | ||
| − | result, _ = string.gsub(result, "%[%b[]%]", fileDetector) | + | result, _ = string.gsub(result, "%[%b[]%]%s*", fileDetector) |
return result .. suffix | return result .. suffix | ||
end | end | ||
Aktualna wersja na dzień 21:36, 19 wrz 2019
Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Infoboksy/opis
Błąd skryptu: Błąd Lua: Błąd wewnętrzny: Proces interpretera został zakończony z sygnałem "-129".
local p = {}
function p.grafika(wywolanie)
local grafika = wywolanie.args[1]
grafika = mw.ustring.gsub(grafika, "%s*[Pp]lik%s*:%s*", "Plik:")
grafika = mw.ustring.gsub(grafika, "%s*[Ff]ile%s*:%s*", "Plik:")
grafika = mw.ustring.gsub(grafika, "%s*[Gg]rafika%s*:%s*", "Plik:")
grafika = mw.ustring.gsub(grafika, "%s*[Ii]mage%s*:%s*", "Plik:")
if mw.ustring.match(grafika, "^Plik:(.*)") then
grafika = mw.ustring.match(grafika, "^Plik:(.*)")
elseif mw.ustring.match(grafika, "%[%[Plik:([^%[%]|]+)[|%]]") then
grafika = mw.ustring.match(grafika, "%[%[Plik:([^%[%]|]+)[|%]]")
end
return grafika
end
function p.grafika_kategoria(wywolanie)
local grafika = wywolanie.args[1]
local kategoria = ""
grafika = mw.ustring.gsub(grafika, "%s*[Pp]lik%s*:%s*", "Plik:")
grafika = mw.ustring.gsub(grafika, "%s*[Ff]ile%s*:%s*", "Plik:")
grafika = mw.ustring.gsub(grafika, "%s*[Gg]rafika%s*:%s*", "Plik:")
grafika = mw.ustring.gsub(grafika, "%s*[Ii]mage%s*:%s*", "Plik:")
if mw.ustring.match(grafika, "^Plik:(.*)") then
kategoria = "[[Kategoria:Łatki - Plik]]"
elseif mw.ustring.match(grafika, "%[%[Plik:([^%[%]|]+)[|%]]") then
kategoria = "[[Kategoria:Łatki - Plik]]"
end
return kategoria
end
function p.grafika_rozmiar(wywolanie)
local parametr = wywolanie.args[1]
local maksymalny = wywolanie.args[2] or "BRAK"
local minimalny = wywolanie.args[3] or "BRAK"
local maxwidth = tonumber(mw.ustring.match(maksymalny, "^(%d+)x%d+px$")) or 240
local maxheight = tonumber(mw.ustring.match(maksymalny, "^%d+x(%d+)px$")) or 300
local minwidth = tonumber(mw.ustring.match(minimalny, "^(%d+)x%d+px$")) or 120
local minheight = tonumber(mw.ustring.match(minimalny, "^%d+x(%d+)px$")) or 100
local width = tonumber(mw.ustring.match(parametr, "^(%d+)x?%d*px")) or 240
local height = tonumber(mw.ustring.match(parametr, "^%d*x(%d+)px")) or 240
if width > maxwidth then
width = maxwidth
elseif width < minwidth then
width = minwidth
end
if height > maxheight then
height = maxheight
elseif height < minheight then
height = minheight
end
rozmiar = width .. "x" .. height .. "px"
return rozmiar
end
function p.tabela(wywolanie)
local tabela = ""
local wiersznaglowek = wywolanie.args['wiersz nagłówek'] or ""
local wierszpodsumowanie = wywolanie.args['wiersz podsumowanie'] or ""
local wierszcenter = wywolanie.args['wiersz center'] or "style=\"background:#ddd; border-top:1px solid #aaa; text-align:center;\""
local separator = "*"
local linia
local element
local kolumny = 0
local suma = {}
local pokazsuma = {}
local format = {}
local kategoria = "Kategoria:Infoboksy – błędne dane – " .. (wywolanie.args['kategoria'] or "Moduł:Infoboksy")
local i
if wywolanie.args['nagłówek'] then
local naglowek = "!" .. wywolanie.args['nagłówek']
tabela = tabela .. "|- " .. wiersznaglowek .. "\n"
while (mw.ustring.match(naglowek, "![^!]*")) do
kolumny = kolumny + 1
element = mw.ustring.match(naglowek, "![^!]*")
naglowek = mw.ustring.gsub(naglowek, p._escapePattern(element), "", 1)
element = mw.ustring.gsub(element, "!%s*", "")
tabela = tabela .. "| " .. element .. "\n"
suma[kolumny] = 0
pokazsuma[kolumny] = 1
format[kolumny] = ""
end
end
if wywolanie.args['wiersz'] then
local wiersz = "!" .. wywolanie.args['wiersz']
i = 0
while (mw.ustring.match(wiersz, "![^!]*")) do
element = mw.ustring.match(wiersz, "![^!]*")
wiersz = mw.ustring.gsub(wiersz, p._escapePattern(element), "", 1)
element = mw.ustring.gsub(element, "!%s*", "")
i = i+1
format[i] = element
end
end
local wiersze = 0
if wywolanie.args['tabela'] then
local zawartosc = wywolanie.args['tabela'] .. "\n"
while (mw.ustring.match(zawartosc, "[^\n]*\n")) do
wiersze = wiersze + 1
linia = mw.ustring.match(zawartosc, "[^\n]*\n")
zawartosc = mw.ustring.gsub(zawartosc, p._escapePattern(linia), "", 1)
linia = mw.ustring.gsub(linia, "\n", "")
tabela = tabela .. "|-\n"
i = 0
if mw.ustring.match(linia, "!%+") then
linia = mw.ustring.gsub(linia, "!%+%s", "")
i = kolumny
tabela = tabela .. "! colspan=\"" .. kolumny .. "\" " .. wierszcenter .. " | " .. linia .. "\n"
linia = ""
end
while (i<kolumny and mw.ustring.match(linia, "![^!]*")) do
element = mw.ustring.match(linia, "![^!]*")
linia = mw.ustring.gsub(linia, p._escapePattern(element), "", 1)
element = mw.ustring.gsub(element, "!%s*", "")
i = i+1
local liczba
liczba = mw.ustring.match(element, "^%d+") or ""
element = mw.ustring.gsub(element, p._escapePattern(liczba), "", 1)
if tonumber(liczba) == nil then
pokazsuma[i] = 0
else
suma[i] = suma[i] + (tonumber(liczba) or 0)
end
element = liczba .. element
if element ~= "" then
if format[i] == "()" then
element = "(" .. element .. ")"
end
end
if (wywolanie.args['kol'..i]) then
tabela = tabela .. "| " .. wywolanie.args['kol'..i] .. " | " .. element .. "\n"
else
tabela = tabela .. "| " .. element .. "\n"
end
end
while (i<kolumny) do
i = i+1
pokazsuma[i] = 0
end
if linia ~= "" then
tabela = tabela .. "|-\n! colspan=\"" .. kolumny .. "\" style=\"background:pink;\" | [[" .. kategoria .. "]] BŁĄD: " .. mw.ustring.gsub(linia, "%n", "") .. "\n"
end
end
if zawartosc ~= "" then
tabela = tabela .. "|-\n! colspan=\"" .. kolumny .. "\" style=\"background:red;\" | [[" .. kategoria .. "]] BŁĄD: " .. mw.ustring.gsub(zawartosc, "%n", "") .. "\n"
end
end
if wywolanie.args['podsumowanie'] then
i = 0
tabela = tabela .. "|- " .. wierszpodsumowanie .. "\n"
local podsumowanie = "!" .. wywolanie.args['podsumowanie']
local pokazsumy = 1
if wiersze < 2 then
pokazsumy = 0
end
local sumy = ""
while (i<kolumny and mw.ustring.match(podsumowanie, "![^!]*")) do
element = mw.ustring.match(podsumowanie, "![^!]*")
podsumowanie = mw.ustring.gsub(podsumowanie, p._escapePattern(element), "", 1)
element = mw.ustring.gsub(element, "!%s*", "")
i = i+1
if element == "+" then
if pokazsuma[i]>0 then
if format[i] == "()" then
suma[i] = "(" .. suma[i] .. ")"
end
sumy = sumy .. "| style=\"text-align:right;\" | " .. suma[i] .. "\n"
else
sumy = sumy .. "| \n"
pokazsumy = 0;
end
else
sumy = sumy .. "| style=\"text-align:right;\" | " .. element .. "\n"
end
end
if pokazsumy>0 then
tabela = tabela .. sumy
end
end
return tabela
end
-- kopia z [[Moduł:String]]
function p._escapePattern( pattern_str )
return mw.ustring.gsub( pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" );
end
function p.usun_grafiki(frame)
local text = frame.args[1]
local cat = frame.args[2] or ""
local suffix = ""
if text then
local function fileDetector(input)
local file = string.match(input, "%[%[[Pp]lik%s*:%s*.-%]%]")
or string.match(input, "%[%[[Gg]rafika%s*:%s*.-%]%]")
or string.match(input, "%[%[[Ff]ile%s*:%s*.-%]%]")
or string.match(input, "%[%[[Ii]mage%s*:%s*.-%]%]")
if file then
suffix = cat
return ""
else
return false
end
end
local result, _ = string.gsub(text, "% %[%b[]%]", fileDetector)
result, _ = string.gsub(result, "%[%b[]%]% ", fileDetector)
result, _ = string.gsub(result, "%[%b[]%]%s*", fileDetector)
return result .. suffix
end
end
return p