Content added Content deleted
(added more flexibility to arguments) |
mNo edit summary |
||
Line 31: | Line 31: | ||
return p._main{ |
return p._main{ |
||
image = args['image'] or thumb, |
image = args['image'] or thumb, |
||
size = args['size'], |
size = args['size'], |
||
link = args['link'] or link, |
link = args['link'] or link, |
||
count = args['count'] |
count = args['count'] |
||
} |
} |
||
Line 41: | Line 41: | ||
local thumbSize = args['size'] or '80px' |
local thumbSize = args['size'] or '80px' |
||
local link = args['link'] or '' |
local link = args['link'] or '' |
||
local count = args['count'] or |
local count = args['count'] or 1 |
||
local root = mw.html.create('div') |
local root = mw.html.create('div') |
Revision as of 02:47, 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