Przejdź do zawartości

Moduł:Moduł Dane tekstu2

Z Wikiźródeł, wolnej biblioteki

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

function FindFields4( frame )

-- Przeznaczenie znajduje na jakiejś stronie szablon {{:Dane tekstu}} kopiuje go, ale podmienia lub dodaje dodatkowe pola
-- tj. te wymienione w dalszych parametrach (pattern1, pattern2, pattern3 … )
-- Wynik: na nowo ewaluowany szablon {{Dane tekstu}}
-- pola szablonu źródłowego zazwyczaj {{Dane tekstu}} lub {{Dane tekstu2}} nie muszą być w osobnej linii (tak zazwyczaj robimy dla przejrzystości, ale nie jest to wymóg techniczny)
-- Na przykład chcąc zrezygnować z okładki napiszemy | okładka = | strona z okładką =
-- chcąc dodać pole pochodzenie napiszemy | pochodzenie = tutaj skąd pochodzi
-- parametr referencja określa referencyjną stronę, z niej ściągane są dane. Najczęściej będzie to 
--                     | referencja = {{ROOTPAGENAME}}
-- zródłowy szablon NIE jest pobierany, gdy w nim samym jest parametr referencja
-- w źródłowym szablonie nie są wykorzystywane parametry poprzedzone podkreśleniem, jednak są one dziedziczone i zastępują wtedy ewentualny argument bez podkreślenia

    local PageResult = ""
    local PageName = ""
    local PageContent= "{{}}"
    local referen = frame.args["referencja"]
    if frame.args["referencja"] ~= nil then
    	PageContent= mw.title.new(frame.args["referencja"]):getContent()
    end
    local i = 0
    local j = 0
    local k = ""
    local l = ""
    local v = ""
    local t = ""
	i, j =  string.find(PageContent, "%b{}"  )
   	PageResult = " " .. string.sub(PageContent, i, j-2):gsub("[^|]*","",1) .. "|"
   	PageResult = PageResult:gsub("%b{}",
   		function(s1) return string.gsub(s1,"|", "🐉") end)
   	PageResult = PageResult:gsub("%b[]",
   		function(s1) return string.gsub(s1,"|", "🐉") end)
   	while PageResult:find("| *_") do
   		l = PageResult:match("| *_[^=]*")
   		l = l:gsub("^| *_", "", 1)
   		l = l:gsub(" *$","")
   		PageResult = PageResult:gsub("| *" .. l .. "[^|]*|", "|", 1)
   		PageResult = PageResult:gsub("| *_" .. l .. " *=", "| " .. l .. " =", 1)
   	end
   	if string.match(PageResult, "| *referencja *=") then
   		return "Szablon na stronie referencyjnej zawiera odwołanie do innej strony!!!"
   		-- Nie chcemy dwukrotnie dziedziczyć danych, tylko pojedyncze odwołanie (referencja) jest OK.
   	else
	   	for k,v in pairs(frame.args) do
	   		if k ~= "referencja" then
	   			t = v:gsub("|","🐉"):gsub("%%","🐢"):gsub("^%s+","")
				if (string.find(PageResult, "| *" .. k .." *=[^|]*") ~= nil) then
					PageResult=PageResult:gsub("| *" .. k .. " *=[^|]*", "| " .. k .. " = " .. t )
				else
					PageResult = PageResult  .. k .. " = " .. t .." |".. string.char(10)
				end
			end
	   	end
	   	PageResult = PageResult:gsub("🐉","|"):gsub("🐢","%%")
	   	PageResult = PageResult:gsub("|\n?$","\n")
	   	PageResult = "{{Dane tekstu" .. PageResult .. "}}"
	   	return frame:preprocess(PageResult)
	end
end

local p = {}
function p.FindFields( frame )
    return  FindFields4( frame:getParent() )
end

function p.FindFields3( frame )

-- Wywołanie: {{#invoke: ... | FindFields3 |Ostatnia brygada |pole}}
-- Przeznaczenie znajduje na jakiejś stronie w pierwszym szablonie ( pomyślane {{Dane tekstu}}/{{Dane tekstu2}}, ale może to być dowolny pierwszy indeks na stronie (na przykład szablon w indeksie)
-- wyszukuje argument pole
-- zwraca go
-- pomyślany jako sposób na wpisanie takiego samego argumentu jak na innej stronie

    local PageResult = ""
    local PageName = ""
    local PageContent= "{{}}"
    local referen = frame.args[1]
    if frame.args[1] ~= nil then
    	PageContent= mw.title.new(frame.args[1]):getContent()
    end
    local i = 0
    local j = 0
    local l = ""
	i, j =  string.find(PageContent, "%b{}"  )
   	PageResult = " " .. string.sub(PageContent, i, j-2):gsub("[^|]*","",1) .. "|"
   	PageResult = PageResult:gsub("%b{}",
   		function(s1) return string.gsub(s1,"|", "🐉") end)
   	PageResult = PageResult:gsub("%b[]",
   		function(s1) return string.gsub(s1,"|", "🐉") end)
   	if PageResult:match("| *" .. frame.args[2] .. "[ ]*=[ ]*[^|]*") then
		l = PageResult:match("| *" .. frame.args[2] .. "[ ]*=[ ]*[^|]*"):gsub("| *" .. frame.args[2] .. "[ ]*=[ ]*", ""):gsub("🐉", "|")
		return frame:preprocess(l)
	else
		return ''
	end
end

return p