Jump to content

Module:Italic title/sandbox

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Nullzero (talk | contribs) at 08:07, 22 August 2014. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
-- This module implements {{italic title}}, {{italic title prefixed}},
-- and {{lcfirstitalictitle}}.

local p = {}

local function _main(start)
	start = start or 0
	
	local title = mw.title.getCurrentTitle()
	
	-- Find the parts before and after the disambiguation parentheses, if any.
	local prefix, parentheses = mw.ustring.match(title.text, '^(.+) (%([^%(%)]+%))$')

	-- If parentheses were found, italicise only the part before them. Otherwise
	-- italicise the whole title.
	local result
	if prefix and parentheses and args.all ~= 'yes' then
		result = prefix
	else
		result = title.text
		parentheses = nil
	end
	
	result = result:sub(1, start) .. "''" .. result:sub(start + 1) .. "''"
	
	if parenthesis then
		result = result .. " " .. parentheses
	end

	-- Add the namespace if we're not in mainspace.
	if title.namespace ~= 0 then
		result = mw.site.namespaces[title.namespace].name .. ':' .. result
	end
	
	return result
end

function p.italic_title(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:Italic title'
	})
	-- Call displaytitle with the text we generated.
	return mw.getCurrentFrame():callParserFunction(
		'DISPLAYTITLE',
		_main(),
		args[1]
	)
end

function p.lcfirstitalictitle(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:Lcfirstitalictitle'
	})
	-- Call displaytitle with the text we generated.
	local lang = mw.language.getContentLanguage()
	return mw.getCurrentFrame():callParserFunction(
		'DISPLAYTITLE',
		lang:lcfirst(_main()),
		args[1] -- TODO: what are original parameters in Template:Lcfirstitalictitle?
	)
end

function p.italic_title_prefixed(frame)
	local args = require('Module:Arguments').getArgs(frame, {
		wrappers = 'Template:Italic title prefixed/sandbox'
	})
	-- Call displaytitle with the text we generated.
	return mw.getCurrentFrame():callParserFunction(
		'DISPLAYTITLE',
		_main(args[1]),
		args[2] -- TODO: what are original parameters in Template:Italic title prefixed?
	)
end

return p