コンテンツにスキップ

モジュール:See/core

半永久的に保護されているモジュール

2019年8月25日 (日) 04:54; ネイ (会話 | 投稿記録) による版 (「モジュール:See/core」を保護しました: 影響が特に大きいテンプレート: 使用数106,000以上 ([編集=管理者のみ許可] (無期限) [移動=管理者のみ許可] (無期限)))(日時は個人設定で未設定ならUTC

(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
モジュールの解説[表示] [編集] [履歴] [キャッシュを破棄]

local p = {}

function p.GetLink(frame)
    local link = frame.args[1]
    local display = frame.args[2]

    -- 第一引数の値が技術的に利用可能な記事名でない場合、
    -- 第一引数の値をそのまま返す
    local IsValidPageName = require('モジュール:IsValidPageName')
    if IsValidPageName.isValidPageName(frame) == "" then
        return link
    end

    if display == "" then
        display = nil
    end

    return p._formatLink(link, display)
end

function p._formatLink(link, display)
    -- Remove the initial colon for links where it was specified manually.
    link = link:match('^:?(.*)')

    -- Find whether a faux display value has been added with the {{!}} magic
    -- word.
    if not display then
        local prePipe, postPipe = link:match('^(.-)|(.*)$')
        link = prePipe or link
        display = postPipe
    end

    -- Assemble the link.
    if display then
        return string.format(
            '[[:%s|%s]]',
            string.gsub(link, '|(.*)$', ''), --display overwrites manual piping
            display
        )
    else
        return string.format('[[:%s]]', link)
    end
end

return p