Module:Link: Difference between revisions
From Teriock
More actions
// via Wikitext Extension for VSCode |
// via Wikitext Extension for VSCode |
||
| Line 12: | Line 12: | ||
'Ability', | 'Ability', | ||
} | } | ||
local upperCaseNS = { | |||
'Ability', | |||
'Class', | |||
} | |||
local upperCaseText = { | |||
'Ethereal', | |||
'Ethereal Realm', | |||
} | |||
function findNamespace ( title ) | |||
for _, namespace in ipairs(namespaces) do | |||
local fullTitle = namespace == '' and title or (namespace .. ':' .. title) | |||
local page = mw.title.new(fullTitle) | |||
if page and page.exists then | |||
return namespace | |||
end | |||
end | |||
return '' | |||
end | |||
function p.l ( frame ) | function p.l ( frame ) | ||
| Line 28: | Line 49: | ||
end | end | ||
return title | return title | ||
end | |||
function p.m ( frame ) | |||
local args = frame.args | |||
local a1 = args[1] | |||
local a2 = args[2] | |||
local a3 = args[3] | |||
local ns = '' | |||
local page = '' | |||
local text = '' | |||
local uc = false | |||
local lc = false | |||
local textPre = '' | |||
local textPost = '' | |||
if args['pre'] then | |||
textPre = args['pre'] | |||
end | |||
if args['post'] then | |||
textPost = args['post'] | |||
end | |||
if a3 then | |||
ns = a1 | |||
page = a2 | |||
text = a3 | |||
elseif a2 then | |||
if table.contains(namespaces, a1) then | |||
ns = a1 | |||
page = a2 | |||
text = a2 | |||
else | |||
ns = findNamespace(a1) | |||
page = a1 | |||
text = a2 | |||
end | |||
else | |||
ns = findNamespace(a1) | |||
page = a1 | |||
text = a1 | |||
end | |||
if table.contains(upperCaseNS, ns) or table.contains(upperCaseText, text) then | |||
uc = true | |||
lc = false | |||
end | |||
if args['uc'] then | |||
uc = true | |||
lc = false | |||
end | |||
if args['lc'] then | |||
uc = false | |||
lc = true | |||
end | |||
text = pre .. text .. post | |||
if lc then | |||
text = mw.ustring.lower(text) | |||
end | |||
return '[[:' .. ns .. ':' .. page .. '|' .. text .. ']]' | |||
end | end | ||
Revision as of 00:05, 31 January 2025
Documentation for this module may be created at Module:Link/doc
local p = {}
local namespaces = {
'',
'Core',
'Keyword',
'Category',
'Condition',
'Damage',
'Drain',
'Property',
'Ability',
}
local upperCaseNS = {
'Ability',
'Class',
}
local upperCaseText = {
'Ethereal',
'Ethereal Realm',
}
function findNamespace ( title )
for _, namespace in ipairs(namespaces) do
local fullTitle = namespace == '' and title or (namespace .. ':' .. title)
local page = mw.title.new(fullTitle)
if page and page.exists then
return namespace
end
end
return ''
end
function p.l ( frame )
local args = frame.args
local title = args[1]
for _, namespace in ipairs(namespaces) do
local fullTitle = namespace == '' and title or (namespace .. ':' .. title)
local page = mw.title.new(fullTitle)
if page and page.exists then
if namespace == 'Category' then
return ' :' .. fullTitle
else
return fullTitle
end
end
end
return title
end
function p.m ( frame )
local args = frame.args
local a1 = args[1]
local a2 = args[2]
local a3 = args[3]
local ns = ''
local page = ''
local text = ''
local uc = false
local lc = false
local textPre = ''
local textPost = ''
if args['pre'] then
textPre = args['pre']
end
if args['post'] then
textPost = args['post']
end
if a3 then
ns = a1
page = a2
text = a3
elseif a2 then
if table.contains(namespaces, a1) then
ns = a1
page = a2
text = a2
else
ns = findNamespace(a1)
page = a1
text = a2
end
else
ns = findNamespace(a1)
page = a1
text = a1
end
if table.contains(upperCaseNS, ns) or table.contains(upperCaseText, text) then
uc = true
lc = false
end
if args['uc'] then
uc = true
lc = false
end
if args['lc'] then
uc = false
lc = true
end
text = pre .. text .. post
if lc then
text = mw.ustring.lower(text)
end
return '[[:' .. ns .. ':' .. page .. '|' .. text .. ']]'
end
function p.n ( frame )
local args = frame.args
local ns = args[1]
for _, namespace in ipairs(namespaces) do
if ns == namespace then
return 'true'
end
end
return ''
end
return p