Wrapper templates that only require reading fromparentFrame(). Positional arguments using template parameters (e.g.,{{{var|}}}) are ignored, ascurrentFrame() is not used. Improves performance by avoiding argument checks in both frames.
Returns: string|nil wikitextOutput Wikitext for insertion on a wiki page.
Thismodule is rated asready 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 onhelp pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed throughsandbox testing rather than repeated trial-and-error editing.
This Lua module is used in system messages, and onapproximately 1,130,000 pages, or roughly 2% 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 ownmodule sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on thetalk page before implementing them.
This module depends on the following other modules:
To use this module from wikitext, you should normally use the{{Clickable button}} template. However, it can also be used with the syntax{{#invoke:Clickable button|main|arguments}}. Please see the template page for a list of available parameters.
Usage from Lua modules
To use this module from other Lua modules, first load the module.
You can then generate a button using the.main function.
mClickableButton.main(args)
Theargs variable should be a table containing the arguments to pass to the module. To see the different arguments that can be specified and how they affect the module output, please refer to the{{Clickable button}} template documentation.
-- This module implements {{clickable button 2}}.localyesno=require('Module:Yesno')localdelink=require('Module:Delink')._delinklocalp={}functionp.main(frame)localgetArgs=require('Module:Arguments').getArgslocalargs=getArgs(frame)returnp._main(args)endfunctionp._main(args)-- If first arg or a url is not provided,-- but we have a second arg, make a button.-- Otherwise, return nothing.args.originalInput=args[1]args[1]=delink({args[1]})ifargs[1]==""thenargs[1]=nilendifnotargs[1]andnotargs.urlthenifargs[2]thenp.nolink=trueelsereturn''endendlocaldata=p.makeLinkData(args)locallink=p.renderLink(args.originalInput,data)localtrackingCategories=p.renderTrackingCategories(args)returnlink..trackingCategoriesendfunctionp.makeLinkData(args)localdata={}-- Get the link and display values,-- and find whether we are outputting-- a wikilink or a URL.ifargs.urlthendata.isUrl=truedata.link=args.urlifargs[1]thendata.display=args[1]elseifargs[2]thendata.display=args[2]elsedata.display=args.urlp.urlisdisplay=trueendelsedata.isUrl=falsep.urlisdisplay=falsedata.link=args[1]ifargs[2]thendata.display=args[2]elsedata.display=args[1]endifargs[1]andargs[1]:find('http')thendata.isUrl=trueendendifyesno(args.link)==falsethenp.nolink=trueend-- Colours-- For the merge with {{clickable button}}localcolour=args.colorandargs.color:lower()-- Classeslocalclass=args.classandargs.class:lower()data.classes={}ifclass=='ui-button-green'orclass=='ui-button-blue'orclass=='ui-button-red'thentable.insert(data.classes,'submit ui-button ui-widget ui-state-default ui-corner-all'..' ui-button-text-only ui-button-text')elsetable.insert(data.classes,'mw-ui-button')end--If class is unset,--then let color determine classifnotclassthenifcolour=='blue'thenclass='mw-ui-progressive'elseifcolour=='red'thenclass='mw-ui-destructive'elseifcolour=='green'thenclass='mw-ui-constructive'endendifclassthentable.insert(data.classes,class)end-- Stylesdo--[[-- Check whether we are on the same page as we have specified in-- args[1], but not if we are using a URL link, as then args[1] is only-- a display value. If we are currently on the page specified in-- args[1] make the button colour darker so that it stands out from-- other buttons on the page.--]]localsuccess,linkTitle,currentTitleifnotdata.isUrlthencurrentTitle=mw.title.getCurrentTitle()success,linkTitle=pcall(mw.title.new,args[1])elseifp.urlisdisplaythencurrentTitle=mw.title.getCurrentTitle()endifsuccessandlinkTitleandmw.title.equals(currentTitle,linkTitle)andnotp.urlisdisplaythenifclass=='ui-button-blue'orclass=='mw-ui-progressive'orclass=='mw-ui-constructive'thendata.backgroundColor='#2962CB'data.color='#fff'elseifclass=='ui-button-green'thendata.backgroundColor='#008B6D'elseifclass=='ui-button-red'orclass=='mw-ui-destructive'thendata.backgroundColor='#A6170F'elsedata.backgroundColor='#CCC'data.color='#666'endelseifp.urlisdisplaythendata.dummyLink=tostring(currentTitle)end-- Add user-specified styles.data.style=args.styleendreturndataendfunctionp.renderLink(originalInput,data)-- Render the display span tag.localdisplaydolocaldisplaySpan=mw.html.create('span')fori,classinipairs(data.classesor{})dodisplaySpan:addClass(class)enddisplaySpan:css{['background-color']=data.backgroundColor,color=data.color}ifdata.stylethendisplaySpan:cssText(data.style)enddisplaySpan:wikitext(data.display)display=tostring(displaySpan)end-- Render the linklocallinkiforiginalInputandoriginalInput:find('|')thenlink=string.format('[[%s|%s]]',delink({originalInput,wikilinks='target'}),display)elseifp.nolinkthenifp.urlisdisplaythenlink=string.format('[[%s|%s]]',data.dummyLink,display)elselink=string.format('%s',display)endelseifdata.isUrlthenlink=string.format('[%s %s]',data.link,display)elselink=string.format('[[%s |%s]]',data.link,display)endendreturnstring.format('<span class="plainlinks clickbutton">%s</span>',link)endfunctionp.renderTrackingCategories(args)ifyesno(args.category)==falsethenreturn''endlocalclass=args.classandargs.class:lower()ifclass=='ui-button-green'orclass=='ui-button-blue'orclass=='ui-button-red'thenreturn'[[Category:Pages using old style ui-button-color]]'elsereturn''endendreturnp