Module:Remove parentheses: Difference between revisions
From Amaranth Legacy, available at amaranth-legacy.community
More actions
Content deleted Content added
Tesinormed (talk | contribs) No edit summary |
Tesinormed (talk | contribs) No edit summary |
||
| Line 28: | Line 28: | ||
local displayTitle = getDisplayTitle(args['scope'], title) |
local displayTitle = getDisplayTitle(args['scope'], title) |
||
if title ~= displayTitle then |
if title ~= displayTitle then |
||
return |
return mw.ext.displaytitle.set(displayTitle) |
||
else |
else |
||
return '' |
return '' |
||
Revision as of 22:22, February 4, 2025
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
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