localp={}localgetArgs=require('Module:Arguments').getArgslocalportalBar=require('Module:Portal bar')._mainp.main=function(frame)-- get module arguments and processlocalargs=getArgs(frame)localportalArgs={}ifargs.borderthenportalArgs.border=args.borderendlocaltalkpage=args.pageor''-- if the talk page isn't given, try to do something with the current page-- presently this assumes the template is called in mainspace; ought to work in Talk: alsoifmw.text.trim(talkpage)==''thentalkpage="Talk:"..mw.title.getCurrentTitle().textend-- get the talk page content; if it isn't there, abort and return nothinglocaltalkpagetitle=mw.title.new(talkpage)localtalkpagecontent=talkpagetitleandtalkpagetitle:getContent()if(nottalkpagecontent)thenreturnend-- chop off everything after the first main top level header.-- note this assumes all relevant Wikiproject notices appear in the top section!talkpagecontent=mw.ustring.gsub(talkpagecontent,"\n%s*==[^=\n]==%s*\n.*","")-- strip irrelevant templates; any common talk page templates can be put here-- NOTE do not add templates that wrap WikiProject templates, like the banner shell, or you'll lose one portal.-- NOTE any template in the following array is interpreted as pattern (special character meanings for +, -, etc.)localstripTemplates={'Talkheader','OnThisDay','auto archiving notice','User:MiszaBot','WikiProjectBannerShell','aan'}fori=1,#stripTemplatesdotalkpagecontent=mw.ustring.gsub(talkpagecontent,"{{"..stripTemplates[i],"")end-- now expand everything in the section fullytalkpagecontent=frame:preprocess(talkpagecontent)-- go through and look for portals and add them to an output stringlocalnextportal=mw.ustring.gmatch(talkpagecontent,"%[%[Portal:(.-)|(.-) portal%]%]")localportal=nextportal()localportallist={}whileportaldotable.insert(portallist,portal)portal=nextportal()end-- send the output string to Module:Portal barreturnportalBar(portallist,portalArgs)endp[""]=p.mainreturnp