Module:UserLinks/sandbox: Difference between revisions

Content deleted Content added
Handle link functions returning nil (to indicate that they should be omitted from this usage)
others
 
(34 intermediate revisions by 11 users not shown)
Line 15:
local mTableTools -- [[Module:TableTools]]
local interwikiTable -- [[Module:InterwikiTable]], loaded with mw.loadData
local mSu -- [[Module:Su]]
 
-- Load shared helper functions
Line 26 ⟶ 25:
local makeFullUrlLink = mShared.makeFullUrlLink
local message = mShared.message
local function makeWikilinkIfExists(namespace, page, display)
local title = mw.title.new(page, namespace)
if title and title.exists then
return makeWikilink("", namespace, page, display)
end
end
 
local p = {}
Line 65 ⟶ 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 85 ⟶ 89:
message('display-contributions')
)
end
function linkFunctions.c64(snippets)
-- Contributions
local first64 = snippets.username:match('^%x+:%x+:%x+:%x+:')
or snippets.username:match('^%x+:%x+:%x+:')
or snippets.username:match('^%x+:%x+:')
or snippets.username:match('^%x+:')
return first64 and makeWikilink(
snippets.interwiki,
-1,
'Contribs/' .. first64 .. ':/64',
'(/64)'
) or ''
end
 
function linkFunctions.ct(snippets)
-- Edit count
return makeUrlLinkmakeWikilink(
{'xtools',
0,
host = 'xtools.wmflabs.org',
'ec/' .. snippets.toolLang .. '.' .. snippets.projectLong .. '.org/' .. snippets.username,
path = '/ec/',
query = {
username = snippets.username,
project = snippets.toolLang .. '.' .. snippets.projectLong .. '.org'
}
},
message('display-count')
)
Line 124 ⟶ 137:
function linkFunctions.ae(snippets)
-- Automated edits (and non-automated contributions).
return makeUrlLinkmakeWikilink(
{'xtools',
0,
host = 'xtools.wmflabs.org',
'autoedits/' .. snippets.toolLang .. '.' .. snippets.projectLong .. '.org/' .. snippets.username,
path = '/autoedits/',
query = {
username = snippets.username,
project = snippets.toolLang .. '.' .. snippets.projectLong .. '.org'
}
},
message('display-autoedits')
)
end
 
function linkFunctions.arb(snippets)
return makeWikilinkIfExists(
4,
"Requests for arbitration/" .. snippets.username,
"rfarb"
)
end
function linkFunctions.bl(snippets)
-- Block log
Line 208:
function linkFunctions.es(snippets)
-- Edit summaries
return makeUrlLinkmakeWikilink(
{'xtools',
0,
host = 'xtools.wmflabs.org',
'editsummary/' .. snippets.toolLang .. '.' .. snippets.projectLong .. '.org/' .. snippets.username,
path = '/editsummary/',
query = {
username = snippets.username,
project = snippets.toolLang .. '.' .. snippets.projectLong .. '.org'
}
},
message('display-editsummaries')
)
Line 228 ⟶ 223:
'Log/delete/' .. snippets.username,
message('display-deletions')
)
end
 
function linkFunctions.lta(snippets)
return makeWikilinkIfExists(
4,
"Long-term abuse/" .. snippets.username
"lta"
)
end
Line 320 ⟶ 307:
message('display-rfa')
)
end
function linkFunctions.rfcuser(snippets)
return makeWikilinkIfExists(
4,
"Wikipedia:Requests for comment" .. snippets.username,
"rfcuser"
)
end
function linkFunctions.rfcheckuser(snippets)
return makeWikilinkIfExists(
snippets.interwiki,
4,
"Requests for checkuser/Case/" .. snippets.username,
"rfcu"
)
end
function linkFunctions.spi(snippets)
return makeWikilinkIfExists(
snippets.interwiki,
4,
"Sockpuppet investigations/" .. snippets.username,
"spi"
)
end
function linkFunctions.socks(snippets)
sspLink = makeWikilinkIfExists(
snippets.interwiki,
4,
"Suspected sock puppets investigations/" .. snippets.username,
"ssp"
)
local confirmed = mw.title.new('Wikipedia sockpuppets of ' .. snippets.username, 14)
local suspected = mw.title.new('Suspected Wikipedia sockpuppets of ' .. snippets.username, 14)
if confirmed and confirmed.exists or suspected and suspected.exists then
local sup, sub
if confirmed and confirmed.exists then
sup = '&ensp;' .. makeWikilink(
':' .. confirmed.prefixedText,
'confirmed&nbsp;socks'
)
end
if suspected and suspected.exists then
sub = '&ensp;' .. makeWikilink(
':' .. suspected.prefixedText,
'suspected&nbsp;socks'
)
end
mSu = maybeLoadModule("Module:Su")
if mSu then
return (ssp or "") .. mSu._main(sup, sub)
end
end
return ssp
end
 
Line 400 ⟶ 333:
'ListFiles/' .. snippets.username,
message('display-uploads')
)
end
function linkFunctions.nuke(snippets)
-- Mass delete/Special:Nuke
return makeWikilink(
snippets.interwiki,
-1,
'Nuke/' .. snippets.username,
message('display-nuke')
 
)
end
function linkFunctions.gender(snippets)
-- Gender
return mw.getCurrentFrame():callParserFunction(
'GENDER',
snippets.username,
'he/him',
'she/her',
'they/them'
)
end
Line 426 ⟶ 382:
end
end
 
local function getExtraLinkFunctions()
-- Loads the table of extra link functions from the /extra module.
Line 452 ⟶ 409:
local function memoizeExtraLink(code, func)
local success, link = pcall(func, snippets)
if link ~= nilsuccess and type(link) ~== "'string"' then
success = false
link = nil
end
if success then
links[code] = link
return link
end
return success, linknil
end
 
Line 474 ⟶ 428:
local linkFunction = linkFunctions[code]
local link
local success = false
if linkFunction then
link = linkFunction(snippets)
links[code] = link
success = true
else
extraLinkFunctions = getExtraLinkFunctions()
Line 484 ⟶ 436:
local extraLinkFunction = extraLinkFunctions[code]
if type(extraLinkFunction) == 'function' then
success, link = memoizeExtraLink(code, extraLinkFunction)
end
end
end
if successlink then
return link
else
Line 518 ⟶ 470:
return links
end
 
--------------------------------------------------------------------------------
-- User data snippets
Line 683 ⟶ 636:
function snippetFunctions.fullDomain()
-- The full ___domain name of the site, e.g. www.mediawiki.org,
-- en.wikpediawikipedia.org, or ja.wikibooks.org.
local fullDomain
local lang = getSnippet('toolLang')
Line 764 ⟶ 717:
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 789 ⟶ 743:
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 852 ⟶ 806:
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