Użytkownik:Dreńkalo Taras/Moduł:Ping: Różnice pomiędzy wersjami

Z Nonsensopedii, polskiej encyklopedii humoru
M
M
 
Linia 5: Linia 5:
function p.ping(f)
function p.ping(f)
local a=f.args
local a=f.args
if f:getParent() ~= nil and f:getParent().args ~= nil and f:getParent().args[1] then
a=f:getParent().args
end
if not a[1] or a[1]:match("^%s*$") then
if not a[1] or a[1]:match("^%s*$") then
mw.smw.info('Musisz podać nick oznaczonego użytkownika!', 'error')
return mw.smw.info('Musisz podać nick oznaczonego użytkownika!', 'error')
return ''
end
end
local o="@[[User:"..a[1].."|"..a[1].."]]"
local o="@[[User:"..a[1].."|"..a[1].."]]"
for i=2,50 do
for i=2,50 do
if a[i] then
if a[i] and not a[i]:match("^%s*$") then
if a[i]:match("^%s*$") then
if i == #a then
mw.smw.info('The tagged username can not contain only white spaces', 'error')
o = o.." oraz @[[User:"..a[i].."|"..a[i].."]]"
return ''
else
o = o..", @[[User:"..a[i].."|"..a[i].."]]"
end
if i == 51 then
return mw.smw.info('Podałeś zadużo ników użytkowników! Następne niki zostali się zignorowane!', 'warning')
break
end
end
o=o..", @[[User:"..a[i].."|"..a[i].."]]"
elseif a[i] and a[i]:match("^%s*$") then
return mw.smw.info('The tagged username can not contain only white spaces', 'error')
else
else
break
break
end
if i == 50 and a[i+1] then mw.smw.info('Podałeś zadużo ników użytkowników! Następne niki zostali się zignorowane!', 'warning')
return ''
end
end
end
end

Aktualna wersja na dzień 03:38, 1 sie 2023

Tworzymy Module:Ping ze kodem poniżej:

local p={}
function p.ping(f)
    local a=f.args
    if f:getParent() ~= nil and f:getParent().args ~= nil and f:getParent().args[1] then
        a=f:getParent().args
    end
    if not a[1] or a[1]:match("^%s*$") then
        return mw.smw.info('Musisz podać nick oznaczonego użytkownika!', 'error')
    end
    local o="@[[User:"..a[1].."|"..a[1].."]]"
    for i=2,50 do 
        if a[i] and not a[i]:match("^%s*$") then
            if i == #a then
                o = o.." oraz @[[User:"..a[i].."|"..a[i].."]]"
            else
                o = o..", @[[User:"..a[i].."|"..a[i].."]]"
            end
            if i == 51 then
                return mw.smw.info('Podałeś zadużo ników użytkowników! Następne niki zostali się zignorowane!', 'warning')
                break
            end
        elseif a[i] and a[i]:match("^%s*$") then
            return mw.smw.info('The tagged username can not contain only white spaces', 'error')
        else
            break
        end
    end
    return o
end
return p

Potem zmieniamy we szablonie {{re}} kod

{{#if:{{{1|}}}|@[[Użytkownik:{{{1}}}|{{{1}}}]]|'''{{c|red|Nie podano nicku oznaczonego użytkownika!}}'''}}{{#if:{{{2|}}}|, @[[Użytkownik:{{{2}}}|{{{2}}}]]}}{{#if:{{{3|}}}|, @[[Użytkownik:{{{3}}}|{{{3}}}]]}}{{#if:{{{4|}}}|, @[[Użytkownik:{{{4}}}|{{{4}}}]]}}{{#if:{{{5|}}}|, @[[Użytkownik:{{{5}}}|{{{5}}}]]}}

na podobny kod:

{{#invoke:Ping|ping|{{#titleparts: {{{1}}}|-1,1000}}}}

Wynik: Ta sama funkcjonalność, ale można pingować do 50 użytkowników za jeden raz oraz o 80% mniejsze wiki kodu.