Module:Link: Difference between revisions

From SPCodex, The Smashing Pumpkins wiki
No edit summary
(link/no link)
Line 10: Line 10:
end
end


function p._studio_link(content)
function p._studio(content, link)
local studios = {
local studios = {
['Battery Studios'] = true,
['Battery Studios'] = true,
Line 56: Line 56:


if studio ~= nil then
if studio ~= nil then
table.insert(t, '[[' .. studio .. '|' .. s .. ']]')
if link then
table.insert(t, '[[' .. studio .. '|' .. s .. ']]')
else
table.insert(t, studio)
end
end
end
end
end
Line 86: Line 90:
ret = ret .. ', ' .. s
ret = ret .. ', ' .. s
end
end
 
return mw.text.trim(ret, ', ')
return mw.text.trim(ret, ', ')
end
end
Line 117: Line 121:
function p.studio( frame )
function p.studio( frame )
local content = frame.args[1]
local content = frame.args[1]
return p._studio_link(content)
return p._studio_link(content, false)
end
 
function p.studio_link( frame )
local content = frame.args[1]
return p._studio_link(content, true)
end
end



Revision as of 05:41, 11 July 2020

Documentation for this module may be created at Module:Link/doc

local p = {}

local function person_link( content, title, linkType, linkSubtype )
	for _i, subject in ipairs({ 'Billy Corgan', 'James Iha', "D'arcy Wretzky", 'Jimmy Chamberlin', 'Butch Vig', 'Flood', 'Alan Moulder', 'Kerry Brown', 'Bjorn Thorsrud', 'Nellee Hooper', 'Terry Date', 'Jeff Schroeder', 'Howard Willing', 'Rick Rubin', 'Roy Thomas Baker', 'Brad Wood', 'Dale Griffin', 'Ted de Bono' }) do
		local cat_str = 'Category:' .. linkType .. 's ' .. linkSubtype .. ' by ' .. subject .. '|'
		content = mw.ustring.gsub( content, subject, '[[:' .. cat_str .. subject .. ']][[' .. cat_str .. title .. ']]' )
	end
	
	return content
end

function p._studio(content, link)
	local studios = {
		['Battery Studios'] = true,
		['BBC Radio One Studios'] = true,
		['Broadway Rehearsal Studios'] = true,
		['Bugg Studios'] = true,
		['Charing Cross Studios'] = true,
		['Chicago Recording Company'] = true,
		['Chicago Trax Recording'] = true,
		['Chung King Studios'] = true,
		['Coldwater Studios'] = true,
		['Maida Vaile Studios'] = true,
		['Penguin Studios'] = true,
		['Pumpkinland'] = true,
		['Pumpkinland II'] = true,
		['Reel Time Studios'] = true,
		['Sadlands'] = true,
		['Schwa Productions'] = true,
		['Smart Studios'] = true,
		['Solid Sound Studios'] = true,
		['Sound City Studios'] = true,
		['Soundworks Studio'] = true,
		['Streeterville Studios'] = true,
		['Sunset Sound'] = true,
		['Sweet 16 Studio'] = true,
		['The Hinge Chicago'] = true,
		['The Hit Factory'] = true,
		['The Village Recorder'] = true,
		['VPRO Radio'] = true,
		['Waterfront Studios'] = true,
		['WZRD Studios'] = true
	}

	local t = {}
	for s in string.gmatch(content, "([^,]+)") do
		s = mw.text.trim(s)
		local studio = nil
		if studios[s] ~= nil then
			studio = s
		elseif studios[s .. ' Studios'] ~= nil then
			studio = s .. ' Studios'
		elseif studios[s .. ' Studio'] ~= nil then
			studio = s .. ' Studio'
		end

		if studio ~= nil then
			if link then
				table.insert(t, '[[' .. studio .. '|' .. s .. ']]')
			else
				table.insert(t, studio)
			end
		end
	end

	local ret = ''
	for _i, s in pairs(t) do
		ret = ret .. ', ' .. s
	end

	return mw.text.trim(ret, ', ')
end

function p._link(content, kind)
	local t = {}
	for s in string.gmatch(content, "([^,]+)") do
		s = mw.text.trim(s)
		if kind == 'album' then
			s = "''[[" .. s .. "]]''"
		elseif kind == 'song' then
			s = '"[[' .. s .. ']]"'
		else
			s = '[[' .. s .. ']]'
		end
		table.insert(t, s)
	end

	local ret = ''
	for _i, s in pairs(t) do
		ret = ret .. ', ' .. s
	end

	return mw.text.trim(ret, ', ')
end

function p._categorize(content, suffix)
	local t = {}
	for s in string.gmatch(content, "([^,]+)") do
		s = mw.text.trim(s)
		s = '[[Category:' .. s .. ' ' .. suffix .. ']]'
		table.insert(t, s)
	end

	local ret = ''
	for _i, s in pairs(t) do
		ret = ret .. s
	end

	return mw.text.trim(ret, ', ')
end

function p.main( frame )
	local content = frame.args[1]
	local kind = frame.args[2]
	if content == '' then
		return content
	end
	return p._link(content, kind)
end

function p.studio( frame )
	local content = frame.args[1]
	return p._studio_link(content, false)
end

function p.studio_link( frame )
	local content = frame.args[1]
	return p._studio_link(content, true)
end

function p.categorize( frame )
	local content = frame.args[1]
	local suffix = frame.args[2]
	if content == '' then
		return content
	end
	return p._categorize(content, suffix)
end

function p.album( frame )
	local content = frame.args[1]
	if content == '' then
		return content
	end
	return p._link(content, 'album')
end

function p.producer( frame )
	local content = frame.args[1]
	local title = frame.args[2]
	local linkType = frame.args[3]
	if content == '' then
		return content
	end

	return person_link(content, title, linkType, 'produced')
end

function p.writer( frame )
	local content = frame.args[1]
	local title = frame.args[2]
	local linkType = frame.args[3]
	if content == '' then
		return content
	end

	return person_link(content, title, linkType, 'written')
end

return p