Jump to content
Wikipedia The Free Encyclopedia

Module:Template link general

From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
[画像:Warning] This Lua module is used in system messages, and on approximately 3,660,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 state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Page protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
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).

The above documentation is transcluded from Module:Template link general/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (edit) pages.
Subpages of this module.

 -- This implements Template:Template link general and various other templates in its family
 localgetArgs=require('Module:Arguments').getArgs
 localp={}

 -- Is a string non-empty?
 localfunction_ne(s)
 returns~=nilands~=""
 end

 localnw=mw.text.nowiki

 localfunctionaddTemplate(s)
 locali,_=s:find(':',1,true)
 ifi==nilthen
 return'Template:'..s
 end
 localns=s:sub(1,i-1)
 ifns==''ormw.site.namespaces[ns]then
 returns
 else
 return'Template:'..s
 end
 end

 localfunctiontrimTemplate(s)
 localneedle='template:'
 ifs:sub(1,needle:len()):lower()==needlethen
 returns:sub(needle:len()+1)
 else
 returns
 end
 end

 localfunctionlinkTitle(args)
 if_ne(args.nolink)then
 if_ne(args.subst)then
 return'subst:'..args['1']
 else
 returnargs['1']
 end
 end

 localtitleObj
 localtitlePart='[['
 ifargs['1']then
 -- This handles :Page and other NS
 titleObj=mw.title.new(args['1'],'Template')
 else
 titleObj=mw.title.getCurrentTitle()
 end

 titlePart=titlePart..(titleObj~=nilandtitleObj.fullTextor
 addTemplate(args['1']))

 localtextPart=args.alttext
 ifnot_ne(textPart)then
 iftitleObj~=nilthen
 textPart=titleObj:inNamespace("Template")andargs['1']ortitleObj.fullText
 else
 -- redlink
 textPart=args['1']
 end
 end

 if_ne(args.subst)then
 -- HACK: the ns thing above is probably broken
 textPart='subst:'..textPart
 end

 if_ne(args.brace)then
 textPart=nw('{{')..textPart..nw('}}')
 elseif_ne(args.braceinside)then
 textPart=nw('{')..textPart..nw('}')
 end

 titlePart=titlePart..'|'..textPart..']]'
 if_ne(args.braceinside)then
 titlePart=nw('{')..titlePart..nw('}')
 end
 returntitlePart
 end

 functionp.main(frame)
 localargs=getArgs(frame,{
 trim=true,
 removeBlanks=false
 })
 returnp._main(args)
 end

 functionp._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 part
 localtitlePart=linkTitle(args)
 ifboldthentitlePart="'''"..titlePart.."'''"end
 if_ne(args.nowrapname)thentitlePart='<span class="nowrap">'..titlePart..'</span>'end

 -- Build the arguments
 localtextPart=""
 localtextPartBuffer="&#124;"
 localcodeArguments={}
 localcodeArgumentsString=""
 locali=2
 localj=1
 whileargs[i]do
 localval=args[i]
 ifval~=""then
 if_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 up
 val=nw(mw.text.unstripNoWiki(val))
 end
 localk,v=string.match(val,"(.*)=(.*)")
 ifnotkthen
 codeArguments[j]=val
 j=j+1
 else
 codeArguments[k]=v
 end
 codeArgumentsString=codeArgumentsString..textPartBuffer..val
 ifitalicthen
 val='<span style="font-style:italic;">'..val..'</span>'
 end
 textPart=textPart..textPartBuffer..val
 end
 i=i+1
 end

 -- final wrap
 localret=titlePart..textPart
 ifnotdontBracethenret=nw('{{')..ret..nw('}}')end
 if_ne(args.a)thenret=nw('*')..'&nbsp;'..retend
 if_ne(args.kbd)thenret='<kbd>'..ret..'</kbd>'end
 ifcodethen
 ret='<code>'..ret..'</code>'
 elseif_ne(args.plaincode)then
 ret='<code style="border:none;background:transparent;color:inherit">'..ret..'</code>'
 end
 if_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>'end

 ifshow_resultthen
 localresult=mw.getCurrentFrame():expandTemplate{title=addTemplate(args[1]),args=codeArguments}
 ret=ret.." → "..result
 end

 ifexpandthen
 localquery=mw.text.encode('{{'..addTemplate(args[1])..string.gsub(codeArgumentsString,textPartBuffer,"|")..'}}')
 localurl=mw.uri.fullUrl('special:ExpandTemplates','wpInput='..query)
 mw.log()
 ret=ret.." ["..tostring(url).."]"
 end

 returnret
 end

 returnp

AltStyle によって変換されたページ (->オリジナル) /