Content deleted Content added
localise snippet project values and add a default projectLong value |
Sohom Datta (talk | contribs) others |
||
(52 intermediate revisions by 14 users not shown) | |||
Line 1:
--------------------------------------------------------------------------------
-- UserLinks --
-- This module creates a list of links about a given user. It can be used on --
-- its own or from a template. See the /doc page for more documentation. --
--------------------------------------------------------------------------------
-- Require necessary modules
local yesno = require('Module:Yesno')
Line 13 ⟶ 19:
local mShared = require('Module:UserLinks/shared')
local raiseError = mShared.raiseError
local maybeLoadModule = mShared.maybeLoadModule
local makeWikitextError = mShared.makeWikitextError
local makeWikilink = mShared.makeWikilink
Line 41 ⟶ 48:
-- data snippets. New link functions should be added below the existing
-- functions.
----------------------------------------------------------------------------
Line 54 ⟶ 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 71 ⟶ 86:
snippets.interwiki,
-1,
'
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
0,
'ec/' .. snippets.toolLang .. '.' .. snippets.projectLong .. '.org/' .. snippets.username,
message('display-count')
)
Line 108 ⟶ 132:
'Log/' .. snippets.username,
message('display-logs')
)
end
function linkFunctions.ae(snippets)
-- Automated edits (and non-automated contributions).
return makeWikilink(
'xtools',
0,
'autoedits/' .. snippets.toolLang .. '.' .. snippets.projectLong .. '.org/' .. snippets.username,
message('display-autoedits')
)
end
Line 174 ⟶ 208:
function linkFunctions.es(snippets)
-- Edit summaries
return
0,
'editsummary/' .. snippets.toolLang .. '.' .. snippets.projectLong .. '.org/' .. snippets.username,
message('display-editsummaries')
)
Line 204 ⟶ 232:
-1,
'ListUsers',
{limit = 1,
message('display-listuser')
)
Line 290 ⟶ 318:
action = 'query',
list = 'users',
usprop = 'groups|editcount',
ususers = snippets.username
}
Line 305 ⟶ 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 322 ⟶ 373:
-- Define functions for shared code in the metatable.
local function validateCode(code)
-- Checks whether code is a valid link code - i.e. checks that it is a
-- string and that it is not the blank string. Returns the code if
-- the check passes, and nil if not.
if type(code) == 'string' and code ~= '' then
return code
else
return nil
end
end
local function getExtraLinkFunctions()
-- Loads the table of extra link functions from the /extra module.
-- If there is a problem with loading it, return false. We use the
-- distinction between false and nil to record whether we have already
-- tried to load it.
if extraLinkFunctions ~= nil then
return extraLinkFunctions
end
if mExtra == nil then
-- If loading the module fails, maybeLoadModule returns false.
-- Here we use the distinction between false and nil to record
-- whether we have already tried to load the /extra module.
mExtra = maybeLoadModule('Module:UserLinks/extra')
end
if type(mExtra) == 'table'
and type(mExtra.linkFunctions) == 'table'
Line 585 ⟶ 636:
function snippetFunctions.fullDomain()
-- The full ___domain name of the site, e.g. www.mediawiki.org,
-- en.
local fullDomain
local lang = getSnippet('toolLang')
Line 608 ⟶ 659:
return snippets
end
function p.validateProjectCode(s)
Line 616 ⟶ 667:
-- returns nil for both.
interwikiTable = interwikiTable or mw.loadData('Module:InterwikiTable')
end
end
Line 666 ⟶ 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 676 ⟶ 728:
-- Gets the link codes from the arguments. The codes aren't validated
-- at this point.
mTableTools =
local codes
if mTableTools then codes = mTableTools.compressSparseArray(args) else
codes = {}
for i, code in ipairs(args) do
codes[i] = code
end
end
return codes
end
Line 683 ⟶ 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 702 ⟶ 762:
local toolbar = mToolbar.main(toolbarArgs)
-- Apply the sup option
if options.sup then
toolbar = '<sup>' .. toolbar .. '</sup>'
end
-- If we are transcluding, add a non-breaking space, but if we are substing
-- just use a normal space
local space = mw.isSubsting() and ' ' or ' '
return userLink .. space .. toolbar
end
Line 741 ⟶ 806:
return links[code]
end
return p
|