Advertisement

Module:TitleUtil

To edit the documentation or categories for this module, click here.


local util_map = require("Module:MapUtil")
local util_table = require('Module:TableUtil')
local util_text = require('Module:TextUtil')
local util_vars = require('Module:VarsUtil')

local p = {}
local h = {}

function p.titleTable(title)
	local title = title or mw.title.getCurrentTitle().text
	return util_text.split(title,'/')
end

function p.concatSubpage(base, extension)
	-- concatenate the two but don't add a / if the 2nd argument is empty or Overview
	if extension == 'Overview' or extension == '' or not extension then
		return base
	elseif base == '' or not base then
		return extension
	else
		return base .. '/' .. extension
	end
end

function p.concatSubpageParts(base, ...)
	local args = {...}
	while next(args) do
		base = p.concatSubpage(base, table.remove(args, 1))
	end
	return base
end

function p.concatSubpageArg(base, extension)
	if base == 'events' then base = nil end
	return p.concatSubpage(base, extension)
end

function p.concatSubpageSystem(base, extension)
	local systems = mw.loadData('Module:Systems')
	return p.concatSubpage(base, systems[extension])
end

function p.concatSystemSubpage(base, extension)
	local systems = mw.loadData('Module:Systems')
	return p.concatSubpage(systems[base], extension)
end

function p.concatSubpages(tbl, extension)
	for k, v in pairs(tbl) do
		tbl[k] = p.concatSubpage(v, extension)
	end
	return
end

function p.titleparts(str, n, s)
	local tbl = util_text.split(str or mw.title.getCurrentTitle().text, '/')
	s = util_table.guaranteeIndex(tbl, s)
	return table.concat(util_table.slice(tbl,s,s+n-1),'/')
end

function p.titleslice(str, s, e)
	local tbl = p.titleTable(str)
	s = util_table.guaranteeIndex(tbl, s)
	e = util_table.guaranteeIndex(tbl, e)
	return table.concat(util_table.slice(tbl,s,e),'/')
end

function p.target(page)
	if not page then return nil end
	local title = mw.title.makeTitle(ns or '', page)
	if title.redirectTarget then
		return p.escape(title.redirectTarget.fullText)
	end
	return p.escape(page)
end

function p.isRedirect(page)
	return p.target(page) ~= page
end

function p.escape(page)
	return util_text.ucfirst(page:gsub('_', ' '))
end

function p.lowercase()
	return mw.getCurrentFrame():expandTemplate({ title = 'lowercase' })
end

return p

Power Rankings of Brazil and Oceania are not yet updated to the last season, we are doing our best to update them before the start of the new competitive season. Please be patient.

READ MORE