local p = {}
local function noredir(page)
local link = page:fullUrl("redirect=no")
return "<span class=\"plainlinks\">[" .. link .. " " .. page.fullText .. "]</span>"
end
function p.main(frame)
local args = require("Module:Arguments").getArgs(frame, {removeBlanks=false})
-- Demo parameters, for demonstrating behavior with certain redirect
-- targets and avoiding categorization (do not use in articles)
local noError = args.noerror
local demo = args.demo or noError or args.thistarget or args.othertarget
local function formatError(err)
return "<span class=\"error\">Chyba v [[Modul:Napřímené přesměrování]]: " .. err .. "</span>"
.. (demo and "" or "[[Kategorie:Napřímená přesměrování/chyba]]")
end
local thisPage = mw.title.getCurrentTitle()
local otherPage = mw.title.new(args[1] or "")
if not otherPage then
return formatError("Nebyla zadána stránka.");
end
if mw.title.equals(thisPage, otherPage) then
return formatError("Byla zadána aktuální stránka.");
end
-- Get mw.title objects for redirect targets.
-- Note that using mw.title's redirectTarget will correctly handle preview mode, unlike Module:Redirect.
local thisTarget, otherTarget
if demo and args.thistarget then
thisTarget = mw.title.new(args.thistarget)
else
thisTarget = thisPage.redirectTarget
end
if demo and args.othertarget then
otherTarget = mw.title.new(args.othertarget)
else
otherTarget = otherPage.redirectTarget
end
-- For double redirects
local thisDoubleTarget = thisTarget and thisTarget.redirectTarget
local otherDoubleTarget = otherTarget and otherTarget.redirectTarget
local function formatOutput(update, info)
local from, cat
if otherTarget then
from = "přes stránku '''" .. noredir(otherPage) .. "'''"
else
from = "přes stránku '''[[:" .. otherPage.fullText .. "]]'''"
end
cat = demo and "" or update and "Napřímená přesměrování k úpravě" or "Napřímená přesměrování"
return frame:expandTemplate({
title = "Cedule",
args = {
["text"] = "Tato stránka je '''[[šablona:napřímené přesměrování|napřímené dvojité přesměrování]]''' " .. from .. ". " .. info,
["obrázek"] = "Redirect arrow without text (cropped).svg"
}
}) .. (cat and "[[Kategorie:" .. cat .. "]]")
end
if not noError then
if not thisTarget then
return formatError("Tato stránka není přesměrování.", demo)
elseif mw.title.equals(thisPage, thisTarget) then
return formatOutput(true, "<span class=\"error\">Tato stránka přesměrovává sama na sebe.</span>")
elseif not thisTarget.exists then
return formatOutput(true, "<span class=\"error\">Tato stránka přesměrovává na neexistující stránku.</span>")
elseif not otherPage.exists then
return formatOutput(true, "<span class=\"error\">[[:" .. otherPage.fullText .. "]] neexistuje.</span>")
elseif otherTarget and mw.title.equals(otherPage, otherTarget) then
return formatOutput(true, "<span class=\"error\">[[:" .. otherPage.fullText .. "]] přesměrovává sama na sebe.</span>")
elseif otherTarget and not otherTarget.exists then
return formatOutput(true, "<span class=\"error\">[[:" .. otherPage.fullText .. "]] přesměrovává na neexistující stránku.</span>")
elseif mw.title.equals(thisTarget, otherPage) then
if not otherTarget then
return formatOutput(true, "<span class=\"error\">[[:" .. otherPage.fullText .. "]] není přesměrování a tato stránka již na něj míří.</span> Tato šablona by se nejspíš měla odstranit.")
elseif mw.title.equals(otherTarget, thisPage) then
return formatOutput(true, "<span class=\"error\">Toto je cyklické přesměrování.</span> Změňte cíl tohoto přesměrování i " .. noredir(otherPage) .. " na správný článek.")
end
return formatOutput(true, "<span class=\"error\">Tato stránka přesměrovává na stránku " .. noredir(otherPage) .. ", která přesměrovává na [[:" .. otherTarget.fullText .. "]].</span> Napřimte toto dvojité přesměrování.")
elseif not otherTarget then
return formatOutput(true, "<span class=\"error\">Stránka [[:" .. otherPage.fullText .. "]] není přesměrování.</span> Toto přesměrování by tedy nejspíš mělo mířit na ni.")
elseif thisDoubleTarget then
if otherDoubleTarget then
return formatOutput(true, "<span class=\"error\">Tato stránka i " .. noredir(otherPage) .. " jsou [[WP:Dvojité přesměrování|dvojitá přesměrování]].</span> Napřimte je.")
end
return formatOutput(true, "<span class=\"error\">Tato stránka je [[WP:Dvojité přesměrování|dvojité přesměrování]].</span> Nejspíš by se mělo namířit přímo na [[:" .. otherTarget.fullText .. "]].")
elseif not mw.title.equals(thisTarget, otherTarget) then
return formatOutput(true, "<span class=\"error\">Tato stránka a " .. noredir(otherPage) .. " přesměrovávají na různé stránky.</span>")
elseif thisTarget.fragment ~= otherTarget.fragment then
return formatOutput(true, "Protože [[WP:Dvojité přesměrování|dvojitá přesměrování]] nejsou podporována, obě stránky přesměrovávají na stránku [[:" .. otherTarget.prefixedText .. "]], avšak míří na různé kotvy.")
end
end
return formatOutput(false, "Protože [[WP:Dvojité přesměrování|dvojitá přesměrování]] nejsou podporována, obě přesměrování míří na stránku [[:" .. otherTarget.prefixedText .. "]].")
end
return p