Module:Template link general
Appearance
![]() | This Lua module is used in system messages, and on approximately 3,560,000 pages, or roughly 6% of all pages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
![]() | This module is rated as ready for general use. It has reached a mature form and is thought to be relatively bug-free and ready for use wherever appropriate. It is ready to mention on help pages and other Wikipedia resources as an option for new users to learn. To reduce server load and bad output, it should be improved by sandbox testing rather than repeated trial-and-error editing. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
![]() | This module depends on the following other modules: |
Implements {{Template link general}} and other templates in its family
Basic usage
{{#invoke:Template link general|main}}
This module is used by {{Template link general}} and related templates to display links to templates. It is similar to {{Template link}} but with additional formatting options and the ability to include parameters in the display. See Template:Template link general § Parameters for the full list, which can be enabled by passing any value to them (such as "on", "yes", etc).
-- This implements Template:Template link general and various other templates in its familylocalgetArgs=require('Module:Arguments').getArgslocalp={}-- Is a string non-empty?localfunction_ne(s)returns~=nilands~=""endlocalnw=mw.text.nowikilocalfunctionaddTemplate(s)locali,_=s:find(':',1,true)ifi==nilthenreturn'Template:'..sendlocalns=s:sub(1,i-1)ifns==''ormw.site.namespaces[ns]thenreturnselsereturn'Template:'..sendendlocalfunctiontrimTemplate(s)localneedle='template:'ifs:sub(1,needle:len()):lower()==needlethenreturns:sub(needle:len()+1)elsereturnsendendlocalfunctionlinkTitle(args)if_ne(args.nolink)thenif_ne(args.subst)thenreturn'subst:'..args['1']elsereturnargs['1']endendlocaltitleObjlocaltitlePart='[['ifargs['1']then-- This handles :Page and other NStitleObj=mw.title.new(args['1'],'Template')elsetitleObj=mw.title.getCurrentTitle()endtitlePart=titlePart..(titleObj~=nilandtitleObj.fullTextoraddTemplate(args['1']))localtextPart=args.alttextifnot_ne(textPart)theniftitleObj~=nilthentextPart=titleObj:inNamespace("Template")andargs['1']ortitleObj.fullTextelse-- redlinktextPart=args['1']endendif_ne(args.subst)then-- HACK: the ns thing above is probably brokentextPart='subst:'..textPartendif_ne(args.brace)thentextPart=nw('{{')..textPart..nw('}}')elseif_ne(args.braceinside)thentextPart=nw('{')..textPart..nw('}')endtitlePart=titlePart..'|'..textPart..']]'if_ne(args.braceinside)thentitlePart=nw('{')..titlePart..nw('}')endreturntitlePartendfunctionp.main(frame)localargs=getArgs(frame,{trim=true,removeBlanks=false})returnp._main(args)endfunctionp._main(args)localbold=_ne(args.bold)or_ne(args.boldlink)or_ne(args.boldname)localitalic=_ne(args.italic)or_ne(args.italics)localdontBrace=_ne(args.brace)or_ne(args.braceinside)localcode=_ne(args.code)or_ne(args.tt)localshow_result=_ne(args._show_result)localexpand=_ne(args._expand)-- Build the link partlocaltitlePart=linkTitle(args)ifboldthentitlePart="'''"..titlePart.."'''"endif_ne(args.nowrapname)thentitlePart='<span class="nowrap">'..titlePart..'</span>'end-- Build the argumentslocaltextPart=""localtextPartBuffer="|"localcodeArguments={}localcodeArgumentsString=""locali=2localj=1whileargs[i]dolocalval=args[i]ifval~=""thenif_ne(args.nowiki)then-- Unstrip nowiki tags first because calling nw on something that already contains nowiki tags will-- mangle the nowiki strip marker and result in literal UNIQ...QINU showing upval=nw(mw.text.unstripNoWiki(val))endlocalk,v=string.match(val,"(.*)=(.*)")ifnotkthencodeArguments[j]=valj=j+1elsecodeArguments[k]=vendcodeArgumentsString=codeArgumentsString..textPartBuffer..valifitalicthenval='<span style="font-style:italic;">'..val..'</span>'endtextPart=textPart..textPartBuffer..valendi=i+1end-- final wraplocalret=titlePart..textPartifnotdontBracethenret=nw('{{')..ret..nw('}}')endif_ne(args.a)thenret=nw('*')..' '..retendif_ne(args.kbd)thenret='<kbd>'..ret..'</kbd>'endifcodethenret='<code>'..ret..'</code>'elseif_ne(args.plaincode)thenret='<code style="border:none;background:transparent;color:inherit">'..ret..'</code>'endif_ne(args.nowrap)thenret='<span class="nowrap">'..ret..'</span>'end--[[ Wrap as html?? local span = mw.html.create('span') span:wikitext(ret) --]]if_ne(args.debug)thenret=ret..'\n<pre>'..mw.text.encode(mw.dumpObject(args))..'</pre>'endifshow_resultthenlocalresult=mw.getCurrentFrame():expandTemplate{title=addTemplate(args[1]),args=codeArguments}ret=ret.." → "..resultendifexpandthenlocalquery=mw.text.encode('{{'..addTemplate(args[1])..string.gsub(codeArgumentsString,textPartBuffer,"|")..'}}')localurl=mw.uri.fullUrl('special:ExpandTemplates','wpInput='..query)mw.log()ret=ret.." ["..tostring(url).."]"endreturnretendreturnp