Leaguepedia | League of Legends Esports Wiki
Advertisement
Leaguepedia | League of Legends Esports Wiki

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

local util_args = require('Module:ArgsUtil')
local util_cargo = require("Module:CargoUtil")
local util_esports = require("Module:EsportsUtil")
local util_html = require("Module:HtmlUtil")
local util_news = require("Module:NewsUtil")
local util_source = require("Module:SourceUtil")
local util_table = require("Module:TableUtil")
local util_text = require("Module:TextUtil")
local util_time = require("Module:TimeUtil")
local util_vars = require("Module:VarsUtil")
local i18n = require('Module:i18nUtil')

local NewsQueryAbstract = require('Module:NewsQueryAbstract')
local NewsQuery = NewsQueryAbstract:extends()

local THRESHOLD_TO_TAB = 10

NewsQuery.SUBJECT_SIZE = 45

local PRELOADS_TO_IGNORE = {
	'contract_data_removal', 'contract_data_fuzzy', 'opportunities', 'expire_notleave',
}

local lang = mw.getLanguage('en')

local h = {}

local p = {}

function p.main(frame)
	local args = util_args.merge()
	return p._main(args)
end

function p._main(args)
	return NewsQuery(args):run()
end

function NewsQuery:getQuery(args)
	local query = self:super('getQuery', args)
	local new = {
		tables = { 'NewsItems__Teams=NT', 'TeamRedirects=TR', 'Teams=T', 'Organizations=O' },
		join = {
			'News._ID=NT._rowID',
			'NT._value=TR.AllName',
			'TR._pageName=T._pageName',
			'T.OrganizationPage=O.OverviewPage',
		},
		where = h.getWhere(args, query.where),
		orderBy = 'News.Date_Sort ASC, N_LineInDate ASC, News.Date_Display, News.IsApproxDate',
	}
	return util_cargo.concatQueriesAnd(query, new)
end

function h.getWhere(args, where)
	local tbl = {
		where,
		('O.OverviewPage="%s"'):format(h.getOrg(args)),
		util_news.getExcludedNewsPreloadsWhereCondition(PRELOADS_TO_IGNORE),
	}
	return util_cargo.concatWhere(tbl)
end

function h.getOrg(args)
	return args[1] or mw.title.getCurrentTitle().text
end

function NewsQuery:groupDataByDate(data)
	local byDate = self:super('groupDataByDate', data)
	local byYear = {}
	for _, date in ipairs(byDate) do
		util_table.initDict(byYear, byDate[date].year)
		util_table.pushDict(byYear[byDate[date].year], date, byDate[date])
	end
	return byYear
end

function NewsQuery:getDateKey(row)
	return (row.Date_Display or row.Date) .. tostring(row.IsApproxDate) .. row.Subject
end

-- print
function NewsQuery:makeOutput(byDate, args)
	local tabs = {}
	for _, year in ipairs(byDate) do
		tabs[#tabs+1] = {
			name = year,
			content = h.getYearContent(byDate[year])
		}
	end
	return util_news.sectionsOrTabs(byDate, THRESHOLD_TO_TAB, tabs)
end

function h.getYearContent(byDate)
	local tbl = mw.html.create('table')
		:addClass('news-table')
		:addClass('news-player-table')
		:addClass('hoverable-rows')
	for _, date in ipairs(byDate) do
		h.printDateAndContent(tbl, byDate[date])
	end
	return tostring(tbl)
end

function h.printDateAndContent(tbl, lines)
	local tr = tbl:tag('tr')
	tr:tag('td')
		:wikitext(lines.region)
	tr:tag('td')
		:wikitext(lines.subject)
		:addClass('news-player-subject')
	local td = tr:tag('td')
		:addClass('news-player-content')
	for i, line in ipairs(lines) do
		h.printLine(td, i, line)
		if i < #lines then
			td:wikitext(' ')
		end
	end
	util_news.printEditButton(td, lines.page)
end

function h.printLine(td, i, line)
	td:wikitext(util_esports.boldLinksToThisPlayer(
		h.getSentenceVersion(line, i),
		line.ThisPlayer
	))
	if DEBUG then td:wikitext(line.Preload) end
	h.printRef(td, line)
end

function h.getSentenceVersion(line, i)
	if i == 1 then return line.SentenceWithDate end
	return line.Sentence
end

function h.printRef(td, line)
	if not line.Source then return end
	td:wikitext(util_source.makeRef(line.Source))
end

return p
Advertisement