Module:UserLinks/sandbox: Difference between revisions

Content deleted Content added
Restore
others
 
(18 intermediate revisions by 9 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,
"Requests for comment/" .. snippets.username,
"rfcuser"
)
end
function linkFunctions.rfcheckuser(snippets)
return makeWikilinkIfExists(
4,
"Requests for checkuser/Case/" .. snippets.username,
"rfcu"
)
end
function linkFunctions.spi(snippets)
return makeWikilinkIfExists(
4,
"Sockpuppet investigations/" .. snippets.username,
"spi"
)
end
function linkFunctions.socks(snippets)
local ssp = makeWikilinkIfExists(
4,
"Suspected sock puppets/" .. snippets.username,
"ssp"
)
local confirmed = makeWikilinkIfExists(
14,
'Wikipedia sockpuppets of ' .. snippets.username,
'confirmed&nbsp;socks'
)
local suspected = makeWikilinkIfExists(
14,
'Suspected Wikipedia sockpuppets of ' .. snippets.username,
'suspected&nbsp;socks'
)
if confirmed or suspected then
mSu = maybeLoadModule("Module:Su")
if mSu then
return (ssp or "") .. mSu._main(confirmed, suspected)
end
end
return ssp
end
 
Line 392 ⟶ 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 418 ⟶ 382:
end
end
 
local function getExtraLinkFunctions()
-- Loads the table of extra link functions from the /extra module.
Line 444 ⟶ 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 466 ⟶ 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 476 ⟶ 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 510 ⟶ 470:
return links
end
 
--------------------------------------------------------------------------------
-- User data snippets
Line 675 ⟶ 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 756 ⟶ 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 781 ⟶ 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 845 ⟶ 807:
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
p.mei = makeWikilinkIfExists
return p