Module:PlayerPronunciations

local util_args = require('Module:ArgsUtil') local util_cargo = require('Module:CargoUtil') local util_html = require('Module:HtmlUtil') local util_text = require('Module:TextUtil') local util_vars = require('Module:VarsUtil')

local i18n = require('Module:i18nUtil')

local h = {}

local p = {} function p.getDataAndReturnPlaceholder(player) -- called from IntroSentence/Player local data = h.getCargoData(player or mw.title.getCurrentTitle.rootText) if not data or not next(data) then return '' end util_vars.setObject('pronunciationGuide', data) return ' PRONUNCIATION_REPLACE' end

function p.replaceButtonInSentence(frame) -- called from StandardBioSentence -- storing an sm2 extension tag in a variable was breaking things -- so the actual creation will be done here local args = util_args.merge(true) local sentence = args.sentence i18n.init('PlayerPronunciations') local data = util_vars.getObject('pronunciationGuide') if not data or not next(data) then return sentence end local ret = sentence:gsub('PRONUNCIATION_REPLACE', tostring(h.makeSentenceButton(data[1].File))) return ret end

function p.endOfPage -- called at the end of the page i18n.init('PlayerPronunciations') local data = util_vars.getObject('pronunciationGuide') if not data then return '' end return h.makeEndOfPageHeading, h.makeEndOfPageTables(data) end

function h.getCargoData(player) return util_cargo.queryAndCast(h.makeQuery(player)) end

function h.makeQuery(player) local ret = { tables = h.tables, join = h.join, fields = h.fields, orderBy = '_pD._modificationDate DESC', where = h.makeWhere(player) }	return ret end

h.tables = { 'PlayerPronunciationFiles=PF', '_pageData=_pD', 'PlayerRedirects=PR' }

h.join = { 'PF._pageName=_pD._pageName', 'PF.Player=PR.AllName' }

h.fields = { 'PF._pageName=File', 'PF.Name=Name', 'PF.RecordedBy=RecordedBy', 'PF.Source=Source', }

function h.makeWhere(player) local tbl = { ('PR._pageName="%s"'):format(player) }	return util_cargo.concatWhere(tbl) end

function h.makeSentenceButton(file) local output = mw.html.create('span') :addClass('no-desc2') output:wikitext('(', h.makeButton(file), ' ', h.makeAnchor, ')') return output end

function h.makeButton(file) return tostring(mw.getCurrentFrame:callParserFunction{			name = '#tag:sm2',			args = { file:gsub('File:', '') }		}) end

function h.makeAnchor return util_text.intLink('#Name Pronunciation', i18n.print('listen')) end

--- --- end of page ---

function h.makeEndOfPageHeading return mw.html.create('h3'):wikitext(i18n.print('heading')) end

function h.makeEndOfPageTables(data) local output = mw.html.create for _, row in ipairs(data) do		h.printTable(output, row) end return output end

function h.printTable(output, row) local tbl = output:tag('table') :addClass('wikitable') :addClass('player-pronunciation') util_html.printColspanHeader(tbl, row.Name, 2) h.printTableFile(tbl, row.File) h.printTableRow(tbl, h.accuracyLink, row.Source) h.printTableRow(tbl, i18n.print('RecordedBy'), row.RecordedBy) end

function h.printTableFile(tbl, file) tbl:tag('tr') :tag('td') :attr('colspan', 2) :addClass('player-pronunciation-file') :wikitext(h.makeFile(file)) end

function h.makeFile(file) return ('%s'):format(file) end

function h.printTableRow(tbl, key, val) local tr = tbl:tag('tr') tr:tag('th'):wikitext(key):addClass('player-pronunciation-label') tr:tag('td'):wikitext(val) end

function h.accuracyLink return util_text.intLink('Help:Player Pronunciation Guides#Approval', i18n.print('Accuracy')) end

return p