Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
You must create an account or log in to edit.
Revision as of 18:08, January 28, 2025 by Tesinormed (talk | contribs)

Removes parentheses in a page title; used by Template:Remove parentheses


local libraryUtil = require('libraryUtil')
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg

local p = {}

local function getDisplayTitle(scope, title)
	-- input validation
	checkTypeForNamedArg('getDisplayTitle', 'scope', scope, 'string', false)
	checkTypeForNamedArg('getDisplayTitle', 'title', title, 'string', false)

	if title:find(' %(' .. scope .. '%)$') then
		return title:gsub(' %(' .. scope .. '%)', '')
	end

	if title:find(' %(' .. scope .. ',') then
		return title:gsub(' %(' .. scope .. ',', ' (')
	end

	return title
end

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

	return frame:callParserFunction(
		'DISPLAYTITLE',
		getDisplayTitle(args['scope'], mw.title.getCurrentTitle().prefixedText)
	)
end

return p