[dismiss]
The wiki is currently a work in progress. If you'd like to help out, please check the Community Portal and our getting started guide. Also, check out our sister project on poewiki.net.
Module:New content: Difference between revisions
Jump to navigation
Jump to search
>Vinifera7 m (Vinifera7 moved page Module:Sandbox/Vinifera7/New content to Module:New content without leaving a redirect) |
(Use invoker factory from Module:Util. Translation strings moved to Module:New content/config for easier porting. Changed icon for upcoming content.) |
||
Line 1: | Line 1: | ||
------------------------------------------------------------------------------- | |||
local | -- | ||
local | -- 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 m = {} | local m = {} | ||
local | -- 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 = | 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( | text = string.format(i18n.section_new, self.version) | ||
else | else | ||
text = string.format( | text = string.format(i18n.parts_new, self.space, self.part, self.version) | ||
end | end | ||
else | else | ||
text = string.format( | 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( | text = string.format(i18n.section_upcoming, self.version) | ||
else | else | ||
text = string.format( | text = string.format(i18n.parts_upcoming, self.space, self.part, self.version) | ||
end | end | ||
else | else | ||
text = string.format( | text = string.format(i18n.page_upcoming, self.space, self.version) | ||
end | end | ||
end | end | ||
Line 64: | Line 76: | ||
:done() | :done() | ||
:wikitext(' ') | :wikitext(' ') | ||
:wikitext( | :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'}, | local link = string.format('[%s %s %s]', title:fullUrl{action = 'edit'}, i18n.expand_this, self.space) | ||
node | node | ||
:wikitext(string.format( | :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 = | text = i18n.discussion | ||
link = string.format('[%s#%s %s]', url, self.talk, | link = string.format('[%s#%s %s]', url, self.talk, i18n.talk_page) | ||
else | else | ||
text = | text = i18n.relevant_discussion | ||
link = string.format('[%s %s]', url, | 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 = | image = i18n.icons.newly_released_content | ||
else | else | ||
image = | 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 = | cat = m_util.misc.add_category(i18n.categories.newly_released_content) | ||
else | else | ||
cat = | cat = m_util.misc.add_category(i18n.categories.upcoming_content) | ||
end | end | ||
return cat | return cat | ||
end | end | ||
---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
-- | -- Main functions | ||
---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
local function _main(args) | |||
function | |||
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( | 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 | 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"', | 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:25, 12 May 2022
The above documentation is transcluded from Module:New content/doc.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
-------------------------------------------------------------------------------
--
-- 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