Module:UserLinks: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
Content added Content deleted
(add support for different projects in the edit count link)
(add support for different projects in the edit summary link, reduce some long lines of code)
Line 30: Line 30:
-- u.projectCode If a valid project is specified, this is the code for that --
-- u.projectCode If a valid project is specified, this is the code for that --
-- project in [[Module:InterwikiTable]]. Otherwise this is nil. --
-- project in [[Module:InterwikiTable]]. Otherwise this is nil. --
-- u.projectLong The long project name, e.g. "wikipedia" or "wikibooks". If --
-- not specified the default is "wikipedia". --
-- u.toolLang The language code for use with toolserver or labs tools. The --
-- default is "en". --
-- --
-- --
-- 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 48: Line 52:


local function makeCountLink()
local function makeCountLink()
return '[//tools.wmflabs.org/xtools/pcount/index.php?name=' .. u.usernameHtml
local lang = u.lang or 'en'
.. '&lang=' .. u.toolLang
local project
.. '&wiki=' .. u.projectLong
if u.project then
.. ' count]'
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 93: Line 92:


local function makeEditSummariesLink()
local function makeEditSummariesLink()
return '[http://toolserver.org/~tparis/editsummary/index.php?name=' .. u.usernameHtml .. '&lang=en&wiki=wikipedia edit summaries]'
return '[http://toolserver.org/~tparis/editsummary/index.php?name=' .. u.usernameHtml
.. '&lang=' .. u.toolLang
.. '&wiki=' .. u.projectLong
.. ' edit summaries]'
end
end


Line 242: Line 244:
u.lang = pref2
u.lang = pref2
u.projectCode = pref1ProjectCode
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
and mw.language.isKnownLanguageTag(pref1)
and mw.language.isKnownLanguageTag(pref1)
Line 249: Line 254:
u.lang = pref1
u.lang = pref1
u.projectCode = pref2ProjectCode
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
return err('"' .. u.project .. '" is not a valid interwiki prefix')
return err('"' .. u.project .. '" is not a valid interwiki prefix')
Line 276: Line 284:
-- Generate the other helper strings.
-- Generate the other helper strings.
u.usernameHtml = mw.uri.encode(u.username) -- Html-encoded username. Spaces are encoded as pluses.
u.usernameHtml = mw.uri.encode(u.username) -- Html-encoded username. Spaces are encoded as pluses.
if u.project then
local prefixes = interwikiTable[u.projectCode].iw_prefix
u.projectLong = prefixes[2] or prefixes[1] -- A bit of a hack, but should find the long prefix name most of the time.
else
u.projectLong = 'wikipedia'
end
u.toolLang = u.lang or 'en' -- set the default language for tools on the toolserver or labs.
end
end