Module:Transcript

From Brighter Shores Wiki
Revision as of 07:25, 4 November 2024 by BlackHawk (talk | contribs) (Created page with "local p = {} function p.invoke_main(frame) local args = frame:getParent().args return p.main(args) end function p.main(args) local dtype = string.lower( args[1] or '' ) local pagetitle = mw.title.getCurrentTitle() local pagename = pagetitle.text local basepagename = pagetitle.baseText local ns3000 = pagetitle.namespace == 3000 -- Transcript namespace local linkarg = args.link local link = '' .. ( linkarg or pagename ) .. '' local linkb = args.linkb loca...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:No documentation/doc. [edit] [history] [purge]
This module does not have any documentation. Please consider adding documentation at Module:Transcript/doc. [edit]
Module:Transcript's function invoke_main is invoked by Template:Transcript.

local p = {}

function p.invoke_main(frame)
	local args = frame:getParent().args
	return p.main(args)
end

function p.main(args)
	local dtype = string.lower( args[1] or '' )
	local pagetitle = mw.title.getCurrentTitle()
	local pagename = pagetitle.text
	local basepagename = pagetitle.baseText
	local ns3000 = pagetitle.namespace == 3000  -- Transcript namespace
	local linkarg = args.link
	local link = '[[' .. ( linkarg or pagename ) .. ']]'
	local linkb = args.linkb
	local linkband = linkb and ( '[[' .. linkb .. ']] and ' ) or ''
	local title = args.title or pagename
	
	if dtype == 'update' then
		link = string.format('[[Update:%s|%s]]', ( linkarg or pagename ):gsub('^Update:', ''), pagename)
	end
	
	local sentences = {
		['item'] = 'the transcript of ' .. linkband .. link,
		['scenery'] = 'dialogue related to ' .. linkband .. 'the scenery object ' .. link
	}
	local defaultText = 'dialogue related to ' .. linkband .. link
	local source = 'The content below is copied verbatim from \'\'Brighter Shores\'\' and thus copyrighted by [[Fen Research]].'
	
	local startTable = '{| class="messagebox standard-talk plainlinks" style="border-left:none; text-align:center;"\n|-\n| '
	local line = 'This page contains ' .. ( sentences[dtype] or defaultText ) .. '.'
	local endTable = '<br clear="all" /><div style="font-size:0.85em; line-height:1.4em;">' .. source .. '</div>\n|-\n|}'
	
	local header = startTable .. line .. endTable
	
	local cats = {
		['item'] = {'Item transcripts'},
		['npc'] = {'NPC transcripts'},
		['quest'] = {'Quest transcripts'},
		['scenery'] = {'Scenery transcripts'}
	}
	
	local setcat = ''
	local displayTitle = ''
	if ns3000 then
		local cat = cats[dtype] or {'Miscellaneous transcripts'}
		setcat = '[[Category:' .. table.concat(cat, ']][[Category:') .. ']]'
		
		local titleTypeIds = {
			['npc'] = 1,
			['item'] = 2,
			['misc'] = 2,
			['quest'] = 2
		}
		local titleTypes = {
			'Dialogue for ' .. title,
			'Transcript of ' .. title
		}
		local newTitle = titleTypes[ titleTypeIds[dtype] or 2 ]
		displayTitle = mw.getCurrentFrame():callParserFunction{ name = 'DISPLAYTITLE', args = { newTitle } }
		-- set Transcript authors SMW
		if string.match(args.author or '', '%S') then
			local authors = {}
			for auth in string.gmatch(args.author, "[^;]+") do
				if string.lower(auth) == 'player' then
					table.insert(authors, 'Player character')
				else
					table.insert(authors, auth)
				end
			end
			mw.smw.set( { ['Transcript authors'] = authors } )
		end
	end
	
	return header .. setcat .. displayTitle
end

return p