Module:NewsQueryPlayer

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 = { }

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:init(args) self:super('init', args) util_table.mergeArrays(self.PRELOADS_TO_IGNORE, PRELOADS_TO_IGNORE) end

function NewsQuery:getQuery(args) local query = self:super('getQuery', args) local new = { tables = { 'NewsItems__Players=NP', 'PlayerRedirects=PR' }, join = { 'News._ID=NP._rowID', 'NP._value = PR.AllName' }, fields = { 'NP._value=ThisPlayer' }, where = self: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 NewsQuery:getWhere(args, where) local tbl = { where, ('PR._pageName="%s"'):format(h.getPlayer(args.player)), util_news.getExcludedNewsPreloadsWhereCondition(self.PRELOADS_TO_IGNORE), }	return util_cargo.concatWhere(tbl) end

function h.getPlayer(player) return player or mw.title.getCurrentTitle.baseText 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