localmHatnote=require('Module:Hatnote')localmHatlist=require('Module:Hatnote list')localmArguments--initialize lazilylocalmTableTools=require('Module:TableTools')localp={}functionp.redirectDistinguish(frame)mArguments=require('Module:Arguments')localargs=mArguments.getArgs(frame)returnp._redirectDistinguish(args)endfunctionp._redirectDistinguish(args)ifnotargs[1]thenreturnmHatnote.makeWikitextError('no redirect supplied','Template:Redirect-distinguish',args.category)endlocalredirectTitle=mw.title.new(args[1])localcurrentTitle=currentTitleormw.title.getCurrentTitle()ifstring.match(args[1],'REDIRECT%d+')orargs[1]=='TERM'orcurrentTitle.namespace~=0then--do nothingelseifnotredirectTitleornotredirectTitle.existsthenargs[1]=args[1]..'[[Category:Missing redirects]]'elseifnotredirectTitle.isRedirectthenifstring.find(redirectTitle:getContent(),'#invoke:RfD')thenargs[1]=args[1]..'[[Category:Articles with redirect hatnotes impacted by RfD]]'elseargs[1]=args[1]..'[[Category:Articles with redirect hatnotes needing review]]'endendifnotargs[2]thenreturnmHatnote.makeWikitextError('no page to be distinguished supplied','Template:Redirect-distinguish',args.category)endargs=mTableTools.compressSparseArray(args)--Assignment by removal here makes for convenient concatenation laterlocalredirect=table.remove(args,1)localtext=string.format('"%s" redirects here. Not to be confused with %s.',redirect,mHatlist.orList(args,true))returnmHatnote._hatnote(text)endreturnp