User:Paine Ellsworth/Module:R from acronym

See code in edit screen.["..link.." "..page.."] " end local function process(page) return mw.title.new(page).prefixedText end local function exists(page) return mw.title.new(page).exists 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. thisDemoTarget = thisDemoTarget=="" and "" or thisDemoTarget and process(thisDemoTarget)

--Determine redirect targets (getTarget returns nil if page is not a redirect) local thisTarget = thisDemoTarget or mRedirect.getTarget(thisPage) --For double redirects local thisDoubleTarget = thisTarget and mRedirect.getTarget(thisTarget) -- Allow setting demo parameters to empty string to demonstrate a non-redirect thisTarget = thisDemoTarget~="" and thisTarget

--Errors local err if not thisTarget and exists(thisPage) then --Check existence of thisPage to avoid errors in preview mode err = "This page is not a redirect." elseif thisTarget==thisPage or (not exists(thisTarget) and exists(thisPage)) then err = "This is a broken redirect (it redirects to itself or to a non-existing page)." elseif thisDoubleTarget then err = "This is a double redirect to "..thisDoubleTarget.."." end

--Return either redirect template or error local embed = args.embed local from, info, cat if not err or noError then from = "an acronym to a related topic, such as the expansion of the acronym" info = "** Remember that an acronym is a special type of initialism that can be spoken as a word, such as NATO and RADAR." .."\n** Use for abbreviations that have letters that are pronounced separately, such as OAU, and USSR." cat = demo and "" or "Redirects from acronyms"

return frame:expandTemplate({title="Redirect template",                              args={from=from,info=info,["main category"]=cat,                                     name=(embed=="yes" and "R from acronym" or nil)}}) else return "Error in Module:Sandbox/X. Perry Mentor/Rcat: "..err.." " ..(demo and "" or "") end

end

return p-->