Module:Link: Difference between revisions

From SPCodex, The Smashing Pumpkins wiki
No edit summary
m (Protected "Module:Link" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite) [Delete=Allow only administrators] (indefinite)))
 
(7 intermediate revisions by the same user not shown)
Line 10: Line 10:
end
end


function p._studio(content, link)
function p._studio(content, storage)
local studios = {
local studios = {
['Battery Studios'] = true,
['Battery Studios'] = true,
Line 18: Line 18:
['Charing Cross Studios'] = true,
['Charing Cross Studios'] = true,
['Chicago Recording Company'] = true,
['Chicago Recording Company'] = true,
['Chicago Trax Recording'] = true,
['Chicago Trax Recording Studio'] = true,
['Chung King Studios'] = true,
['Chung King Studios'] = true,
['Coldwater Studios'] = true,
['Coldwater Studios'] = true,
['Eddy Street'] = true,
['Maida Vaile Studios'] = true,
['Maida Vaile Studios'] = true,
['Penguin Studios'] = true,
['Penguin Studios'] = true,
Line 26: Line 27:
['Pumpkinland II'] = true,
['Pumpkinland II'] = true,
['Reel Time Studios'] = true,
['Reel Time Studios'] = true,
['River North'] = true,
['Sadlands'] = true,
['Sadlands'] = true,
['Schwa Productions'] = true,
['Schwa Productions'] = true,
Line 38: Line 40:
['The Hit Factory'] = true,
['The Hit Factory'] = true,
['The Village Recorder'] = true,
['The Village Recorder'] = true,
['Triclops Sound Studios'] = true,
['VPRO Radio'] = true,
['VPRO Radio'] = true,
['Waterfront Studios'] = true,
['Waterfront Studios'] = true,
Line 43: Line 46:
}
}


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


if studio ~= nil then
if studio ~= nil then
if link then
if storage then
table.insert(t, '[[' .. studio .. '|' .. s .. ']]')
content = mw.ustring.gsub(content, s:gsub("([^%w])", "%%%1"), studio)
else
else
table.insert(t, studio)
content = mw.ustring.gsub(content, s_normalized, '[[' .. studio .. '|' .. s_normalized .. ']]')
end
end
elseif storage then
content = mw.ustring.gsub(content, s, '')
end
end
end
end


local ret = ''
return mw.text.trim(content, '\t\r\n\f ,')
for _i, s in pairs(t) do
ret = ret .. ', ' .. s
end
 
return mw.text.trim(ret, ', ')
end
end


Line 119: Line 122:
end
end


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


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



Latest revision as of 22:05, 29 March 2023

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, storage)
	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 Studio'] = true,
		['Chung King Studios'] = true,
		['Coldwater Studios'] = true,
		['Eddy Street'] = true,
		['Maida Vaile Studios'] = true,
		['Penguin Studios'] = true,
		['Pumpkinland'] = true,
		['Pumpkinland II'] = true,
		['Reel Time Studios'] = true,
		['River North'] = 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,
		['Triclops Sound Studios'] = true,
		['VPRO Radio'] = true,
		['Waterfront Studios'] = true,
		['WZRD Studios'] = true
	}

	-- if storage then
	-- 	content = content:gsub('(%(.*%))', '')
	-- end
	for s in string.gmatch(content, "([^,]+)") do
		s = mw.text.trim(s)
		local s_normalized = mw.text.trim(s:gsub('( *%(.*%))', ''))
		local studio = nil
		if studios[s_normalized] ~= nil then
			studio = s_normalized
		elseif studios[s_normalized .. ' Studios'] ~= nil then
			studio = s_normalized .. ' Studios'
		elseif studios[s_normalized .. ' Studio'] ~= nil then
			studio = s_normalized .. ' Studio'
		end

		if studio ~= nil then
			if storage then
				content = mw.ustring.gsub(content, s:gsub("([^%w])", "%%%1"), studio)
			else
				content = mw.ustring.gsub(content, s_normalized, '[[' .. studio .. '|' .. s_normalized .. ']]')
			end
		elseif storage then
			content = mw.ustring.gsub(content, s, '')
		end
	end

	return mw.text.trim(content, '\t\r\n\f ,')
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_storage( frame )
	local content = frame.args[1]
	return p._studio(content, true)
end

function p.studio( frame )
	local content = frame.args[1]
	return p._studio(content, false)
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