Moduł:Infoboksy: Różnice pomiędzy wersjami
Wygląd
[wersja przejrzana] | [wersja przejrzana] |
Usunięta treść Dodana treść
mNie podano opisu zmian |
m domyślnie 240x240 |
||
Linia 38: | Linia 38: | ||
function p.grafika_rozmiar(wywolanie) |
function p.grafika_rozmiar(wywolanie) |
||
local parametr = wywolanie.args[1] |
local parametr = wywolanie.args[1] |
||
local |
local maksmalny = wywolanie.args[2] or "BRAK" |
||
local minimalny = wywolanie.args[3] or "BRAK" |
local minimalny = wywolanie.args[3] or "BRAK" |
||
local |
local maxwidth = tonumber(mw.ustring.match(maksymalny, "^(%d+)x%d+px$")) or 240 |
||
local |
local maxheight = tonumber(mw.ustring.match(maksymalny, "^%d+x(%d+)px$")) or 300 |
||
local |
local minwidth = tonumber(mw.ustring.match(minimalny, "^(%d+)x%d+px$")) or 120 |
||
local |
local minheight = tonumber(mw.ustring.match(minimalny, "^%d+x(%d+)px$")) or 100 |
||
local |
local width = tonumber(mw.ustring.match(parametr, "^(%d+)x?%d*px")) or 240 |
||
local |
local height = tonumber(mw.ustring.match(parametr, "^%d*x(%d+)px")) or 240 |
||
if |
if width > maxwidth then |
||
width = maxwidth |
|||
elseif |
elseif width < minwidth then |
||
width = minwidth |
|||
end |
end |
||
if |
if height > maxheight then |
||
height = maxheight |
|||
elseif |
elseif height < minheight then |
||
height = minheight |
|||
end |
end |
||
rozmiar = |
rozmiar = width .. "x" .. height .. "px" |
||
return rozmiar |
return rozmiar |
Wersja z 11:11, 27 sty 2015
![](http://upload.wikimedia.org/wikipedia/commons/thumb/1/19/Test_Template_Info-Icon.svg/50px-Test_Template_Info-Icon.svg.png)
Edytorzy mogą eksperymentować w brudnopisie (edytuj | różnice) tego modułu.
Zobacz podstrony tego modułu. |
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 maksmalny = 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 separator = "*"
local linia
local element
local kolumny = 0
local suma = {}
local i
local skip
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
end
end
if wywolanie.args['tabela'] then
local zawartosc = wywolanie.args['tabela'] .. "\n"
while (mw.ustring.match(zawartosc, "[^\n]*\n")) do
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
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
if (wywolanie.args['kol'..i]) then
tabela = tabela .. "| " .. wywolanie.args['kol'..i] .. " | " .. element .. "\n"
elseif (i~=1 and mw.ustring.gsub(element, "%s", "") == tostring(tonumber(element))) then
tabela = tabela .. "| style=\"text-align:right;\" | " .. element .. "\n"
else
tabela = tabela .. "| " .. element .. "\n"
end
suma[i] = suma[i] + (tonumber(element) or 0)
end
if linia ~= "" then
tabela = tabela .. "|-\n! colspan=\"" .. kolumny .. "\" style=\"background:pink;\" | " .. mw.ustring.gsub(linia, "%n", "") .. "\n"
end
end
if zawartosc ~= "" then
tabela = tabela .. "|-\n! colspan=\"" .. kolumny .. "\" style=\"background:red;\" | " .. mw.ustring.gsub(zawartosc, "%n", "") .. "\n"
end
end
if wywolanie.args['podsumowanie'] then
i = 0
skip = 1
tabela = tabela .. "|- " .. wierszpodsumowanie .. "\n"
local podsumowanie = "!" .. wywolanie.args['podsumowanie']
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
skip = skip+1
elseif element == "+" then
tabela = tabela .. "| style=\"text-align:right;\" | " .. suma[i] .. "\n"
skip = 1
else
if skip>1 then
tabela = tabela .. "| colspan=\"" .. skip .. "\" style=\"text-align:right;\" | " .. element .. "\n"
else
tabela = tabela .. "| style=\"text-align:right;\" | " .. element .. "\n"
end
skip = 1
end
end
if podsumowanie ~= "" then
tabela = tabela .. "|-\n! colspan=\"" .. kolumny .. "\" style=\"background:red;\" | " .. podsumowanie .. "\n"
end
end
return tabela
end
-- kopia z [[Moduł:String]]
function p._escapePattern( pattern_str )
return mw.ustring.gsub( pattern_str, "([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" );
end
return p