Module:New content/sandbox: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
local getArgs = require('Module:Arguments').getArgs
-------------------------------------------------------------------------------
local util = require('Module:Util')
--
local messageBox = require('Module:Message box')
--                            Module:New content
--
-- This module implements Template:New content.
-------------------------------------------------------------------------------
 
local m_util = require('Module:Util')
local m_message_box = require('Module:Message box')


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


local p = {}
-- Should we use the sandbox version of our submodules?
local use_sandbox = m_util.misc.maybe_sandbox('New content')
 
-- The cfg table contains all localisable strings and configuration, to make it
-- easier to port this module to another wiki.
local cfg = use_sandbox and mw.loadData('Module:New content/config/sandbox') or mw.loadData('Module:New content/config')
 
local i18n = cfg.i18n


----------------------------------------------------------------------------
----------------------------------------------------------------------------
Line 23: Line 35:
         :node(self:getEditBlurb())
         :node(self:getEditBlurb())
         :node(self:getTalkBlurb())
         :node(self:getTalkBlurb())
     local mbox = messageBox.main('mbox', {
     local mbox = m_message_box.main('mbox', {
         type = 'content',
         type = 'content',
         image = self:getImage(),
         image = self:getImage(),
Line 41: Line 53:
         if self.part then
         if self.part then
             if self.part == 'section' then
             if self.part == 'section' then
                 text = string.format('This section describes new Path of Exile content released in [[version %s]].', self.version)
                 text = string.format(i18n.section_new, self.version)
             else
             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)
                 text = string.format(i18n.parts_new, 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]].', self.space, self.version)
             text = string.format(i18n.page_new, self.space, self.version)
         end
         end
     else -- Upcoming content
     else -- Upcoming content
         if self.part then
         if self.part then
             if self.part == 'section' then
             if self.part == 'section' then
                 text = string.format('This section describes new Path of Exile content coming in [[version %s]].', self.version)
                 text = string.format(i18n.section_upcoming, self.version)
             else
             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)
                 text = string.format(i18n.parts_upcoming, self.space, self.part, self.version)
             end
             end
         else
         else
             text = string.format('This %s describes new Path of Exile content coming in [[version %s]].', self.space, self.version)
             text = string.format(i18n.page_upcoming, self.space, self.version)
         end
         end
     end
     end
Line 64: Line 76:
             :done()
             :done()
         :wikitext(' ')
         :wikitext(' ')
         :wikitext('Information may be missing or incorrect.')
         :wikitext(i18n.missing_incorrect)
         :tag('br')
         :tag('br')
             :done()
             :done()
Line 74: Line 86:
     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 ' .. self.space)
     local link = string.format('[%s %s %s]', title:fullUrl{action = 'edit'}, i18n.expand_this, self.space)
     node
     node
         :wikitext(string.format('Please %s so that it provides complete and accurate information.', link))
         :wikitext(string.format(i18n.please_edit, link))
         :wikitext(' ')
         :wikitext(' ')
     return node
     return node
Line 88: Line 100:
         local url = title.talkPageTitle:fullUrl()
         local url = title.talkPageTitle:fullUrl()
         if self.talk then
         if self.talk then
             text = 'This is discussed in greater detail on the %s.'
             text = i18n.discussion
             link = string.format('[%s#%s %s]', url, self.talk, 'talk page')
             link = string.format('[%s#%s %s]', url, self.talk, i18n.talk_page)
         else
         else
             text = 'Relevant discussion may be found on the %s.'
             text = i18n.relevant_discussion
             link = string.format('[%s %s]', url, 'talk page')
             link = string.format('[%s %s]', url, i18n.talk_page)
         end
         end
         node
         node
Line 104: Line 116:
     local image
     local image
     if self.released then
     if self.released then
         image = '[[File:Albino Rhoa Feather inventory icon.png|48px|alt=|link=]]'
         image = i18n.icons.newly_released_content
     else
     else
         image = '[[File:Eggu.png|48px|alt=|link=]]'
         image = i18n.icons.upcoming_content
     end
     end
     return image
     return image
Line 114: Line 126:
     local cat
     local cat
     if self.released then
     if self.released then
         cat = util.misc.add_category('Newly released content')
         cat = m_util.misc.add_category(i18n.categories.newly_released_content)
     else
     else
         cat = util.misc.add_category('Upcoming content')
         cat = m_util.misc.add_category(i18n.categories.upcoming_content)
     end
     end
     return cat
     return cat
end
end


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


function p.main(frame)
local function _main(args)
    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 = args or {}
     args.version = args.version or args[1]
     args.version = args.version or args[1]
     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(i18n.errors.version_undefined)
     end
     end
     args.part = args.part or args[2]
     args.part = args.part or args[2]
     args.space = args.space or frame:expandTemplate{title = 'SUBJECTSPACE formatted'}
     args.space = args.space or mw.getCurrentFrame():expandTemplate{title = i18n.templates.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 147: Line 150:
         '_pageName',
         '_pageName',
         {
         {
             where = string.format('version = "%s" AND release_date < "%s"', util.cast.version(args.version, {return_type = 'string'}), now),
             where = string.format('version = "%s" AND release_date < "%s"', m_util.cast.version(args.version, {return_type = 'string'}), now),
             limit = 1,
             limit = 1,
             groupBy = '_pageID',
             groupBy = '_pageID',
Line 154: Line 157:
     return m:new(args.version, #version > 0, args.part, args.space, args.talk)
     return m:new(args.version, #version > 0, args.part, args.space, args.talk)
end
end
-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------
local p = {}
--
-- Template:New content
--
p.main = m_util.misc.invoker_factory(_main, {
    wrappers = cfg.wrapper,
})


return p
return p

Revision as of 21:14, 12 May 2022

This is the module sandbox page for Module:New content (diff).

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


Lua logo

This module depends on the following other modules:

Implements {{New content}}.


-------------------------------------------------------------------------------
-- 
--                             Module:New content
-- 
-- This module implements Template:New content.
-------------------------------------------------------------------------------

local m_util = require('Module:Util')
local m_message_box = require('Module:Message box')

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

-- Should we use the sandbox version of our submodules?
local use_sandbox = m_util.misc.maybe_sandbox('New content')

-- The cfg table contains all localisable strings and configuration, to make it
-- easier to port this module to another wiki.
local cfg = use_sandbox and mw.loadData('Module:New content/config/sandbox') or mw.loadData('Module:New content/config')

local i18n = cfg.i18n

----------------------------------------------------------------------------
-- 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 = m_message_box.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(i18n.section_new, self.version)
            else
                text = string.format(i18n.parts_new, self.space, self.part, self.version)
            end
        else
            text = string.format(i18n.page_new, self.space, self.version)
        end
    else -- Upcoming content
        if self.part then
            if self.part == 'section' then
                text = string.format(i18n.section_upcoming, self.version)
            else
                text = string.format(i18n.parts_upcoming, self.space, self.part, self.version)
            end
        else
            text = string.format(i18n.page_upcoming, self.space, self.version)
        end
    end
    node
        :tag('b')
            :node(text)
            :done()
        :wikitext(' ')
        :wikitext(i18n.missing_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 %s]', title:fullUrl{action = 'edit'}, i18n.expand_this, self.space)
    node
        :wikitext(string.format(i18n.please_edit, 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 = i18n.discussion
            link = string.format('[%s#%s %s]', url, self.talk, i18n.talk_page)
        else
            text = i18n.relevant_discussion
            link = string.format('[%s %s]', url, i18n.talk_page)
        end
        node
            :wikitext(string.format(text, link))
            :wikitext(' ')
    end
    return node
end

function m:getImage()
    local image
    if self.released then
        image = i18n.icons.newly_released_content
    else
        image = i18n.icons.upcoming_content
    end
    return image
end

function m:getCategories()
    local cat
    if self.released then
        cat = m_util.misc.add_category(i18n.categories.newly_released_content)
    else
        cat = m_util.misc.add_category(i18n.categories.upcoming_content)
    end
    return cat
end

-- ----------------------------------------------------------------------------
-- Main functions
-- ----------------------------------------------------------------------------

local function _main(args)
    args = args or {}
    args.version = args.version or args[1]
    if type(args.version) ~= 'string' then -- Version is required
        error(i18n.errors.version_undefined)
    end
    args.part = args.part or args[2]
    args.space = args.space or mw.getCurrentFrame():expandTemplate{title = i18n.templates.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"', m_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

-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------

local p = {}

-- 
-- Template:New content
-- 
p.main = m_util.misc.invoker_factory(_main, {
    wrappers = cfg.wrapper,
})

return p