克鲁赛德战记 Wiki
注册
Advertisement

此模块的文档可以在Module:Base/doc创建

local p = {}

function p.hidden(frames)
    local text = frames.args[1] or ''
    return '<span class="hidden">'..text..'</span>'
end

function p.nodisplay(frames)
    local text = frames.args[1] or ''
    return '<span class="nodisplay">'..text..'</span>'
end

-- 生成comment的 [编辑]
function comment_edit(name)
    url = tostring(mw.uri.fullUrl(name))
    return '<span class="hidden" style="font-size: 13px;"> ['..url..'?action=edit <编辑>]</span>'
end

-- 读取comment
function p.load_comment(name)
    comment_name = string.format("Comment.%s", name)
    if mw.title.new( comment_name, 'Module' ).exists then
        comment_name = string.format("Module:%s", comment_name)
        comment = mw.loadData(comment_name)
        return comment_name, comment
    else
        comment_name = string.format("Module:%s", comment_name)
        return comment_name,''
    end
end

-- 返回comment内的具体内容
function p.get_comment(comment, item, edit, comment_name)
    edit = edit or false
    comment_name = comment_name or ''
    
    local text = ''
    local blank = false
    if comment == '' then
        text = '暂无'
        blank = true
    elseif comment[item] == '' then
        text = '暂无'
        blank = true
    elseif not comment[item] then
        text = '暂无'
        blank = true
    else
        text = comment[item]
    end
    
    if edit then
        text = text..comment_edit(comment_name)
    end
    
    return text, blank
end

-- 分类
function p.cate(name, sorttext)
    sorttext = sorttext or nil
    if name ~= nil then
        if sorttext ~= nil then
            return '[[Category:' .. name .. '|'..sorttext..']]'
        else
            return '[[Category:' .. name .. ']]'
        end
    else
        return ''
    end
end

-- 根据中文文本获取本地化文本
function p.get_local_text(text, lang)
    local local_text_list = mw.loadData('Module:Local_text.data')
   
    if local_text_list[text][lang] then
        return local_text_list[text][lang]
    else
        return '[ '..text..' 不存在]'
    end
end

return p
Advertisement