More actions
Arvid Varg (talk | contribs) No edit summary Tag: Manual revert |
Arvid Varg (talk | contribs) No edit summary |
||
| Line 3: | Line 3: | ||
function p.processTitle(frame) | function p.processTitle(frame) | ||
local input = frame.args[1] or "" | local input = frame.args[1] or "" | ||
if mw.ustring.match(input, "^%s*%{%{%s*[Tt]itle%s*[|}]") then | if mw.ustring.match(input, "^%s*%{%{%s*[Tt]itle%s*[|}]") then | ||
return input | return input | ||
end | end | ||
return frame:expandTemplate{ | return frame:expandTemplate{ | ||
title = "Title", | title = "Title", | ||
| Line 37: | Line 33: | ||
text = mw.ustring.gsub(text, "[%[%]]", "") | text = mw.ustring.gsub(text, "[%[%]]", "") | ||
return text | return text | ||
end | |||
-- New function: automatically adds parent categories | |||
function p.addParentCategories(frame) | |||
local subcat = frame.args[1] or "" | |||
subcat = mw.text.trim(subcat) | |||
if subcat == "" then return "" end | |||
local result = "[[Category:" .. subcat .. "]]" | |||
-- Look for the category page | |||
local catTitle = mw.title.new("Category:" .. subcat) | |||
if catTitle and catTitle.exists then | |||
local catPage = mw.title.new(catTitle.prefixedText) | |||
local catContent = catPage:getContent() or "" | |||
-- Find all categories listed on the subcategory page | |||
for parent in catContent:gmatch("%[%[Category:(.-)%]%]") do | |||
if parent ~= subcat then | |||
result = result .. "\n[[Category:" .. parent .. "]]" | |||
end | |||
end | |||
end | |||
return result | |||
end | end | ||
return p | return p | ||
Revision as of 21:50, 30 March 2026
Titles
! colspan="2" class="infobox-subheader" | Not on a character |-
! colspan="2" class="infobox-subheader" |
|-
| Gnoblin | |
|---|---|
| Using the template | |
| Gnoblin | |
|---|---|
| Simple name only | |
local p = {}
function p.processTitle(frame)
local input = frame.args[1] or ""
if mw.ustring.match(input, "^%s*%{%{%s*[Tt]itle%s*[|}]") then
return input
end
return frame:expandTemplate{
title = "Title",
args = { name = input }
}
end
function p.stripHouse(frame)
local name = frame.args[1]
if not name or name == "" then
name = mw.title.getCurrentTitle().text
end
local prefixes = { "House", "Clan", "Family", "Dynasty" }
for _, prefix in ipairs(prefixes) do
local pattern = "^[" .. mw.ustring.sub(prefix,1,1):lower() .. mw.ustring.sub(prefix,1,1):upper() .. "]" ..
mw.ustring.sub(prefix,2):lower() .. "%s+"
name = mw.ustring.gsub(name, pattern, "")
end
return name
end
function p.unlink(frame)
local text = frame.args[1] or ""
text = mw.ustring.gsub(text, "[%[%]]", "")
return text
end
-- New function: automatically adds parent categories
function p.addParentCategories(frame)
local subcat = frame.args[1] or ""
subcat = mw.text.trim(subcat)
if subcat == "" then return "" end
local result = "[[Category:" .. subcat .. "]]"
-- Look for the category page
local catTitle = mw.title.new("Category:" .. subcat)
if catTitle and catTitle.exists then
local catPage = mw.title.new(catTitle.prefixedText)
local catContent = catPage:getContent() or ""
-- Find all categories listed on the subcategory page
for parent in catContent:gmatch("%[%[Category:(.-)%]%]") do
if parent ~= subcat then
result = result .. "\n[[Category:" .. parent .. "]]"
end
end
end
return result
end
return p