Content added Content deleted
m (variable name fix) |
(added more flexibility to arguments) |
||
Line 28: | Line 28: | ||
end |
end |
||
end |
end |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
return p._main |
return p._main{ |
||
⚫ | |||
size = args['size'], |
|||
⚫ | |||
count = args['count'] |
|||
} |
|||
end |
end |
||
function p._main( |
function p._main(args) |
||
local thumb = args['image'] or '' |
|||
⚫ | |||
local link = args['link'] or '' |
|||
⚫ | |||
local root = mw.html.create('div') |
local root = mw.html.create('div') |
||
root:addClass('item-thumbnail') |
root:addClass('item-thumbnail') |
Revision as of 02:45, 12 July 2022
local getArgs = require('Module:Arguments').getArgs
local QueryBuilder = require('Module:QueryBuilder')
local p = {}
function p.main(frame)
local args = getArgs(frame)
local item = string.lower(args['item'] or '')
local thumb = nil
local link = nil
if item then
local qb = QueryBuilder.new()
qb
:setTables('Items')
:setFields([[
_pageName,
image
]])
:addWhere('item_name', '=', item)
local results = qb:query()
if #results > 0 then
thumb = results[1]['image']
link = results[1]['_pageName']
end
end
return p._main{
image = args['image'] or thumb,
size = args['size'],
link = args['link'] or link,
count = args['count']
}
end
function p._main(args)
local thumb = args['image'] or ''
local thumbSize = args['size'] or '80px'
local link = args['link'] or ''
local count = args['count'] or '1'
local root = mw.html.create('div')
root:addClass('item-thumbnail')
:css({
['height'] = thumbSize,
['width'] = thumbSize
})
:wikitext(string.format(
'[[File:%s|%s|link=%s|%s]]',
thumb,
thumbSize,
link,
link
))
if count and tonumber(count) > 1 then
root:tag('div')
:addClass('item-count')
:addClass('theme-primary')
:wikitext('x' .. count)
end
return
mw.getCurrentFrame():extensionTag{
name = 'templatestyles',
args = { src = 'Template:Item thumbnail/styles.css' }
} .. tostring(root)
end
return p