Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
You must create an account or log in to edit.
Revision as of 15:26, February 15, 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(specifier, title)
	-- input validation
	checkTypeForNamedArg('getDisplayTitle', 'specifier', specifier, 'string', false)
	checkTypeForNamedArg('getDisplayTitle', 'title', title, 'string', false)

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

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

	return title
end

function p.invoke(frame)
	return getDisplayTitle(frame:getArgument('specifier'), frame:getArgument('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

	local title = mw.title.getCurrentTitle().prefixedText
	local displayTitle = getDisplayTitle(args['scope'], title)
	if title ~= displayTitle then
		return mw.ext.displaytitle.set(displayTitle)
	else
		return ''
	end
end

return p