Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
You must create an account or log in to edit.

Module:Remove parentheses: Difference between revisions

From Amaranth Legacy, available at amaranth-legacy.community
Content deleted Content added
No edit summary
No edit summary
Line 4: Line 4:
local p = {}
local p = {}


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


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


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


Line 26: Line 26:


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

Revision as of 15:21, February 15, 2025

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


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

local p = {}

function p.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.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 = p.getDisplayTitle(args['scope'], title)
	if title ~= displayTitle then
		return mw.ext.displaytitle.set(displayTitle)
	else
		return ''
	end
end

return p