Module:Sandbox/Dragoniez

From Test Wiki
Revision as of 04:12, 29 July 2022 by Dragoniez (talk | contribs) (test)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:Sandbox/Dragoniez/doc

local p = {}
--[=[
local isIpOrRange = require('Module:IPAddress')._isIpOrRange

local function isIp(str)
    return isIpOrRange(str) ~= ''
end
]=]

function p.createUserLink(frame)

    local username = frame.args['username']
    --[=[
    if isIp(username) then
        return '<span style="color: red; font-weight: bold;">エラー: IPユーザーは指定できません<span>'
    end
    ]=]
    local pagetitle
    if username:find('^利用者:') ~= nil then
        pagetitle = username
    elseif username:find('^[Uu][Ss][Ee][Rr]:') ~= nil then
        pagetitle = username:gsub('^[Uu][Ss][Ee][Rr]:', '利用者:')
    else
        pagetitle = '利用者:' .. username
    end

    local clss

    local prefix = frame.args['prefix']
    local displayText
    if prefix == 'none' then
        displayText = pagetitle:gsub('^利用者:', '')
    else
        displayText = pagetitle
    end

    if mw.title.new(pagetitle).exists then
        displayText = '<span class="ul-page-exists">' .. displayText ..'</span>'
    else
        displayText = '<span class="ul-page-missing">' .. displayText ..'</span>'
    end

    local url = '//ja.wikipedia.org/wiki/' .. pagetitle
    local extlink = '[' .. url .. ' ' .. displayText .. ']'
    --local templatestyles = frame:extensionTag{name = 'templatestyles', args = {src = 'Template:UserLink/styles.css'}}
    local templatestyles = frame:extensionTag{name = 'templatestyles', args = {src = 'User:Dragoniez/Template:UserLink/styles.css'}}
    local link = templatestyles .. '<span class="plainlinks ' .. clss .. '">' .. extlink .. '</span>'

    return link

end

function p.Main(frame)
    return p.createUserLink(frame)
end

return p