Module:UserLinks: Difference between revisions

918 bytes removed ,  9 months ago
including these imply the lack of a secondary preference, which MW does not support
(username removed)
m (1 revision imported from loginwiki:Module:UserLinks: Updating template with latest edits from loginwiki)
(including these imply the lack of a secondary preference, which MW does not support)
Line 58:
snippets.username
)
end
function linkFunctions.np(snippets)
-- User page (no ping)
return '<span class="plainlinks">' .. makeFullUrlLink(
snippets.interwiki,
2,
snippets.username,
'',
snippets.username
) .. '</span>'
end
 
Line 340 ⟶ 351:
end
function linkFunctions.nuke(snippets)
-- Mass delete/Special:Nuke
return t1[1] < t2[1]makeWikilink(
snippets.interwiki,
-1,
'Nuke/' .. snippets.username,
message('display-nuke')
)
end
 
function linkFunctions.gender(snippets)
-- Gender
return mw.getCurrentFrame():callParserFunction(
'GENDER',
snippets.username,
'he',
'she',
'they'
)
end
 
----------------------------------------------------------------------------
-- End of link functions
Line 698 ⟶ 730:
local options = {}
options.isDemo = yesno(args.demo) or false
options.noPing = yesno(args.noPing) or yesno(args.noping) or yesno(args.np) or false
options.toolbarStyle = yesno(args.small) and 'font-size: 90%;' or nil
options.sup = yesno(args.sup, true)
Line 723 ⟶ 756:
function p.export(codes, links, options)
-- Make the user link.
local userLink = options.noPing and links.np or links.u
 
-- If we weren't passed any link codes, just return the user link.
Line 786 ⟶ 819:
return links[code]
end
 
--------------------------------------------------------------------------------
-- Link table
--------------------------------------------------------------------------------
 
function p.linktable()
-- Returns a wikitext table of link codes, with an example link for each
-- one. This function doesn't take any arguments, so it can be accessed
-- directly from wiki pages without using makeInvokeFunction.
local args = {user = 'Example'}
local snippets = p.getSnippets(args)
local links = p.getLinks(snippets)
 
-- Assemble the codes and links in order
local firstCodes = {'u', 't', 'c'}
local firstLinks, firstCodesKeys = {}, {}
for i, code in ipairs(firstCodes) do
firstCodesKeys[code] = true
firstLinks[#firstLinks + 1] = {code, links[code]}
end
local secondLinks = {}
for code, link in pairs(links) do
if not firstCodesKeys[code] then
secondLinks[#secondLinks + 1] = {code, link}
end
end
table.sort(secondLinks, function(t1, t2)
return t1[1] < t2[1]
end)
local links = {}
for i, t in ipairs(firstLinks) do
links[#links + 1] = t
end
for i, t in ipairs(secondLinks) do
links[#links + 1] = t
end
 
-- Output the code table in table format
local ret = {}
ret[#ret + 1] = '{| class="wikitable plainlinks sortable"'
ret[#ret + 1] = '|-'
ret[#ret + 1] = '! ' .. message('linktable-codeheader')
ret[#ret + 1] = '! ' .. message('linktable-previewheader')
for i, t in ipairs(links) do
local code = t[1]
local link = t[2]
ret[#ret + 1] = '|-'
ret[#ret + 1] = "| '''" .. code .. "'''"
ret[#ret + 1] = '| ' .. link
end
ret[#ret + 1] = '|}'
return table.concat(ret, '\n')
end
 
return p
Anonymous user