Path of Exile Wiki

Wiki поддерживается сообществом, поэтому подумайте над тем, чтобы внести свой вклад.

ПОДРОБНЕЕ

Path of Exile Wiki
Advertisement
Версия для печати больше не поддерживается и может содержать ошибки обработки. Обновите закладки браузера и используйте вместо этого функцию печати браузера по умолчанию.
Template info icon Документация модуля[просмотр] [править] [история] [очистить]

Реализует {{New content}}.

local getArgs = require('Module:Arguments').getArgs
local util = require('Module:Util')
local messageBox = require('Module:Message box')

local cargo = mw.ext.cargo
local gFrame
local m = {}

local p = {}

----------------------------------------------------------------------------
-- Message box pseudo-class
----------------------------------------------------------------------------

function m:new(version, released, part, space, talk)
    self.version = version
    self.released = released or false
    self.part = part
    self.space = space
    self.talk = talk
    local text = mw.html.create()
        :node(self:getMainBlurb())
        :node(self:getEditBlurb())
        :node(self:getTalkBlurb())
    local mbox = messageBox.main('mbox', {
        type = 'content',
        image = self:getImage(),
        text = tostring(text),
    })
    local cats = self:getCategories()
    local html = mw.html.create()
        :wikitext(mbox)
        :wikitext(cats)
    return tostring(html)
end

function m:getMainBlurb()
    local node = mw.html.create()
    local text
    if self.released then -- Newly released content
        if self.part then
            if self.part == 'section' then
                text = string.format('В этом разделе описывается новое обновление Path of Exile, выпущенное в [[версия %s]].', self.version)
            else
                text = string.format('Части этой статьи, связанные с %s, описывают новое обновление Path of Exile, выпущенное в [[версия %s]].', self.part, self.version)
            end
        else
            text = string.format('В этой статье описывается новое обновление Path of Exile, выпущенное в [[версия %s]].', self.version)
        end
    else -- Upcoming content
        if self.part then
            if self.part == 'section' then
                text = string.format('В этом разделе описывается новое обновление Path of Exile, предстоящее в [[версия %s]].', self.version)
            else
                text = string.format('Части этой статьи, связанные с %s, описывают новое обновление Path of Exile, предстоящее в [[версия %s]].', self.part, self.version)
            end
        else
            text = string.format('В этой статье описывается новое обновление Path of Exile, предстоящее в [[версия %s]].', self.version)
        end
    end
    node
        :tag('b')
            :node(text)
            :done()
        :wikitext(' ')
        :wikitext('Информация может отсутствовать или быть неверной.')
        :tag('br')
            :done()
        :newline()
    return node
end

function m:getEditBlurb()
    local node = mw.html.create()
    local title = mw.title.getCurrentTitle()
    local link = string.format('[%s %s]', title:fullUrl{action = 'edit'}, 'расширьте эту статью')
    node
        :wikitext(string.format('Пожалуйста, %s, чтобы она содержала полную и точную информацию.', link))
        :wikitext(' ')
    return node
end

function m:getTalkBlurb()
    local node = mw.html.create()
    local title = mw.title.getCurrentTitle()
    if title.canTalk and title.talkPageTitle.exists then
        local text, link
        local url = title.talkPageTitle:fullUrl()
        if self.talk then
            text = 'Это более подробно обсуждается на %s.'
            link = string.format('[%s#%s %s]', url, self.talk, 'странице обсуждения')
        else
            text = 'Соответствующее обсуждение можно найти на %s.'
            link = string.format('[%s %s]', url, 'странице обсуждения')
        end
        node
            :wikitext(string.format(text, link))
            :wikitext(' ')
    end
    return node
end

function m:getImage()
    local image
    if self.released then
        image = '[[File:Albino Rhoa Feather inventory icon.png|48px|alt=|link=]]'
    else
        image = '[[File:Divination card inventory icon.png|48px|alt=|link=]]'
    end
    return image
end

function m:getCategories()
    local cat
    if self.released then
        cat = util.misc.add_category('Недавно выпущенное обновление')
    else
        cat = util.misc.add_category('Предстоящее обновление')
    end
    return cat
end

----------------------------------------------------------------------------
-- main() - Implements Template:New content
----------------------------------------------------------------------------

function p.main(frame)
    local args = getArgs(frame, {
        parentFirst = true
    })
    gFrame = frame
    return p._main(args)
end

function p._main(args)
    local frame = util.misc.get_frame(gFrame)
    args = args or {}
    args.version = args.version or args[1]
    if type(args.version) ~= 'string' then -- Version is required
        error(string.format('Аргумент "%s" является обязательным', 'version'))
    end
    args.part = args.part or args[2]
    args.space = args.space or frame:expandTemplate{title = 'SUBJECTSPACE formatted'}
    local now = os.date('!%F %T') -- Current UTC timestamp in Y-m-d H:i:s format
    local version = cargo.query( -- Query specified version with release date before current date
        'versions', 
        '_pageName',
        {
            where = string.format('version = "%s" AND release_date < "%s"', util.cast.version(args.version, {return_type = 'string'}), now),
            limit = 1,
            groupBy = '_pageID',
        }
    )
    return m:new(args.version, #version > 0, args.part, args.space, args.talk)
end

return p
Advertisement