Module:Clickable button: Difference between revisions

Content deleted Content added
Anton (talk | contribs)
 
Removing the number 2.
 
(3 intermediate revisions by 3 users not shown)
Line 5:
local p = {}
 
local function p.mainrenderTrackingCategories(frameargs)
if yesno(args.category) == false then
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Clickable button 2'
})
return p.luaMain(args)
end
 
function p.luaMain(args)
if not args[1] and not args.url then
return ''
end
local data = p.makeLinkData(args)
-- we have no tracking categories currently but args.category should be
local link = p.renderLink(data)
-- supported into the future, so just return a string here for now
local trackingCategories = p.renderTrackingCategories(args)
return link .. trackingCategories''
end
 
local function p.makeLinkData(args)
local data = {}
 
-- Get the link and display values, and find whether we are outputting a
-- and find whether we are outputting
-- a wikilink or a URL.
if args.url then
data.isUrl = true
Line 32 ⟶ 26:
if args[1] then
data.display = args[1]
else if args[2] then
data.display = args[2]
else
data.display = args.url
p.urlisdisplay = true
end
end
else
data.isUrl = false
p.urlisdisplay = false
data.link = args[1]
if args[2] then
Line 44 ⟶ 43:
end
end
if yesno(args.link) == false then
p.nolink = true
end
 
-- Colours
-- For the merge with {{clickable button}}
local colour = args.color and args.color:lower()
 
-- Classes
Line 60 ⟶ 67:
table.insert(data.classes, 'mw-ui-button')
end
--If class is unset,
--then let color determine class
if not class then
if colour == 'blue' then
or class == 'mw-ui-button-blueprogressive'
else if colour == 'red' then
or class == 'mw-ui-button-reddestructive'
else if colour == 'green' then
class = 'mw-ui-constructive'
end
end
end
end
 
if class then
table.insert(data.classes, class)
Line 77 ⟶ 99:
currentTitle = mw.title.getCurrentTitle()
success, linkTitle = pcall(mw.title.new, args[1])
elseif p.urlisdisplay then
currentTitle = mw.title.getCurrentTitle()
end
if success
and linkTitle
and mw.title.equals(currentTitle, linkTitle)
and not p.urlisdisplay
then
if class == 'ui-button-blue'
Line 87 ⟶ 112:
then
data.backgroundColor = '#2962CB'
data.color = '#fff'
elseif class == 'ui-button-green' then
data.backgroundColor = '#008B6D'
Line 94 ⟶ 120:
data.backgroundColor = '#CCC'
data.color = '#666'
end
else
if p.urlisdisplay
then
data.dummyLink = tostring(currentTitle)
end
end
Line 103 ⟶ 134:
end
 
local function p.renderLink(data)
-- Render the display span tag.
local display
Line 124 ⟶ 155:
 
-- Render the link
local link
if datap.isUrlnolink then
if p.urlisdisplay then
link = string.format('[%s %s]', data.link, display)
link = string.format('[[%s|%s]]', data.linkdummyLink, display)
else
else
link = string.format('[[%s|%s]]', data.link, display)
link = string.format('%s', display)
end
else if data.isUrl then
link = string.format('[%s %s]', data.link, display)
else
link = string.format('[[%s|%s]]', data.link, display)
end
end
 
return string.format('<span class="plainlinks clickbutton">%s</span>', link)
end
 
function p.renderTrackingCategoriesluaMain(args)
-- If first arg or a url is not provided,
if yesno(args.category) == false then
-- but we have a second arg, make a button.
return ''
-- Otherwise, return nothing.
end
localif class =not args.class[1] and not args.class:lower()url then
if args[2] then
if class == 'ui-button-green'
p.nolink = true
or class == 'ui-button-blue'
else
or class == 'ui-button-red'
return ''
then
end
return '[[Category:Pages using old style ui-button-color]]'
else
return ''
end
local data = p.makeLinkData(args)
local link = p.renderLink(data)
local trackingCategories = p.renderTrackingCategories(args)
return link .. trackingCategories
end
 
function p.luaMainmain(argsframe)
local args = require('Module:Arguments').getArgs(frame, {
wrappers = 'Template:Clickable button 2'
})
return p.luaMain(args)
end