Module:UserLinks: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(bug fix in error function)
(add support for different projects in the edit count link)
Line 28: Line 28:
-- values, separated by colons, e.g. ":wikt:es:". If no project --
-- values, separated by colons, e.g. ":wikt:es:". If no project --
-- or language values are found, this is the blank string, "". --
-- or language values are found, this is the blank string, "". --
-- u.projectCode If a valid project is specified, this is the code for that --
-- project in [[Module:InterwikiTable]]. Otherwise this is nil. --
-- --
-- --
-- If you want more strings, you can define them in the generateUserDataStrings --
-- If you want more strings, you can define them in the generateUserDataStrings --
Line 46: Line 48:


local function makeCountLink()
local function makeCountLink()
local lang = u.lang or 'en'
return '[//tools.wmflabs.org/xtools/pcount/index.php?name=' .. u.usernameHtml .. '&lang=en&wiki=wikipedia count]'
local project
if u.project then
local prefixes = interwikiTable[u.projectCode].iw_prefix
project = prefixes[2] or prefixes[1] -- A bit of a hack, but should find the long prefix name most of the time.
else
project = 'wikipedia'
end
return '[//tools.wmflabs.org/xtools/pcount/index.php?name=' .. u.usernameHtml .. '&lang=' .. lang .. '&wiki=' .. project .. ' count]'
end
end


Line 211: Line 221:
table.insert( trackingCategories, '[[Category:UserLinks transclusions with project parameters]]' )
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
-- If u.project is a known project, we only need to get the project code. If the project
-- check whether it is a valid language code, and if not then see if it's an interwiki code
-- isn't known, first check whether it is a valid language code, and if not then see if it's
-- separated by colons, e.g. "wikt:es".
-- an interwiki code separated by colons, e.g. "wikt:es".
if not isKnownProject(u.project) then
local uprojectIsKnownProject, uprojectProjectCode = isKnownProject(u.project)
if uprojectIsKnownProject then
u.projectCode = uprojectProjectCode
else
if mw.language.isKnownLanguageTag(u.project) then
if mw.language.isKnownLanguageTag(u.project) then
u.lang = u.project
u.lang = u.project
Line 228: Line 241:
u.project = pref1
u.project = pref1
u.lang = pref2
u.lang = pref2
u.projectCode = pref1ProjectCode
table.insert( trackingCategories, '[[Category:UserLinks transclusions with project parameters containing language codes]]' )
table.insert( trackingCategories, '[[Category:UserLinks transclusions with project parameters containing language codes]]' )
elseif pref2IsKnownProject
elseif pref2IsKnownProject
Line 234: Line 248:
u.project = pref2
u.project = pref2
u.lang = pref1
u.lang = pref1
u.projectCode = pref2ProjectCode
table.insert( trackingCategories, '[[Category:UserLinks transclusions with project parameters containing language codes]]' )
table.insert( trackingCategories, '[[Category:UserLinks transclusions with project parameters containing language codes]]' )
else
else