Anonymous user
Module:UserLinks: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
better tracking category handling, add check for the validity of the language prefix in project parameters, add interwiki support for more link types
(re-add support for the demo parameter to the error function) |
(better tracking category handling, add check for the validity of the language prefix in project parameters, add interwiki support for more link types) |
||
Line 3:
local u = {} -- Table for user-data helper strings.
local trackingCategories = {} -- Table for storing the tracking categories.
local demo
Line 56 ⟶ 57:
local function makeBlockLogLink()
local url = mw.uri.fullUrl(u.interwiki .. 'Special:Log/block', 'page=User:' .. u.usernameHtml)
return '[' .. tostring(url) .. ' block log]'
end
Line 89 ⟶ 90:
local function makeListUserLink()
local url = mw.uri.fullUrl(u.interwiki .. 'Special:ListUsers', 'limit=1&username=' .. u.usernameHtml)
return '[' .. tostring(url) .. ' list user]'
end
Line 98 ⟶ 99:
local function makeTargetLogsLink()
local url = mw.uri.fullUrl(u.interwiki .. 'Special:Log', 'page=User:' .. u.usernameHtml)
return '[' .. tostring(url) .. ' target logs]'
end
local function makeEditFilterLogLink()
local url = mw.uri.fullUrl(u.interwiki .. 'Special:AbuseLog', 'wpSearchUser=' .. u.usernameHtml)
return '[' .. tostring(url) .. ' edit filter log]'
end
Line 120 ⟶ 121:
local function makeRfaLink()
if u.project or u.lang then
end
return '[[Special:PrefixIndex/Wikipedia:Requests for adminship/' .. u.username .. '|RfA]]'
end
Line 166 ⟶ 170:
if numArgsExist == false then
return nil -- Don't return a toolbar if no numeric arguments exist.
else
return ToolbarBuilder.main(targs)
Line 172 ⟶ 176:
end
-- This function finds whether a string is a valid interwiki project prefix.
-- If the string is valid, the function outputs two values: true, and the site code
-- used in [[Module:InterwikiTable]]. If the string is valid, the function outputs
-- false and nil.
local function isKnownProject(prefix)
for
for _, iwCode in ipairs(projectVal.iw_prefix) do
if iwCode == prefix then
return true, projectCode
end
end
end
return false, nil
end
Line 194 ⟶ 202:
u.project = args.Project or args.project
u.lang = args.lang or args.Lang
return err('"' .. u.lang .. '" is not a valid language code')
end
-- Process the project value if it is present.
if u.project then
table.insert( trackingCategories, '[[Category:UserLinks transclusions with project parameters]]' )
-- If u.project is a known project, we don't need to do anything. If the project isn't known, first
-- check whether it is a valid language code, and if not then see if it's an interwiki code
Line 205 ⟶ 218:
u.project = nil
else
if pref1 and pref2 then
local pref2IsKnownProject, pref2ProjectCode = isKnownProject(pref2)
if pref1IsKnownProject
and mw.language.isKnownLanguageTag(pref2)
and interwikiTable[pref1ProjectCode].takes_lang_prefix then
u.project = pref1
u.lang = pref2
table.insert( trackingCategories, '[[Category:UserLinks transclusions with project parameters containing language codes]]' )
▲ elseif isKnownProject(pref2) and mw.language.isKnownLanguageTag(pref1) then
elseif pref2IsKnownProject
and mw.language.isKnownLanguageTag(pref1)
and interwikiTable[pref2ProjectCode].takes_lang_prefix then
u.project = pref2
u.lang = pref1
table.insert( trackingCategories, '[[Category:UserLinks transclusions with project parameters containing language codes]]' )
else
return err('"' .. u.project .. '" is not a valid interwiki prefix')
Line 242 ⟶ 262:
end
local function generateTrackingCategories(
else
▲ ret = ret .. '[[Category:UserLinks transclusions with project parameters]]'
return table.concat(trackingCategories)
end
▲ return ret
end
Line 256 ⟶ 276:
end
local result = getLink(linktype)
result = result .. generateTrackingCategories(
return result
end
Line 272 ⟶ 292:
end
result = '<span>' .. makeUserLink() .. result .. '</span>'
result = result .. generateTrackingCategories(
return result
|