词条 | Module:R avoided double redirect |
释义 | local p = {} function p.main(frame) local mRedirect = require("Module:Redirect") local function noredir(page) local link = mw.title.new(page):fullUrl("redirect=no") return "["..link.." "..page.."]" end local function process(page) end local function exists(page) end local args = require("Module:Arguments").getArgs(frame,{removeBlanks=false}) local thisPage = tostring(mw.title.getCurrentTitle()) local otherPage = args[1] or "" --Demo parameters, for demonstrating behavior with certain redirect--targets and avoiding categorization (do not use in articles)local thisDemoTarget = args.thistarget local otherDemoTarget = args.othertarget local noError = args.noerror local demo = args.demo or noError or thisDemoTarget or otherDemoTarget --"Process" pages to remove section links, standardize capitalization, etc.otherPage = otherPage=="" and "" or process(otherPage) thisDemoTarget = thisDemoTarget=="" and "" or thisDemoTarget and process(thisDemoTarget) otherDemoTarget = otherDemoTarget=="" and "" or otherDemoTarget and process(otherDemoTarget) --Determine redirect targets (getTarget returns nil if page is not a redirect)local thisTarget = thisDemoTarget or mRedirect.getTarget(thisPage) local otherTarget = otherDemoTarget or mRedirect.getTarget(otherPage) --For double redirectslocal thisDoubleTarget = thisTarget and mRedirect.getTarget(thisTarget) local otherDoubleTarget = otherTarget and mRedirect.getTarget(otherTarget) -- Allow setting demo parameters to empty string to demonstrate a non-redirectthisTarget = thisDemoTarget~="" and thisTarget otherTarget = otherDemoTarget~="" and otherTarget --Errorslocal err if not thisTarget and exists(thisPage) then --Check existence of thisPage to avoid errors in preview mode elseif otherPage=="" then elseif not exists(otherPage) then elseif thisTarget==thisPage or (not exists(thisTarget) and exists(thisPage)) then elseif otherTarget and (otherTarget==otherPage or not exists(otherTarget)) then elseif otherPage==thisPage then elseif not otherTarget and thisTarget==otherPage then elseif otherPage==thisTarget and otherTarget==thisPage then elseif thisDoubleTarget and otherDoubleTarget and thisDoubleTarget==otherDoubleTarget then err = "Both this page and "..noredir(otherPage).." are double redirects. Please change the redirect target of both to " ..(mRedirect.luaIsRedirect(thisDoubleTarget) and "the correct article." or ""..thisDoubleTarget..".") elseif otherTarget and (thisTarget==otherPage or thisDoubleTarget==otherTarget) then err = "This is a double redirect." .." Please change the redirect target to "..otherTarget.."." elseif otherTarget and thisDoubleTarget then err = "This is a double redirect to "..thisDoubleTarget..", while " ..noredir(otherPage).." redirects to "..otherTarget.."." elseif thisDoubleTarget then elseif otherTarget==thisPage then err = noredir(otherPage).." is a double redirect." .." Please change its target to "..thisTarget.."." elseif otherDoubleTarget then err = noredir(otherPage).." is a double redirect" .." to "..otherDoubleTarget.." via "..otherTarget.."." elseif otherTarget and thisTarget~=otherTarget then end --Return either redirect template or errorlocal embed = args.embed local from, info, cat if not err or noError then if otherTarget then from = "an alternative title for '''"..noredir(otherPage).."''', another redirect to the same title" info = "Because double redirects are disallowed," .." both pages currently point to "..otherTarget..".\" .."**If and when "..noredir(otherPage).." is expanded into a separate" .." article, or its target article is renamed to "..noredir(otherPage)..", this" .." redirect will be recategorized to be changed to target that article instead." cat = demo and "" or "Avoided double redirects" else from = "an alternative title for '''"..otherPage.."''', a former redirect to the same title" info = "\**Since "..otherPage.." is now a separate article, please" .." update this redirect's target to "..otherPage.." and remove the" .." {{R avoided double redirect}} template." .."\**If "..otherPage.." is the wrong target for this redirect," .." edit this page and correct the page name in the template." cat = demo and "" or "Avoided double redirects to be updated" end return frame:expandTemplate({title="Redirect template", args={from=from,info=info,["main category"]=cat, name=(embed=="yes" and "From an avoided double redirect" or nil)}}) else return "Error in R avoided double redirect: "..err.."" ..(demo and "" or "") end end return p 1 : Avoided double redirects/error |
随便看 |
|
开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。