Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
You must create an account or log in to edit.
Revision as of 00:52, May 19, 2025 by Tesinormed (talk | contribs)

General template for scope hatnote templates

Parameters

for
Used in the description of the TemplateData
rawcss_ref
RawCSS application reference to use
categories
Categories to use (like Category:Scope: Imagindarium's Creation)
use_remove_parentheses
If Module:Remove parentheses should be used
use_hatnote_links
If Template:Hatnote links should be used

local yesno = require('Module:Yesno')

local p = {}

local function filterArgsAndStripPrefix(args, prefix)
	local prefixPattern = '^' .. prefix
	local result = {}

	for name, value in pairs(args) do
		-- if the prefix matches
		if name:find(prefixPattern) ~= nil then
			-- add to the result while removing the prefix
			result[name:gsub(prefixPattern, '')] = value
		end
	end

	return result
end

function p.main(frame)
	local args = require('Module:Arguments').getArgs(frame)
	local parentArgs = require('Module:Arguments').getArgs(frame:getParent())
	-- input validation
	if not args['for'] then error('"for" argument is required') end
	if not args['rawcss_ref'] then error('"rawcss_ref" argument is required') end
	if not args['categories'] then error('"categories" argument is required') end

	local result = ''

	-- remove parentheses from the displayed title
	if yesno(args['use_remove_parentheses'] or true) then
		result = result .. require('Module:Remove parentheses').invoke(args['for'])
	end

	-- indicator
	if yesno(args['use_indicator'] or true) and yesno(parentArgs['add_indicator'] or true) then
		result = result .. frame:extensionTag{
			name = 'indicator',
			content = '[[File:' .. (args['file'] or args['file1']) .. '|28px|link=Scope:' .. args['for'] .. '|Scope: ' .. args['for'] .. ']]',
			args = {
				name = 'scope-' .. args['rawcss_ref']
			}
		}
	end

	-- scope styling
	if yesno(parentArgs['use_scope_styling'] or true) then
		result = result .. frame:extensionTag('rawcss', '', {
			ref = args['rawcss_ref']
		})
	end

	-- hatnote
	result = result .. require('Module:Hatnote').main(frame)

	-- hatnote links
	if yesno(args['use_hatnote_links'] or false) then
		result = result .. frame:expandTemplate{
			title = 'Hatnote links',
			args = args
		}
	end

	-- additional text past the hatnotes
	if args['additional_text'] then
		result = result .. args['additional_text']
	end

	-- categories
	if yesno(parentArgs['add_category'] or true) then
		result = result .. args['categories']
	end

	-- TemplateData
	result = result .. frame:getParent():preprocess('<noinclude>' .. frame:extensionTag('templatedata',
		[[{
	"params": {
		"add_category": {
			"label": "Add category",
			"description": "If the scope category should be added to the page",
			"type": "boolean",
			"default": "true"
		},
		"add_indicator": {
			"label": "Add indicator",
			"description": "If the scope indicator should be added to the page",
			"type": "boolean",
			"default": "true"
		},
		"use_scope_styling": {
			"label": "Use scope styling",
			"description": "If the scope's styling should be used",
			"type": "boolean",
			"default": "true"
		}
	},
	"description": "Scope hatnote for ]] .. args['for'] .. [[",
	"format": "inline"
}]],
	{}) .. '[[Category:META: Hatnote]]</noinclude>')

	return result
end

return p