Documentation for this module may be created atModule:Ilh/doc
localilh={}localgetArgslocalyesno=require('Module:Yesno')localargs--local frameArgslocalCOMMON_TAIL='</span>'localMODEL={frame_head='<span class="ilh-all %s" data-orig-title="%s" data-lang-code="%s" data-lang-name="%s" data-foreign-title="%s">',frame_tail=COMMON_TAIL,page_head='<span class="ilh-page">',page_tail=COMMON_TAIL,comment_head='<span class="noprint ilh-comment">(',comment_tail=')'..COMMON_TAIL,lang_head='<span class="ilh-lang">',lang_tail=COMMON_TAIL,colon='<span class="ilh-colon">:</span>',link_head='<span class="ilh-link">',link_body='-{[[:%s:%s|<span lang="%s" dir="auto">%s</span>]]}-',link_tail=COMMON_TAIL}localclazz_pageExist_framehead='ilh-blue'localTRA_CAT='[[Category:Pages with a blue link but without removing the internal link helper template]]'functionilh.main(frame)ifnotgetArgsthengetArgs=require('Module:Arguments').getArgsendargs=getArgs(frame,{parentFirst=true})returnilh._ilh(arg)endfunctionilh._ilh(arg)--frameArgs = getArgs(frame, {frameOnly=true})localcontext={}context["isMainPage"]=ilh.isMainPage()context["localPage"]=args[1]context["foreignPage"]=args[2]orargs[1]--If {{{2}}} does not existcontext["displayName"]=ilh.displayName(args)context["langCode"]=args["lang-code"]context["lang"]=args["lang"]context["nocat"]=yesno(args["nocat"],false)context["isExist"]=(args["$exist$"]andargs["$exist$"]==1)orilh.isExist(context["localPage"])localcurPage_obj=mw.title.getCurrentTitle()context["isNoCatWithNamespace"]=curPage_obj:inNamespaces(2,828)--User,Module--context["curPageNamespace"]=curPage_obj.namespacereturn(context["isMainPage"]andilh.onlyLink(context))orilh.functionLink(context)endfunctionilh.onlyLink(context)return(context["isExist"]andmw.ustring.format('[[%s|%s]]',context["localPage"],context["displayName"]))orcontext["displayName"]endfunctionilh.functionLink(context)context["_localPage"]=mw.ustring.gsub(context["localPage"],'"','"')context["_foreignPage"]=mw.ustring.gsub(context["foreignPage"],'"','"')localneed_cat=(notcontext["nocat"])and(notcontext["isNoCatWithNamespace"])--[[not ( context["curPageNamespace"]==2 --Useror context["curPageNamespace"]==828 --Module )]]--mw.log(context["nocat"])--mw.log(context["curPageNamespace"])--mw.log(need_cat)localoutput_context={}table.insert(output_context,mw.ustring.format(MODEL.frame_head,(context["isExist"]andclazz_pageExist_framehead)or'',context["_localPage"],context["langCode"],context["lang"],context["_foreignPage"]))table.insert(output_context,MODEL.page_head)table.insert(output_context,mw.ustring.format('[[:%s|%s]]',context["localPage"],context["displayName"]))table.insert(output_context,MODEL.page_tail)ifcontext["isExist"]thenifneed_catthentable.insert(output_context,TRA_CAT)endelsetable.insert(output_context,MODEL.comment_head)table.insert(output_context,MODEL.lang_head)table.insert(output_context,context["lang"])table.insert(output_context,MODEL.lang_tail)table.insert(output_context,MODEL.colon)table.insert(output_context,MODEL.link_head)table.insert(output_context,mw.ustring.format(MODEL.link_body,context["langCode"],(context["foreignPage"]orcontext["localPage"]),context["langCode"],(context["foreignPage"]orcontext["localPage"])))table.insert(output_context,MODEL.link_tail)table.insert(output_context,MODEL.comment_tail)endtable.insert(output_context,MODEL.frame_tail)returntable.concat(output_context,"")endfunctionilh.displayName(args)local_d=args["d"]local_1=args["1"]local_3=args["3"]localdpN1=_3or_dreturn(dpN1and{dpN1}or{_1})[1]end--The following needs a more efficient implementation--Confirm homepage--Use mw information to get the homepage name--Use the language library to obtain the default language code (zh) of this site to determine the corresponding language of the information and obtain the full homepage name---Because other zh sub-languages have only names and no namespace, they can be recognized, but it is troublesome--Then determine whether the current page and the home page are consistent---Plan to do redirect judgment, but no needfunctionilh.isMainPage()localmainpage_msgobj=mw.message.new('Mainpage')mainpage_msgobj=mainpage_msgobj:inLanguage(mw.getContentLanguage():getCode())localmainPage_obj=mw.title.makeTitle(0,mainpage_msgobj:plain())localcurpage_obj=mw.title.getCurrentTitle()--local curpage_redirectFrom_obj=curpage_obj.redirectTarget--[[if curpage_redirectFrom_obj ~=false thencurpage_obj=curpage_redirectFrom_objend]]returnmw.title.equals(mainPage_obj,curpage_obj)--and curpage_obj.namespace==4end--Make sure the page exists---exists is a high-cost method that requires a more efficient implementation--Packing method with protection--Because exists and parser function ifexist are both high-cost methods--And if ifexist reaches the limit, the operation that returns the result as false by default--And exists will directly throw an error and interrupt execution--Therefore, the package will be called accordingly to suppress the throwing errors of exists. According to the concept of ifexist, it returns false--Under normal circumstances, everything is normalfunctionilh.isExist(pageName)localexecStatus,result=pcall(ilh._isExist,pageName)ifexecStatusthenreturnresultelsereturnfalseendend--real methodfunctionilh._isExist(pageName)locallocalPage_obj=mw.title.makeTitle(0,pageName)returnlocalPage_obj.existsend--endreturnilh