Jump to content

Module:Rewrite: Difference between revisions

From the Vrienden Universe, a fictional wiki
Create rewrite-marking maintenance system
 
Fix rewrite marker substitution and standalone banner styles
Line 68: Line 68:
end
end


local output = frame:expandTemplate {
local border_color = overdue and '#b32424' or '#d99b00'
title = 'Mbox',
local background_color = overdue and '#fee7e6' or '#fff6cc'
args = {
local output = '<div class="vu-rewrite-box" role="note" style="box-sizing: border-box; margin: 0 0 1em; padding: 0.8em 1em; border: 1px solid '
name = 'Rewrite',
.. border_color
type = overdue and 'delete' or 'content',
.. '; border-left: 6px solid '
text = text
.. border_color
}
.. '; background: '
}
.. background_color
.. '; color: #202122;">'
.. text
.. '</div>'


if mw.title.getCurrentTitle().namespace == 0 then
if mw.title.getCurrentTitle().namespace == 0 then

Revision as of 19:23, 11 September 2026

Documentation for this module may be created at Module:Rewrite/doc

local p = {}

local function trim(value)
	if value == nil then
		return nil
	end
	value = mw.text.trim(value)
	if value == '' then
		return nil
	end
	return value
end

local function format_marked_date(language, value)
	local success, result = pcall(language.formatDate, language, 'j F Y', value)
	if success then
		return result
	end
	return value
end

local function is_older_than_one_week(language, value)
	local marked_success, marked = pcall(language.formatDate, language, 'U', value)
	if not marked_success then
		return false
	end

	local current = tonumber(language:formatDate('U'))
	marked = tonumber(marked)
	return current ~= nil and marked ~= nil and current - marked > 7 * 24 * 60 * 60
end

function p.main(frame)
	local args = frame:getParent().args
	local language = mw.getContentLanguage()
	local reason = trim(args.reason)

	if mw.isSubsting() then
		local invocation_args = {
			date = language:formatDate('Y-m-d')
		}
		if reason then
			invocation_args.reason = reason
		end
		return require('Module:Template invocation').invocation('Rewrite', invocation_args)
	end

	local marked_date = trim(args.date)
	local overdue = marked_date and is_older_than_one_week(language, marked_date)
	local text

	if overdue then
		text = "'''This page has been marked for rewrite for more than one week.''' It was marked on "
			.. format_marked_date(language, marked_date)
			.. ". It may be out of date or no longer follow current wiki standards."
	else
		text = "'''This page is marked for rewrite.''' It may be out of date or no longer follow current wiki standards."
		if marked_date then
			text = text .. ' It was marked on ' .. format_marked_date(language, marked_date) .. '.'
		else
			text = text .. ' The marking date was not recorded.'
		end
	end

	text = text .. ' The page can remain available until a rewrite is ready. See [[Vrienden Universe:Pages marked for rewrite|pages marked for rewrite]] for guidance.'
	if reason then
		text = text .. "<br>'''Reason:''' " .. reason
	end

	local border_color = overdue and '#b32424' or '#d99b00'
	local background_color = overdue and '#fee7e6' or '#fff6cc'
	local output = '<div class="vu-rewrite-box" role="note" style="box-sizing: border-box; margin: 0 0 1em; padding: 0.8em 1em; border: 1px solid '
		.. border_color
		.. '; border-left: 6px solid '
		.. border_color
		.. '; background: '
		.. background_color
		.. '; color: #202122;">'
		.. text
		.. '</div>'

	if mw.title.getCurrentTitle().namespace == 0 then
		output = output .. '[[Category:Pages marked for rewrite]]'
	end
	return output
end

return p