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) m Removed protection from "Module:Remove parentheses" |
||
| (7 intermediate revisions by the same user not shown) | |||
| Line 1: | Line 1: | ||
| ⚫ | |||
local libraryUtil = require('libraryUtil') |
local libraryUtil = require('libraryUtil') |
||
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg |
local checkTypeForNamedArg = libraryUtil.checkTypeForNamedArg |
||
| Line 16: | Line 17: | ||
if title:find(' %(' .. specifier .. ', ') then |
if title:find(' %(' .. specifier .. ', ') then |
||
local result, _ = title:gsub(' %(' .. specifier .. ', ', ' (') |
local result, _ = title:gsub(' %(' .. specifier .. ', ', ' (') |
||
return result |
|||
end |
|||
if title:find(' %(' .. specifier .. ' %- ') then |
|||
local result, _ = title:gsub(' %(' .. specifier .. ' %- ', ' (') |
|||
return result |
return result |
||
end |
end |
||
| Line 22: | Line 29: | ||
end |
end |
||
function p.invoke( |
function p.invoke(specifier) |
||
| ⚫ | |||
| ⚫ | |||
local displayTitle = getDisplayTitle(specifier, title) |
|||
-- input validation |
|||
| ⚫ | |||
if not args['specifier'] then error('"specifier" argument is required') end |
|||
| ⚫ | |||
else |
|||
return getDisplayTitle(args['specifier'], mw.title.getCurrentTitle().text) |
|||
return '' |
|||
end |
|||
end |
end |
||
| Line 35: | Line 44: | ||
if not args['specifier'] then error('"specifier" argument is required') end |
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 |
else |
||
return '' |
return p.invoke(args['specifier']) |
||
end |
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