Module:PageTabs org: Difference between revisions

From TwogPedia
(Created page with "local cargo = mw.ext.cargo local PageTabs = {} function PageTabs.main(frame) local currentTitle = mw.title.getCurrentTitle().text local empty = true local titleSplit = mw.text.split(currentTitle, '/') local org = #titleSplit > 1 and titleSplit[2] or currentTitle -- Check if there are any interviews for this page local tables = 'Teams' local fields = '_pageName, org' local cargoArgs = { where = 'org="' .. org .. '"' } local results = cargo.query(tables, f...")
 
mNo edit summary
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
local cargo = mw.ext.cargo
local cargo = mw.ext.cargo
 
local getArgs = require('Module:Arguments').getArgs
local PageTabs = {}
local PageTabs = {}


function PageTabs.main(frame)
function PageTabs.main(frame)
local currentTitle = mw.title.getCurrentTitle().text
    local args = getArgs(frame)
local currentTitle = args .title or mw.title.getCurrentTitle().text
local empty = true
local empty = true
local titleSplit = mw.text.split(currentTitle, '/')
local org = currentTitle
local org = #titleSplit > 1 and titleSplit[2] or currentTitle


-- Check if there are any interviews for this page
-- Check if there are any interviews for this page
Line 20: Line 19:
tabArgs.name1='Organization'
tabArgs.name1='Organization'
tabArgs.link1 = org
tabArgs.link1 = org
 
if #results > 0 then
if #results > 0 then
empty = false
empty = false
for r = 2, #results do
local game = ''
local gameIndex = 2
for r = 1, #results do
local result = results[r]
local result = results[r]
local resultSplit = mw.text.split(result._pageName, '/')
local resultSplit = mw.text.split(result._pageName, '/')
tabArgs['name' .. tostring(r)] = resultSplit[1]
if game ~= resultSplit[1] then
tabArgs['link' .. tostring(r)] = resultSplit[2]
tabArgs['name' .. tostring(r + 1)] = resultSplit[1]
gameIndex = 2
else
tabArgs['name' .. tostring(r + 1)] = resultSplit[1] .. ' ' .. tostring(gameIndex)
gameIndex = gameIndex + 1
end
game = resultSplit[1]
tabArgs['link' .. tostring(r + 1)] = result._pageName
end
end
end
end
Line 36: Line 44:
return frame:expandTemplate{ title = 'Tabs', args = tabArgs }
return frame:expandTemplate{ title = 'Tabs', args = tabArgs }
end
end
end
end


return PageTabs
return PageTabs

Latest revision as of 19:36, 9 October 2023

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

local cargo = mw.ext.cargo
local getArgs = require('Module:Arguments').getArgs
local PageTabs = {}

function PageTabs.main(frame)
    local args = getArgs(frame)
	local currentTitle = args .title or mw.title.getCurrentTitle().text
	local empty = true
	local org = currentTitle

	-- Check if there are any interviews for this page
	local tables = 'Teams'
	local fields = '_pageName, org'
	local cargoArgs = {
		where = 'org="' .. org .. '"'
	}
	local results = cargo.query(tables, fields, cargoArgs)
	local tabArgs = {}
	tabArgs.name1='Organization'
	tabArgs.link1 = org
	
	if #results > 0 then
		empty = false
		local game = ''
		local gameIndex = 2
		for r = 1, #results do
			local result = results[r]
			local resultSplit = mw.text.split(result._pageName, '/')
			if game ~= resultSplit[1] then
				tabArgs['name' .. tostring(r + 1)] = resultSplit[1]
				gameIndex = 2
			else 
				tabArgs['name' .. tostring(r + 1)] = resultSplit[1] .. ' ' .. tostring(gameIndex)
				gameIndex = gameIndex + 1
			end
			game = resultSplit[1]
			tabArgs['link' .. tostring(r + 1)] = result._pageName
		end
	end
	
	if empty then
		return '<span class="d-none"></span>'
	else
		return frame:expandTemplate{ title = 'Tabs', args = tabArgs }
	end
end

return PageTabs