Jump to content

Module:Contentious topics/aware

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Dreamy Jazz (talk | contribs) at 11:23, 16 January 2023 (Protected "Module:Contentious topics/aware": Highly visible template ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}
local getArgs = require('Module:Arguments').getArgs

function p.detect(frame)
	local title
	local args = getArgs(frame)
	if args.testTitle then
		title = mw.title.new(args.testTitle)
	else
		title = mw.title.getCurrentTitle()
	end
	local content = title:getContent() or ''
	local codes = string.match(content, "{{%s-[cC]ontentious [tT]opics/[aA]ware%s-|([^}]-)}}")
	if not codes then return end
	local text = p._listToText(frame, mw.text.split(codes, "|"))
	return frame:preprocess(
		"<div style = 'font-weight: bold'>It is not necessary to notify this user about the following topics being contentious topics:"
		..text..
		"\n The user has indicated that they are already aware using the template <nowiki>{{Contentious topics/aware}}</nowiki> on their talk page.</div>"
	)
end

function p.listToText(frame)
	return p._listToText(frame, getArgs(frame))
end

function p._listToText(frame, t)
	local new = {}
	local t = require('Module:TableTools').compressSparseArray(t)
	for i,v in ipairs(t) do
		table.insert(new, frame:expandTemplate{title = 'Contentious_topics/list', args = {["sanctions scope"] = v}})
	end
	return '\n*'..table.concat(new, '\n*')
end

return p