This module searches a Portal_talk: page's portal page, and returns an appropriate message based if {{Portal maintenance status}} is found in the page's wikitext, and which parameters are used.
An error is reported if this module is used outside of the Portal_talk namespace. It can be demonstrated, in any namespace, with the |demo= and |demo2= parameters, which take the name of templates to "find" (instead of actually searching a page).
If the portal contains {{Portal maintenance status|date=January 2025|manual=yes|nonstandard=yes|subpages=single|incomplete=yes|note=Lorem ipsum dolor sit amet.}}
localp={}functioncleanupArgs(argsTable)localcleanArgs={}forkey,valinpairs(argsTable)doiftype(val)=='string'thenval=val:match('^%s*(.-)%s*$')ifval~=''thencleanArgs[key]=valendelsecleanArgs[key]=valendendreturncleanArgsendlocalcontent={}functionmakeTemplatePattern(template)localfirst=string.sub(template,1,1)localrest=string.sub(template,2)localpattern=mw.ustring.format('%s[%s%s]%s%s','%{%{%s*',mw.ustring.upper(first),mw.ustring.lower(first),rest,'%s*|?[^%}]*%}%}')returnpatternendfunctionmakeParameterPattern(parameter)returnmw.ustring.format('%s%s%s%s','|%s*',parameter,'%s*=%s*','([^|%}]*)','%s*[|%}]')endfunctiongetMatchingTemplateWikitext(content,template,leadOnly)ifleadOnlythencontent=mw.ustring.gsub(content,"%c%s*==.*","")-- remove first ==Heading== and everything after itendfortemplateWikitextinmw.ustring.gmatch(content,'%b{}')dolocalisCorrectTemplate=mw.ustring.match(templateWikitext,makeTemplatePattern(template))ifisCorrectTemplatethenreturntemplateWikitextendendreturnfalseendfunctiongetSubjectPageContent(contentNamespaceNumber)localnamespace=mw.site.namespaces[contentNamespaceNumber]["name"]localtalkTitle=mw.title.getCurrentTitle()iftalkTitle.namespace~=contentNamespaceNumber+1thenreturnerror('Wrong namespace',0)endlocalsubjectTitle=mw.title.new(namespace..":"..talkTitle.text)returnsubjectTitle:getContent()end-- historical function-- Looks for {{Historical}} on a Wikipedia_talk: page's related project page.-- Returns 'yes' if found or '' (empty string) if not found, or an error if used in the wrong namespace.p.historical=function(frame)localparent=frame.getParent(frame)localargs=cleanupArgs(frame.args)localdemo=args.demoandtrueorfalselocalcontentifdemothenlocaldemoText=mw.ustring.gsub(args.demo,'%{%{%!%}%}','|')content='{{'..demoText..'}}'ifargs.demo2thenlocaldemo2Text=mw.ustring.gsub(args.demo2,'%{%{%!%}%}','|')content=portalContent..'{{'..demo2Text..'}}'endelsecontent=getSubjectPageContent(4)endcontent=mw.ustring.gsub(content,"<!%-%-.-%-%->","")-- remove HTML commentscontent=mw.ustring.gsub(content,"%c%s*==.*","")-- remove first ==Heading== and everything after itcontent=mw.ustring.gsub(content,"<noinclude>.-</noinclude>","")-- remove noinclude bitslocalisHistorical=mw.ustring.match(content,makeTemplatePattern('Historical'))andtrueorfalsereturnisHistoricaland'yes'or''end-- featured function-- Looks for {{Featured portal}} on a Portal_talk: page's related portal page.-- Returns 'yes' if found or '' (empty string) if not found, or an error if used in the wrong namespace.p.featured=function(frame)localparent=frame.getParent(frame)localargs=cleanupArgs(frame.args)localdemo=args.demoandtrueorfalselocalcontentifdemothenlocaldemoText=mw.ustring.gsub(args.demo,'%{%{%!%}%}','|')content='{{'..demoText..'}}'ifargs.demo2thenlocaldemo2Text=mw.ustring.gsub(args.demo2,'%{%{%!%}%}','|')content=portalContent..'{{'..demo2Text..'}}'endelsecontent=getSubjectPageContent(100)endcontent=mw.ustring.gsub(content,"<!%-%-.-%-%->","")-- remove HTML commentscontent=mw.ustring.gsub(content,"<noinclude>.-</noinclude>","")-- remove noinclude bitslocalisFeatured=mw.ustring.match(content,makeTemplatePattern('Featured portal'))andtrueorfalsereturnisFeaturedand'yes'or''end-- main function-- Looks for {{Portal maintenance status}} (or earlier deprecated templates) on a Portal_talk: page's related portal page.-- Returns an appropriate message string if found or '' (empty string) if not found, or an error if used in the wrong namespace.p.main=function(frame)localparent=frame.getParent(frame)localargs=cleanupArgs(frame.args)localdemo=args.demoandtrueorfalselocalportalContentifdemothenlocaldemoText=mw.ustring.gsub(args.demo,'%{%{%!%}%}','|')portalContent='{{'..demoText..'}}'ifargs.demo2thenlocaldemo2Text=mw.ustring.gsub(args.demo2,'%{%{%!%}%}','|')portalContent=portalContent..'{{'..demo2Text..'}}'endelseportalContent=getSubjectPageContent(100)endlocalstatus=getMatchingTemplateWikitext(portalContent,'Portal maintenance status')orgetMatchingTemplateWikitext(portalContent,'Portal flag')ifnotstatusthenreturn''endlocaloutput=mw.ustring.sub(status,0,-3)..'|embed=yes}}'returnframe:preprocess(output)endreturnp