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
m Removed protection from "Module:Remove parentheses"
 
(38 intermediate revisions by the same user not shown)
Line 1: Line 1:
local yesno = require('Module:Yesno')
local libraryUtil = require('libraryUtil')
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg


local p = {}
local p = {}


function p.getDisplayTitle(scope, title)
local function getDisplayTitle(specifier, title)
-- input validation
-- input validation
checkType('Module:Remove parentheses.getDisplayTitle', 1, scope, 'string')
checkTypeForNamedArg('getDisplayTitle', 'specifier', specifier, 'string', false)
checkType('Module:Remove parentheses.getDisplayTitle', 2, title, 'string')
checkTypeForNamedArg('getDisplayTitle', 'title', title, 'string', false)


if title:find('(' .. scope .. ')') then
if title:find(' %(' .. specifier .. '%)$') then
return title:gsub('%(' .. scope .. '%)', '')
local result, _ = title:gsub(' %(' .. specifier .. '%)', '')
return result
elseif title:find('(' .. scope .. ',') then
end
return title:gsub('%(' .. scope, '(')

if title:find(' %(' .. specifier .. ', ') then
local result, _ = title:gsub(' %(' .. specifier .. ', ', ' (')
return result
end


if title:find(' %(' .. specifier .. ' %- ') then
local result, _ = title:gsub(' %(' .. specifier .. ' %- ', ' (')
return result
end

return title
end

function p.invoke(specifier)
local title = mw.title.getCurrentTitle().prefixedText
local displayTitle = getDisplayTitle(specifier, title)
if title ~= displayTitle then
return mw.ext.displaytitle.set(displayTitle)
else
else
return title
return ''
end
end
end
end
Line 21: Line 42:
local args = require('Module:Arguments').getArgs(frame)
local args = require('Module:Arguments').getArgs(frame)
-- input validation
-- input validation
if not args['scope'] then error('"scope" argument is required') end
if not args['specifier'] then error('"specifier" argument is required') end


if yesno(args['return'] or false) then
return frame:callParserFunction(
return getDisplayTitle(args['specifier'], mw.title.getCurrentTitle().text)
'DISPLAYTITLE',
else
getDisplayTitle(args['scope'], mw.title.getCurrentTitle().fullText)
return p.invoke(args['specifier'])
)
end
end
end



Latest revision as of 10:51, September 11, 2025

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


local yesno = require('Module:Yesno')
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
		local result, _ = title:gsub(' %(' .. specifier .. '%)', '')
		return result
	end

	if title:find(' %(' .. specifier .. ', ') then
		local result, _ = title:gsub(' %(' .. specifier .. ', ', ' (')
		return result
	end


	if title:find(' %(' .. specifier .. ' %- ') then
		local result, _ = title:gsub(' %(' .. specifier .. ' %- ', ' (')
		return result
	end

	return title
end

function p.invoke(specifier)
	local title = mw.title.getCurrentTitle().prefixedText
	local displayTitle = getDisplayTitle(specifier, title)
	if title ~= displayTitle then
		return mw.ext.displaytitle.set(displayTitle)
	else
		return ''
	end
end

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

	if yesno(args['return'] or false) then
		return getDisplayTitle(args['specifier'], mw.title.getCurrentTitle().text)
	else
		return p.invoke(args['specifier'])
	end
end

return p