[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
mNo edit summary |
m (9 revisions imported) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
------------------------------------------------------------------------------- | |||
local | -- | ||
-- Module:New content | |||
-- | |||
-- This module implements Template:New content. | |||
------------------------------------------------------------------------------- | |||
local m_util = require('Module:Util') | |||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local | 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 | local i18n = cfg.i18n | ||
---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ||
-- | -- Message box pseudo-class | ||
---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ||
function | 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:getEditBlurb()) | |||
:node(self:getTalkBlurb()) | |||
local mbox = mw.getCurrentFrame():expandTemplate{title = i18n.templates.message_box, args = { | |||
type = 'content', | |||
image = self:getImage(), | |||
title = tostring(self:getMainBlurb()), | |||
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 | if self.released then -- Newly released content | ||
if | if self.part then | ||
if | 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 | if self.part then | ||
if | 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 | ||
node | node | ||
: | :wikitext(text) | ||
:wikitext(' ') | |||
:wikitext(i18n.missing_incorrect) | |||
:newline() | :newline() | ||
:newline() | :newline() | ||
return node | return node | ||
end | end | ||
function | function m:getEditBlurb() | ||
local node = mw.html.create() | local node = mw.html.create() | ||
local title = mw.title.getCurrentTitle() | local title = mw.title.getCurrentTitle() | ||
local | local link = mw.html.create('span') | ||
:addClass('plainlinks') | |||
:wikitext(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, tostring(link))) | ||
: | :wikitext(' ') | ||
return node | return node | ||
end | end | ||
function | function m:getTalkBlurb() | ||
local node = mw.html.create() | local node = mw.html.create() | ||
local title = mw.title.getCurrentTitle() | local title = mw.title.getCurrentTitle() | ||
if title.canTalk and title.talkPageTitle.exists then | if title.canTalk and title.talkPageTitle.exists then | ||
local | local text, link | ||
if | 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 | else | ||
text = i18n.relevant_discussion | |||
link = string.format('[%s %s]', url, i18n.talk_page) | |||
end | end | ||
node: | node | ||
:wikitext(string.format(text, link)) | |||
:wikitext(' ') | |||
end | end | ||
return node | return node | ||
end | end | ||
function | function m:getImage() | ||
local image | local image | ||
if | 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 | ||
end | end | ||
function | function m:getCategories() | ||
local cat | local cat | ||
if | 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 | ||
---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
function | local function _main(args) | ||
args = args or {} | args = args or {} | ||
args. | 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.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 135: | Line 148: | ||
'_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', | ||
} | } | ||
) | ) | ||
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 |
Latest revision as of 20:57, 23 September 2024
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 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:getEditBlurb())
:node(self:getTalkBlurb())
local mbox = mw.getCurrentFrame():expandTemplate{title = i18n.templates.message_box, args = {
type = 'content',
image = self:getImage(),
title = tostring(self:getMainBlurb()),
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
:wikitext(text)
:wikitext(' ')
:wikitext(i18n.missing_incorrect)
:newline()
:newline()
return node
end
function m:getEditBlurb()
local node = mw.html.create()
local title = mw.title.getCurrentTitle()
local link = mw.html.create('span')
:addClass('plainlinks')
:wikitext(string.format('[%s %s %s]', title:fullUrl{action = 'edit'}, i18n.expand_this, self.space))
node
:wikitext(string.format(i18n.please_edit, tostring(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