[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 |
mNo edit summary |
||
Line 5: | Line 5: | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local gFrame | local gFrame | ||
local | local m = {} | ||
local p = {} | local p = {} | ||
---------------------------------------------------------------------------- | ---------------------------------------------------------------------------- | ||
-- | -- 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: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 | if self.released then -- Newly released content | ||
if | if self.part then | ||
if | if self.part == 'section' then | ||
text = string.format('This section describes new Path of Exile content released in [[version %s]].', | 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]].', | 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]].', | 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 | if self.part then | ||
if | if self.part == 'section' then | ||
text = string.format('This section describes Path of Exile content coming in [[version %s]].', | 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]].', | 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]].', | 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 | 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 ' .. | 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 | 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 | 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, | 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 | function m:getImage() | ||
local image | local image | ||
if | 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 | function m:getCategories() | ||
local cat | local cat | ||
if | 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. | 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 | 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: | ||
} | } | ||
) | ) | ||
return m:new(args.version, #version > 0, args.part, args.space, args.talk) | |||
end | end | ||
return p | return p |
Revision as of 06:48, 20 December 2020
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.
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