Moduł:Sandbox/Draco flavus/TestAllPagesUnivRangeUniv

Z Wikiźródeł, wolnej biblioteki

Dokumentacja dla tego modułu może zostać utworzona pod nazwą Moduł:Sandbox/Draco flavus/TestAllPagesUnivRangeUniv/opis

local p = {}

local function ifisempty(s)
	if s==nil or s=='' then
		return "???"
	else
		return s
	end
end

function p.sections_in_range(frame)

-- Wywołanie: {{#invoke: Sandbox/Draco flavus/TestAllPagesUnivRangeUniv | sections_in_range | Strona:PL Encyklopedyja powszechna 1860 T1.djvu|start|end|pattern}}
-- Wynik: jeśli w danym zakresie stron występuje dany string zwraca go 
-- do wykorzystania w szablonie

    local SubPageResult = frame.args[4]..string.char(10)..string.char(10)
    local n = tonumber(frame.args[2])
    local m = tonumber(frame.args[3])
    local SubPageName=""
    local Items=""
    local FirstPage={}
    local LastPage={}
    local ListOfItems="◇"
    -- local Test=""
    while (n <= m) do
    	
    	--
    
    	SubPageName=frame.args[1] .. "/" .. n
    
    
    	
    	if (string.match(mw.title.new(SubPageName):getContent(), frame.args[4]) ~= nil ) then
    		SubPageResult = SubPageResult .. string.char(10) .. string.char(10) .. "𝕬".. n .. "◇"
    		for w in  string.gmatch(mw.title.new(SubPageName):getContent(), frame.args[4]) do
    			w = w:gsub("section begin=" .. string.char(34), "𝕭")
    			w = w:gsub("section end=" .. string.char(34), "𝕰")
    			w = w:gsub(string.char(34) .. string.char(32), "𝖅")
    			w = w .. n .. "◇"
        		SubPageResult = SubPageResult .. w
    		end
    	end
	
    	--
		n=n+1
		SubPageName=frame.args[1] .. "/" .. n
    end
    for k, v in string.gmatch(SubPageResult, "𝕭([^𝖅]*)𝖅(%d*)◇") do
    	-- Items=Items .. k .. v
    	if FirstPage[k]==nil then
    		FirstPage[k]=v
    		ListOfItems=ListOfItems .. k .. "◇"
    	end
    end
    for k, v in string.gmatch(SubPageResult, "𝕰([^𝖅]*)𝖅(%d*)◇") do
    	-- Items=Items .. k .. v
    	LastPage[k]=v
    end
	-- return SubPageResult
	-- return Items
	
	for m in string.gmatch(ListOfItems, "◇([^◇][^◇]*)") do
		Items = Items .. m .. string.char(32) .. FirstPage[m] .. string.char(32) .. ifisempty(LastPage[m]) .. "<br>" .. string.char(10)
		-- Test = Test .. m .. "★"
	end
	return Items 

end

return p