Introducing: Representatives. swedishwin.com, chud.win, and soyzellig.party positions are vacant.


The new Community missions system is now live! Where anyone can propose a task, discuss nominations, or join the current mission. Community missions give editors a place to turn requests from the Janny noticeboard into focused projects. No mission can be too small

Module:News/issue

From Soyjak Wiki, the free ensoyclopedia
Jump to navigationJump to search

Returns one piece of information about a newspaper issue. It is used by Template:News/issue by the issue nameplate and footer.

Usage

{{News/issue|<part>|issue=}}

The issue is the one given with issue=, or, without it, the one whose ID is in the page title.

part returns
id The issue ID, used for the issue's CSS class.
styles Loads the issue's own stylesheet for extra styling. The pattern is determined by issueStylesPattern.
number "No. x" or "No. ?" for a draft
date The issue's date, in the long format from config
price the Boorubux price, from the second argument: a number becomes "X boorubux", none shows nothing (not recommended), other text overrides bux unit and is shown as written. Missing is not accepted.
notice The draft or embargo notice, and its category, if the page is a draft or in embargo
older, newer A link to the "neighboring" listed issue, or nothing
contributors "Last revised <date>" , with the editor when showLastEditor is on. Due to limitations, renders nothing in preview.

Notes

For what makes an issue a draft, embargoed, or listed, see: tbd


local p = {}

local getArgs = require('Module:Arguments').getArgs
local News = require('Module:News')
local cfg = News.cfg

local parts = {}

function parts.number(state, issue)
	return News.numberText(state, issue)
end

function parts.date(state, issue)
	return News.formatDate(News.need('dateFormat'), issue.date)
end

function parts.price(state, issue, today, args)
	return News.bux(state, issue, args[2]) or ''
end

function parts.notice(state, issue, today, args)
	local key, category
	if issue.state == 'draft' then
		key, category = 'draftNotice', 'drafts'
	elseif issue.state == 'embargoed' then
		key, category = 'embargoNotice', 'embargoed'
	else
		return ''
	end
	News.addCategory(state, category)
	local date = News.formatDate(News.need('dateFormat'), issue.rec and issue.rec.embargo)
	local notice = '<div class="sn-news-notice">' .. News.text(state, key, { date = date }) .. '</div>'
	return '<div class="sn-news-notices">'
	.. notice
		.. require('Module:News/status').notice(state, issue, args, today)
		.. '</div>' -- immediately yoink it in
end

local function neighbor(state, issue, today, which)
	local older, newer = News.neighbors(issue, today)
	local other = newer
	if which == 'older' then other = older end
	if not other then return '' end
	return News.link(other.page, News.text(state, which, { number = News.numberText(state, other) }))
end

function parts.older(state, issue, today)
	return neighbor(state, issue, today, 'older')
end

function parts.newer(state, issue, today)
	return neighbor(state, issue, today, 'newer')
end

function parts.contributors(state, issue, today, args)
	if not args[2] then return '' end
	return News.text(state, 'contributors') .. args[2]
end

function parts.revised(state, issue, today, args, frame)
	local date, user = News.lastRevision(frame)
	if not date then return '' end
	date = News.formatDate(News.need('shortDateFormat'), date)
	if cfg.showLastEditor and user then return News.text(state, 'lastRevisedBy', { date = date, user = user }) end
	return News.text(state, 'lastRevised', { date = date })
end

function p.main(frame)
	local args = getArgs(frame, { wrappers = cfg.wrappers })
	local state = News.newState()
	local issue, today, problem = News.resolve(frame, args, state)
	if args[1] == 'id' then
		if issue.state == 'malformed' then return '' end
		return issue.id
	end
	if args[1] == 'styles' then
		if issue.state == 'malformed' then return '' end
		local title = mw.title.new((News.need('issueStylesPattern'):gsub('%$id', issue.id)))
		if not title or not title.exists then return '' end
		return frame:extensionTag('templatestyles', '', { src = title.prefixedText })
	end
	if args[1] == 'state' then return issue.state end
	local part = parts[args[1]]
	if not part then
		return News.finish(state, problem .. News.errorText(state, 'unknownPart', { value = tostring(args[1]) }))
	end
	return News.finish(state, problem .. part(state, issue, today, args, frame))
end

return p