Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:Link: Difference between revisions

From Teriock
Content deleted Content added
// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 68: Line 68:
local page = ''
local page = ''
local text = ''
local text = ''
local uc = false
local lc = true
local lc = false
local textPre = ''
local textPre = ''
local textPost = ''
local textPost = ''
Line 98: Line 97:
end
end
if contains(upperCaseNS, ns) or contains(upperCaseText, text) then
if contains(upperCaseNS, ns) or contains(upperCaseText, text) then
uc = true
lc = false
lc = false
end
end
if args['uc'] then
if args['uc'] then
uc = true
lc = false
lc = false
end
end
if args['lc'] then
if args['lc'] then
uc = false
lc = true
lc = true
end
end
text = textPre .. text .. textPost
text = textPre .. text .. textPost
if lc then
if lc then
text = string.lower(text)
text = frame:preprocess( string.lower(text) )
end
end
if ns == '' then
if ns == '' then

Revision as of 00:22, 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 contains(tbl, value)
    for _, v in ipairs(tbl) do
        if v == value then
            return true
        end
    end
    return false
end

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 lc = true
    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 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 contains(upperCaseNS, ns) or contains(upperCaseText, text) then
        lc = false
    end
    if args['uc'] then
        lc = false
    end
    if args['lc'] then
        lc = true
    end
    text = textPre .. text .. textPost
    if lc then
        text = frame:preprocess( string.lower(text) )
    end
    if ns == '' then
        return frame:preprocess( '[[' .. page .. '|' .. text .. ']]' )
    else
        return frame:preprocess( '[[:' .. ns .. ':' .. page .. '|' .. text .. ']]' )
    end
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