More actions
dustloop>TarkusLee No edit summary |
dustloop>TarkusLee No edit summary |
||
| Line 17: | Line 17: | ||
local tables = 'Glossary' | local tables = 'Glossary' | ||
local fields = 'term,definition,gameSpecifier' | local fields = 'term,definition,gameSpecifier' | ||
local args = {} | |||
if gameSpecifier then | if gameSpecifier then | ||
args = { | |||
where = string.format('Glossary.gameSpecifier=%s',gameSpecifier), | where = string.format('Glossary.gameSpecifier=%s',gameSpecifier), | ||
orderBy = 'Glossary._rowID', | orderBy = 'Glossary._rowID', | ||
limit = | limit = '300', | ||
} | } | ||
else | else | ||
args = { | |||
orderBy = 'Glossary._rowID', | orderBy = 'Glossary._rowID', | ||
limit = | limit = '300', | ||
} | } | ||
end | end | ||
| Line 47: | Line 48: | ||
local match = data[ term ] | local match = data[ term ] | ||
if not match then | -- if not match then | ||
-- error( string.format( 'Could not find matching term: %s', term ) ) | |||
end | -- end | ||
return match | return match | ||
| Line 86: | Line 87: | ||
local term = getTerm( term, gameSpecifier ) | local term = getTerm( term, gameSpecifier ) | ||
local html = buildTooltip(term) | local html = buildTooltip(term) | ||
return tostring(html) | return tostring(html) | ||
end | end | ||
return p | return p | ||
Revision as of 16:44, 19 May 2024
Documentation for this module may be created at Module:Keyword/doc
local p = {}
local mArguments
local cargo
local cache = {}
--- Return the Moves data and cache the data for reuse on the same page
---
--- @return table
local function getGlossaryData( gameSpecifier )
-- Return cached data
if #cache > 0 then return cache end
-- Lazy initalize Module:Cargo
cargo = require( 'Module:Cargo' )
local tables = 'Glossary'
local fields = 'term,definition,gameSpecifier'
local args = {}
if gameSpecifier then
args = {
where = string.format('Glossary.gameSpecifier=%s',gameSpecifier),
orderBy = 'Glossary._rowID',
limit = '300',
}
else
args = {
orderBy = 'Glossary._rowID',
limit = '300',
}
end
local results = cargo.getQueryResults( tables, fields, args, false )
local items = {}
for _, result in pairs( results ) do
items[result.term] = result
end
-- Save to cache
cache = items
return cache
end
local function getTerm( term, gameSpecifier )
local data = getGlossaryData( gameSpecifier )
local match = data[ term ]
-- if not match then
-- error( string.format( 'Could not find matching term: %s', term ) )
-- end
return match
end
local function buildTooltip(term)
mw.logObject(term)
local tooltipHTML = mw.html.create('span'):addClass('tooltip')
:wikitext(term['term'])
:tag('span'):addClass('tooltiptext')
:wikitext(term['definition'])
:done()
:done()
return tooltipHTML
end
function p.main(frame)
mArguments = require( 'Module:Arguments' )
local args = mArguments.getArgs(frame)
return p._main(args)
end
--- Return the wikitext needed for the template
---
--- @return string
function p._main( args )
local term = args['term']
local gameSpecifier = args['gameSpecifier']
if not term then
error( 'No term specified for the template' )
end
local term = getTerm( term, gameSpecifier )
local html = buildTooltip(term)
return tostring(html)
end
return p