Module:UserLinks/sandbox: Difference between revisions

Content deleted Content added
Sandbox no ping
others
 
(19 intermediate revisions by 9 users not shown)
Line 15:
local mTableTools -- [[Module:TableTools]]
local interwikiTable -- [[Module:InterwikiTable]], loaded with mw.loadData
local mNoping -- [[Module:No ping]]
 
-- Load shared helper functions
Line 33 ⟶ 32:
--------------------------------------------------------------------------------
 
function p.getLinks(snippets, noping)
--[=[
-- Get a table of links that can be indexed with link codes. The table
Line 51 ⟶ 50:
----------------------------------------------------------------------------
 
function linkFunctions.u(snippets, noping)
-- User page
return makeWikilink(
local returnlink
snippets.interwiki,
if not noping then
2,
returnlink = makeWikilink(
snippets.interwikiusername,
snippets.username
2,
)
snippets.username,
end
snippets.username
)
function linkFunctions.np(snippets)
else
-- User page (no ping)
returnlink = mNoping._main({snippets.username})
return '<span class="plainlinks">' .. makeFullUrlLink(
end
snippets.interwiki,
return returnlink
2,
snippets.username,
'',
snippets.username
) .. '</span>'
end
 
Line 89 ⟶ 93:
function linkFunctions.c64(snippets)
-- Contributions
local first64 = snippets.username:match('^%x+:%x+:%x+:%x+:')
return makeWikilink(
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/' .. snippets.usernamefirst64 .. ':/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 134 ⟶ 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')
)
Line 210 ⟶ 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 340 ⟶ 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 413 ⟶ 429:
local link
if linkFunction then
link = linkFunction(snippets, noping)
links[code] = link
else
Line 444 ⟶ 460:
-- Allow built-in functions to overwrite extra functions.
for code, func in pairs(linkFunctions) do
local link = func(snippets, noping)
links[code] = link
end
Line 620 ⟶ 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 683 ⟶ 699:
local snippets = p.getSnippets(args)
local codes = p.getCodes(args)
local nplinks = optionsp.noping == "1"getLinks(snippets)
local links = p.getLinks(snippets, np)
-- Overload the built-in Lua error function to generate wikitext errors
-- meant for end users to see. This makes things harder to debug when
Line 702 ⟶ 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)
options.separator = args.separator
options.span = args.span
options.noping = args.noping
if(options.noping) then
mNoping = require('Module:No ping/sandbox')
end
return options
end
Line 731 ⟶ 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 772 ⟶ 784:
local options = p.getOptions(args)
local snippets = p.getSnippets(args)
local links = p.getLinks(snippets, options)
local code = args[1]
local success, link = pcall(p.exportSingle, links, code)
Line 794 ⟶ 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, false)
 
-- 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