Module:Userlinks: Difference between revisions
From Test Wiki
m Saint moved page Module:UserLinks to Module:Userlinks without leaving a redirect |
|||
Line 1: | Line 1: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- | -- Userlinks -- | ||
-- This module creates a list of links about a given user. It can be used on -- | -- 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. -- | -- its own or from a template. See the /doc page for more documentation. -- | ||
Line 9: | Line 9: | ||
-- Lazily initialise modules that we might or might not need | -- Lazily initialise modules that we might or might not need | ||
local mExtra -- [[Module: | local mExtra -- [[Module:Userlinks/extra]] | ||
local mArguments -- [[Module:Arguments]] | local mArguments -- [[Module:Arguments]] | ||
local mToolbar -- [[Module:Toolbar]] | local mToolbar -- [[Module:Toolbar]] | ||
Line 17: | Line 17: | ||
-- Load shared helper functions | -- Load shared helper functions | ||
local mShared = require('Module: | local mShared = require('Module:Userlinks/shared') | ||
local raiseError = mShared.raiseError | local raiseError = mShared.raiseError | ||
local maybeLoadModule = mShared.maybeLoadModule | local maybeLoadModule = mShared.maybeLoadModule | ||
Line 38: | Line 38: | ||
-- indexed. This is made possible by the metatable and by the various link | -- indexed. This is made possible by the metatable and by the various link | ||
-- functions, some of which are defined here, and some of which are defined | -- functions, some of which are defined here, and some of which are defined | ||
-- at [[Module: | -- at [[Module:Userlinks/extra]]. | ||
--]=] | --]=] | ||
local links, linkFunctions = {}, {} | local links, linkFunctions = {}, {} | ||
Line 58: | Line 58: | ||
snippets.username | 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 | end | ||
Line 340: | Line 351: | ||
end | 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', | |||
'she', | |||
'they' | |||
) | |||
end | |||
---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ||
-- End of link functions | -- End of link functions | ||
Line 345: | Line 377: | ||
-- Define the metatable that memoizes the link functions, and fetches link | -- Define the metatable that memoizes the link functions, and fetches link | ||
-- functions from [[Module: | -- functions from [[Module:Userlinks/extra]] if necessary. | ||
-- Lazily initialise the extraLinkFunctions table. We only want to load | -- Lazily initialise the extraLinkFunctions table. We only want to load | ||
-- [[Module: | -- [[Module:Userlinks/extra]] as necessary, so it has a low transclusion | ||
-- count. | -- count. | ||
local extraLinkFunctions | local extraLinkFunctions | ||
Line 376: | Line 408: | ||
-- Here we use the distinction between false and nil to record | -- Here we use the distinction between false and nil to record | ||
-- whether we have already tried to load the /extra module. | -- whether we have already tried to load the /extra module. | ||
mExtra = maybeLoadModule('Module: | mExtra = maybeLoadModule('Module:Userlinks/extra') | ||
end | end | ||
if type(mExtra) == 'table' | if type(mExtra) == 'table' | ||
Line 471: | Line 503: | ||
-- | -- | ||
-- If you add a new snippet, please document it at | -- If you add a new snippet, please document it at | ||
-- [[Module: | -- [[Module:Userlinks#Adding new links]]. | ||
--]=] | --]=] | ||
local snippets, snippetFunctions = {}, {} | local snippets, snippetFunctions = {}, {} | ||
Line 637: | Line 669: | ||
-- End snippet functions. If you add a new snippet function, please | -- End snippet functions. If you add a new snippet function, please | ||
-- document it at [[Module: | -- document it at [[Module:Userlinks#Adding new links]]. | ||
return snippets | return snippets | ||
Line 698: | Line 730: | ||
local options = {} | local options = {} | ||
options.isDemo = yesno(args.demo) or false | 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.toolbarStyle = yesno(args.small) and 'font-size: 90%;' or nil | ||
options.sup = yesno(args.sup, true) | options.sup = yesno(args.sup, true) | ||
Line 723: | Line 756: | ||
function p.export(codes, links, options) | function p.export(codes, links, options) | ||
-- Make the user link. | -- Make the user link. | ||
local userLink = links.u | local userLink = options.noPing and links.np or links.u | ||
-- If we weren't passed any link codes, just return the user link. | -- If we weren't passed any link codes, just return the user link. | ||
Line 786: | Line 819: | ||
return links[code] | return links[code] | ||
end | end | ||
return p | return p |