3,471
edits
m (1 revision imported) |
|||
(4 intermediate revisions by 4 users not shown) | |||
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 48: | Line 48: | ||
-- data snippets. New link functions should be added below the existing | -- data snippets. New link functions should be added below the existing | ||
-- functions. | -- functions. | ||
---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ||
Line 61: | 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 81: | Line 89: | ||
message('display-contributions') | 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 | end | ||
Line 87: | Line 109: | ||
return makeUrlLink( | return makeUrlLink( | ||
{ | { | ||
host = ' | host = 'xtools.wmflabs.org', | ||
path = '/ | path = '/ec/', | ||
query = { | query = { | ||
username = snippets.username, | |||
project = snippets.toolLang .. '.' .. snippets.projectLong .. '.org' | project = snippets.toolLang .. '.' .. snippets.projectLong .. '.org' | ||
} | } | ||
Line 115: | Line 137: | ||
'Log/' .. snippets.username, | 'Log/' .. snippets.username, | ||
message('display-logs') | message('display-logs') | ||
) | |||
end | |||
function linkFunctions.ae(snippets) | |||
-- Automated edits (and non-automated contributions). | |||
return makeUrlLink( | |||
{ | |||
host = 'xtools.wmflabs.org', | |||
path = '/autoedits/', | |||
query = { | |||
username = snippets.username, | |||
project = snippets.toolLang .. '.' .. snippets.projectLong .. '.org' | |||
} | |||
}, | |||
message('display-autoedits') | |||
) | ) | ||
end | end | ||
Line 183: | Line 220: | ||
return makeUrlLink( | return makeUrlLink( | ||
{ | { | ||
host = ' | host = 'xtools.wmflabs.org', | ||
path = ' | path = '/editsummary/', | ||
query = { | query = { | ||
username = snippets.username, | |||
project = snippets.toolLang .. '.' .. snippets.projectLong .. '.org' | |||
} | } | ||
}, | }, | ||
Line 315: | 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 320: | 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 351: | 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 446: | 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 612: | 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 | ||
end | end | ||
function p.validateProjectCode(s) | function p.validateProjectCode(s) | ||
Line 623: | Line 680: | ||
-- returns nil for both. | -- returns nil for both. | ||
interwikiTable = interwikiTable or mw.loadData('Module:InterwikiTable') | interwikiTable = interwikiTable or mw.loadData('Module:InterwikiTable') | ||
for key, t in pairs(interwikiTable) do | |||
for i, prefix in ipairs(t.iw_prefix) do | |||
if s == prefix then | |||
return s, key | |||
end | |||
end | |||
end | |||
return nil, nil | |||
end | end | ||
Line 673: | 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 698: | 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 761: | Line 819: | ||
return links[code] | return links[code] | ||
end | end | ||
return p | return p |