Module:New content: Difference between revisions

From Path of Exile 2 Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 5: Line 5:
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo
local gFrame
local gFrame
local h = {}
local m = {}


local p = {}
local p = {}


----------------------------------------------------------------------------
----------------------------------------------------------------------------
-- Helper functions
-- Message box pseudo-class
----------------------------------------------------------------------------
----------------------------------------------------------------------------


function h.mainBlurb()
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 node = mw.html.create()
     local text
     local text
     if h.args.released then -- Newly released content
     if self.released then -- Newly released content
         if h.args.part then
         if self.part then
             if h.args.part == 'section' then
             if self.part == 'section' then
                 text = string.format('This section describes new Path of Exile content released in [[version %s]].', h.args.version)
                 text = string.format('This section describes new Path of Exile content released in [[version %s]].', self.version)
             else
             else
                 text = string.format('Parts of this %s related to %s describe new Path of Exile content released in [[version %s]].', h.args.space, h.args.part, h.args.version)
                 text = string.format('Parts of this %s related to %s describe new Path of Exile content released in [[version %s]].', self.space, self.part, self.version)
             end
             end
         else
         else
             text = string.format('This %s describes new Path of Exile content released in [[version %s]].', h.args.space, h.args.version)
             text = string.format('This %s describes new Path of Exile content released in [[version %s]].', self.space, self.version)
         end
         end
     else -- Upcoming content
     else -- Upcoming content
         if h.args.part then
         if self.part then
             if h.args.part == 'section' then
             if self.part == 'section' then
                 text = string.format('This section describes Path of Exile content coming in [[version %s]].', h.args.version)
                 text = string.format('This section describes new Path of Exile content coming in [[version %s]].', self.version)
             else
             else
                 text = string.format('Parts of this %s related to %s describe Path of Exile content coming in [[version %s]].', h.args.space, h.args.part, h.args.version)
                 text = string.format('Parts of this %s related to %s describe new Path of Exile content coming in [[version %s]].', self.space, self.part, self.version)
             end
             end
         else
         else
             text = string.format('This %s describes Path of Exile content coming in [[version %s]].', h.args.space, h.args.version)
             text = string.format('This %s describes new Path of Exile content coming in [[version %s]].', self.space, self.version)
         end
         end
     end
     end
Line 49: Line 71:
end
end


function h.editBlurb()
function m:getEditBlurb()
     local node = mw.html.create()
     local node = mw.html.create()
     local title = mw.title.getCurrentTitle()
     local title = mw.title.getCurrentTitle()
     local link = string.format('[%s %s]', title:fullUrl{action = 'edit'}, 'expand this ' .. h.args.space)
     local link = string.format('[%s %s]', title:fullUrl{action = 'edit'}, 'expand this ' .. self.space)
     node
     node
         :wikitext(string.format('Please %s so that it provides complete and accurate information.', link))
         :wikitext(string.format('Please %s so that it provides complete and accurate information.', link))
Line 59: Line 81:
end
end


function h.talkBlurb()
function m:getTalkBlurb()
     local node = mw.html.create()
     local node = mw.html.create()
     local title = mw.title.getCurrentTitle()
     local title = mw.title.getCurrentTitle()
Line 65: Line 87:
         local text, link
         local text, link
         local url = title.talkPageTitle:fullUrl()
         local url = title.talkPageTitle:fullUrl()
         if h.args.talk then
         if self.talk then
             text = 'This is discussed in greater detail on the %s.'
             text = 'This is discussed in greater detail on the %s.'
             link = string.format('[%s#%s %s]', url, h.args.talk, 'talk page')
             link = string.format('[%s#%s %s]', url, self.talk, 'talk page')
         else
         else
             text = 'Relevant discussion may be found on the %s.'
             text = 'Relevant discussion may be found on the %s.'
Line 79: Line 101:
end
end


function h.image()
function m:getImage()
     local image
     local image
     if h.args.released then
     if self.released then
         image = '[[File:Albino Rhoa Feather inventory icon.png|48px|alt=|link=]]'
         image = '[[File:Albino Rhoa Feather inventory icon.png|48px|alt=|link=]]'
     else
     else
Line 89: Line 111:
end
end


function h.messageBox()
function m:getCategories()
    local text = mw.html.create()
    text
        :node(h.mainBlurb())
        :node(h.editBlurb())
        :node(h.talkBlurb())
    return messageBox.main('mbox', {
        type = 'content',
        image = h.image(),
        text = tostring(text),
    })
end
 
function h.categories()
     local cat
     local cat
     if h.args.released then
     if self.released then
         cat = util.misc.add_category('Newly released content')
         cat = util.misc.add_category('Newly released content')
     else
     else
Line 127: Line 136:
     local frame = util.misc.get_frame(gFrame)
     local frame = util.misc.get_frame(gFrame)
     args = args or {}
     args = args or {}
     args.part = args[1]
     args.version = args.version or args[1]
    args.type = args.type or frame:expandTemplate{title = 'SUBJECTSPACE formatted'}
    args.space = args.space or args.type
    args.talksection = args.talksection or args.discuss
    args.talk = args.talk or args.talksection
     if type(args.version) ~= 'string' then -- Version is required
     if type(args.version) ~= 'string' then -- Version is required
         error(string.format('Argument "%s" is required.', 'version'))
         error(string.format('Argument "%s" is required', 'version'))
     end
     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 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
     local version = cargo.query( -- Query specified version with release date before current date
Line 145: Line 152:
         }
         }
     )
     )
     if #version > 0 then -- Version has already been released
     return m:new(args.version, #version > 0, args.part, args.space, args.talk)
        args.released = true
    else -- Version does not exist or has not been released yet
        args.released = false
    end
    h.args = args
    local html = mw.html.create()
        :wikitext(h.messageBox())
        :wikitext(h.categories())
    return tostring(html)
end
end


return p
return p

Revision as of 06:48, 20 December 2020

Module documentation[view] [edit] [history] [purge]


Lua logo

This module depends on the following other modules:

Implements {{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('This section describes new Path of Exile content released in [[version %s]].', self.version)
            else
                text = string.format('Parts of this %s related to %s describe new Path of Exile content released in [[version %s]].', self.space, self.part, self.version)
            end
        else
            text = string.format('This %s describes new Path of Exile content released in [[version %s]].', self.space, self.version)
        end
    else -- Upcoming content
        if self.part then
            if self.part == 'section' then
                text = string.format('This section describes new Path of Exile content coming in [[version %s]].', self.version)
            else
                text = string.format('Parts of this %s related to %s describe new Path of Exile content coming in [[version %s]].', self.space, self.part, self.version)
            end
        else
            text = string.format('This %s describes new Path of Exile content coming in [[version %s]].', self.space, self.version)
        end
    end
    node
        :tag('b')
            :node(text)
            :done()
        :wikitext(' ')
        :wikitext('Information may be missing or incorrect.')
        :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'}, 'expand this ' .. self.space)
    node
        :wikitext(string.format('Please %s so that it provides complete and accurate information.', 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 = 'This is discussed in greater detail on the %s.'
            link = string.format('[%s#%s %s]', url, self.talk, 'talk page')
        else
            text = 'Relevant discussion may be found on the %s.'
            link = string.format('[%s %s]', url, 'talk page')
        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('Newly released content')
    else
        cat = util.misc.add_category('Upcoming content')
    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('Argument "%s" is required', '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