Moduł:Sandbox/Draco flavus/Test4

Z Wikiźródeł, wolnej biblioteki

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

local p = {}

local escape_lua_pattern
do
  local matches =
  {
    ["^"] = "%^";
    ["$"] = "%$";
    ["("] = "%(";
    [")"] = "%)";
    ["%"] = "%%";
    ["."] = "%.";
    ["["] = "%[";
    ["]"] = "%]";
    ["*"] = "%*";
    ["+"] = "%+";
    ["-"] = "%-";
    ["?"] = "%?";
  }

  escape_lua_pattern = function(s)
    return (s:gsub(".", matches))
  end
end


function p.Przypisy(frame)

-- Wywołanie: {{#invoke: ContainsRef | Przypisy | Strona:Tadeusz Dołęga-Mostowicz - Ostatnia brygada.djvu|from|to|fromsection|tosection}}
-- Wynik: jeśli w danym zakresie stron występuje <ref> {{pw}} {{bwd}} to zwraca słowo Przypisy inaczej Void
-- Może być wykorzystany tak {{ {{#if:1|{{#invoke: ContainsRef | Przypisy | Strona:PL Encyklopedyja powszechna 1860 T1.djvu|702|702||trzecia}}}} }}
-- W efekcie wstawiana jest sekcja Przypisy tylko tam, gdzie jest potrzebna
-- Naśladuje nieco składnię <pages index=... from=... to=... fromsection=... tosection=... />
-- ale jest mniej odporna np. sekcja from section musi się znajdować na stronie from 
-- podobnie jest z tosection i to
-- żadne parametry step, include, exclude nie są przewidziane
-- działa tylko z podstronami plików wielostronicowych (.djvu i .pdf)

    local SubPageResult = "Void"
    local SubPageName = ""
    local n = tonumber(frame.args[2])
    local m = tonumber(frame.args[3])
    local from_section='<section begin=' .. '"?' .. escape_lua_pattern(frame.args[4]) .. '"? */>'
    local to_section='<section end=' .. '"?' .. escape_lua_pattern(frame.args[5]) .. '"? */>'
    local start=""
    local stop=""
    local substring=""
    SubPageName=frame.args[1] .. "/" .. n
    
    if n == m and frame.args[4] ~= '' and frame.args[4] ~= nil and frame.args[5] ~= '' and frame.args[5] ~= nil then
    	start, stop = string.find(mw.title.new(SubPageName):getContent(), from_section .. '.*' .. to_section)
    	SubPageResult = start .. " " .. stop
    end
	--return SubPageResult
	return type(tonumber('1')) .. type(tonumber('')) .. type(tonumber(nil)) .. type(tonumber('x')) .. 'cztery'
	
end

return p