UWAGA
Strona jest ponownie oddana do uzytku po zabiegach konfiguracyjnych. Jeśli zobaczą Państwo na niej jakieś błedy techniczne, prosimy o ich zgłoszenie.

Większość artykułów w portalu to nasze własne teksty z kluczowych dziedzin związanych z naszą misją. Spora część materiałów pochodzi też z polskiej wersji Wikipedii, gdzie były odrzucone ze względu na politykę redaktorów (przeczytaj o krytyce Wikipedii). Są też i takie, które zostały przeniesione na nasze strony, gdyż stanowią istotne uzupełnienie merytorycznej treści naszego serwisu. Wszystkie artykuły podlegają edycji przez naszych Użytkowników, dlatego ich wersje mogą się różnić od prezentowanych na innych witrynach.

Moduł:Infoboksy

Z Wedapedia
Przejdź do nawigacji Przejdź do wyszukiwania

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Infoboksy/opis

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:Infoboksy – błędne wywołania plików]]"
    elseif mw.ustring.match(grafika, "%[%[Plik:([^%[%]|]+)[|%]]") then
        kategoria = "[[Kategoria:Infoboksy – błędne wywołania plików]]"
    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 500

    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 sumowanekolumny = 0
        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
                sumowanekolumny = sumowanekolumny+1
                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 sumowanekolumny == 0 then
            pokazsumy = 0
        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, "%&nbsp;%[%b[]%]", fileDetector)
		result, _ = string.gsub(result, "%[%b[]%]%&nbsp;", fileDetector)
		result, _ = string.gsub(result, "%[%b[]%]%s*", fileDetector)
		result = string.gsub(result, "^<br ?%/?>", " ");

		return result .. suffix
	end
end

function p.usun_wikilinki(frame)
	local text = frame.args[1]
	local signalFiles = frame.args.pliki
	local signalLinks = frame.args.linki
	
	local catPrefix = "[[Kategoria:"
	local catSuffix = "]]"
	local appendix = {""}
	local hasFiles = false
	local hasLinks = false

	local linkEliminator = function(s)
		local cat = mw.ustring.match(s, "^[Kk][Aa][Tt][Ee][Gg][Oo][Rr][Ii][Aa] *: *(%S.*)$")
			or mw.ustring.match(s, "^[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy] *: *(%S.*)$")
		if cat then
			table.insert(appendix, catPrefix..cat..catSuffix)
			return ""
		end
		
		local file = mw.ustring.match(s, "^[Pp][Ll][Ii][Kk] *: *(%S.*)$")
			or mw.ustring.match(s, "^[Ff][Ii][Ll][Ee] *: *(%S.*)$")
			or mw.ustring.match(s, "^[Ii][Mm][Aa][Gg][Ee] *: *(%S.*)$")
			or mw.ustring.match(s, "^[Gg][Rr][Aa][Ff][Ii][Kk][Aa] *: *(%S.*)$")
		if file then
			hasFiles = true
			return ""
		end
		
		hasLinks = true
		return mw.ustring.match(s, "| *(.+)") or s
	end
	
	local c = 1
	while c > 0 do
		text, c = mw.ustring.gsub(text, "%[%[ *([^%[%]\n\r]-) *%]%]", linkEliminator)
	end

	if hasLinks and signalLinks and (#signalLinks > 0) then
		table.insert(appendix, signalLinks)
	end
	if hasFiles and signalFiles and (#signalFiles > 0) then
		table.insert(appendix, signalFiles)
	end
	
	return text..table.concat(appendix, "")
end

return p