Die Dokumentation für dieses Modul kann unter Modul:ImageLink/Doku erstellt werden
-- <pre>
local ImageLink = {}
-- Dependencies
local HF = require("Dev:HF")
local FN = require("Module:Filename")
local lib = require('Module:Feature')
local CD = require('Module:Champion')
local userError = require('Dev:User error')
--[[
{{#invoke: ImageLink | ability
| champion =
| ability = -- can be empty
...
}}
{{#invoke: ImageLink | buff
| buff =
| variant = -- can be empty
...
}}
{{#invoke: ImageLink | champion
| champion =
| skin = -- can be empty
| circle = -- can be empty
| variant = -- can be empty
...
}}
{{#invoke: ImageLink | item
| item =
| enchantment = -- can be empty
| variant = -- can be empty
...
}}
{{#invoke: ImageLink | loading
| champion =
| skin =
| variant = -- can be empty
...
}}
{{#invoke: ImageLink | rune
| rune =
| variant = -- can be empty
...
}}
{{#invoke: ImageLink | spell
| spell =
| variant = -- can be empty
...
}}
{{#invoke: ImageLink | ward
| ward =
| variant = -- can be empty
...
}}
{{#invoke: ImageLink | basic
| link =
| text =
| alttext =
| image =
| image2 =
| image3 =
| size =
| width =
| height =
| border =
| separator =
| display =
| class =
| style =
| iconclass =
| iconstyle =
| label =
| labellink =
| labelclass =
| labelstyle =
| possessive =
| edit =
| editlink =
}}
]]--
local function formatnil(text, ...)
if select("#", ...) == 0 then return text end
for i=1, select("#", ...) do
if select(i, ...) == nil then return nil end
end
return mw.ustring.format(text, ...)
end
local function getSize(size)
local fields = HF.explode('x', mw.ustring.gsub(tostring(size or ''), 'px', '', 1))
local width = tonumber(fields[1]) or nil
local height = tonumber(fields[2]) or nil
return width, height
end
function ImageLink.ability(frame)
local args = lib.arguments(frame.args or frame)
args['champion'] = lib.validateName(args['champion'])
args['link'] = args['link'] or formatnil('%s#%s', args['champion'], args['ability']) or args['champion'] or ''
args['text'] = args['text'] or args['ability'] or ''
args['image'] = args['image'] or FN.ability{champion = args['champion'], ability = formatnil('%s_%s', args['ability'], args['abilitynum']) or args['ability'], variant = args['variant']}
args['editlink'] = args['editlink'] or formatnil('Template:Ability data/%s/%s', args['champion'], args['ability']) or ''
local t = formatnil('Template:Ability data/%s/%s', args['champion'], args['ability'])
if not t or args['notooltip'] ~= 'true' or not mw.title.new(t).exists then args['notooltip'] = 'true' end
local link, img = ImageLink._createLink(args)
if args['notooltip'] == 'true' then
else
link:addClass('ability-icon')
if args['champion'] then link:attr('data-champion', args['champion']) end
if args['ability'] then link:attr('data-ability', args['ability']) end
if args['variant'] then link:attr('data-variant', args['variant']) end
end
if args['width'] and img ~= nil then img:addClass('icon-' .. args['width']) end
return link
end
function ImageLink.buff(frame)
local args = lib.arguments(frame.args or frame)
args['link'] = args['link'] or args['buff'] or ''
args['text'] = args['text'] or args['buff'] or ''
args['image'] = args['image'] or FN.buff{args['buff'], args['variant']}
args['editlink'] = args['editlink'] or formatnil('Vorlage:Data %s', args['buff']) or ''
local link, img = ImageLink._createLink(args)
link:addClass('buff-icon')
if args['buff'] then link:attr('data-buff', args['buff']) end
if args['variant'] then link:attr('data-variant', args['variant']) end
if args['width'] and img ~= nil then img:addClass('icon-' .. args['width']) end
return link
end
function ImageLink.champion(frame)
local args = lib.arguments(frame.args or frame)
local _input = args['champion']
args['champion'] = lib.validateName(args['champion'])
args['link'] = args['link'] or args['champion'] or ''
args['text'] = args['text'] or _input or ''
if args['showtitle'] == 'true' then args['text'] = args['text']..', '..CD.get{'get', champname = args['champion'], datatype='title'} end
if args['circle'] == 'true' then
args['image'] = args['image'] or FN.championcircle{_input, args['skin'], args['variant']}
args['border'] = args['border'] or 'false'
else
args['image'] = args['image'] or FN.championsquare{_input, args['variant']}
end
args['editlink'] = args['editlink'] or 'Modul:Champion/data'
args['selflink'] = args['selflink'] or mw.title.getCurrentTitle().rootText
local link, img = ImageLink._createLink(args)
if args['notooltip'] == 'true' then
else
link:addClass('character-icon')
link:attr('data-skin', lib.ternary(args['skin'] == '', 'Standard '..args['champion'], args['skin'] or 'Standard '..args['champion']))
if args['champion'] then link:attr('data-character', args['champion']) end
if args['variant'] then link:attr('data-variant', args['variant']) end
if args['width'] and img ~= nil then img:addClass('icon-' .. args['width']) end
end
return link
end
function ImageLink.item(frame)
local args = lib.arguments(frame.args or frame)
if args['enchantment'] then
args['link'] = args['link'] or args['enchantment'] or ''
args['text'] = args['text'] or formatnil('%s (%s)', args['item'], args['enchantment']) or ''
args['image'] = args['image'] or FN.item{item = args['item'], enchantment = args['enchantment'], variant = args['variant']}
else
args['link'] = args['link'] or args['item'] or ''
args['text'] = args['text'] or args['item'] or ''
args['image'] = args['image'] or FN.item{item = args['item'], variant = args['variant']}
end
args['editlink'] = args['editlink'] or formatnil('Template:Item data/%s', args['item']) or ''
local link, img = ImageLink._createLink(args)
if args['notooltip'] == 'true' then
else
link:addClass('item-icon')
if args['item'] then link:attr('data-item', args['item']) end
if args['variant'] then link:attr('data-variant', args['variant']) end
if args['enchantment'] then link:attr('data-enchantment', args['enchantment']):addClass('enchantment-icon') end
if args['width'] and img ~= nil then img:addClass('icon-' .. args['width']) end
end
return link
end
function ImageLink.loading(frame)
local args = lib.arguments(frame.args or frame)
local _input = args['champion']
args['champion'] = lib.validateName(args['champion'])
args['link'] = args['link'] or args['champion'] or ''
args['text'] = args['text'] or _input or ''
args['image'] = args['image'] or FN.loading{_input, args['skin'], args['variant']}
args['border'] = args['border'] or 'false'
args['size'] = args['size'] or '110px'
args['selflink'] = args['selflink'] or mw.title.getCurrentTitle().rootText
local link, img = ImageLink._createLink(args)
link:addClass('skin-icon')
link:attr('data-skin', lib.ternary(args['skin'] == '', "Standard "..args['champion'], args['skin'] or "Standard "..args['champion']))
if args['champion'] then link:attr('data-character', args['champion']) end
if args['variant'] then link:attr('data-variant', args['variant']) end
if args['width'] and img ~= nil then img:addClass('icon-' .. args['width']) end
return link
end
function ImageLink.rune(frame)
local args = lib.arguments(frame.args or frame)
args['link'] = args['link'] or args['rune']
args['text'] = args['text'] or args['rune'] or ''
args['image'] = args['image'] or FN.rune{rune = args['rune'], variant = args['variant']}
args['editlink'] = args['editlink'] or formatnil('Template:Rune data/%s', args['rune']) or ''
args['border'] = args['border'] or 'false'
local link, img = ImageLink._createLink(args)
if args['notooltip'] == 'true' then
else
link:addClass('rune-icon')
if args['rune'] then link:attr('data-rune', args['rune']) end
if args['variant'] then link:attr('data-variant', args['variant']) end
if args['width'] and img ~= nil then img:addClass('icon-' .. args['width']) end
end
return link
end
function ImageLink.skin(frame)
local args = lib.arguments(frame.args or frame)
local _input = args['champion']
args['champion'] = lib.validateName(args['champion'])
local skinData = mw.loadData('Module:Skin/data')
local skinname = args['skin'] or "Standard "..args['champion']
if skinData[args['champion']] == nil then
return userError("''" .. args['champion'] .. "'' ist kein gültiger Championname" , "LuaError")
end
if skinData[args['champion']].skins[skinname] == nil then
return userError("Der Skin ''" .. skinname .. "'' für " .. args['champion'] .. " ist nicht in Modul:Skin/data hinterlegt" , "LuaError")
end
args['link'] = args['link'] or args['champion']..'#Kosmetisch~'..args['skin'] or ''
args['text'] = args['text'] or lib.ternary(skinname) or ''
if args['circle'] == 'true' then
args['image'] = args['image'] or FN.championcircle{_input, args['skin'], args['variant']}
args['border'] = args['border'] or 'false'
else
args['image'] = args['image'] or FN.championsquare{_input, ["variant"] = args['variant']}
end
args['editlink'] = args['editlink'] or formatnil('Template:Data %s', args['champion']) or ''
args['selflink'] = args['selflink'] or mw.title.getCurrentTitle().rootText
local link, img = ImageLink._createLink(args)
if args['loading'] == 'true' then
link:addClass('skinloading-icon')
else
link:addClass('skin-icon')
end
link:attr('data-skin', lib.ternary(args['skin'] == '', 'Standard '..args['champion'], args['skin'] or 'Standard '..args['champion']))
if args['champion'] then link:attr('data-character', args['champion']) end
if args['variant'] then link:attr('data-variant', args['variant']) end
if args['width'] and img ~= nil then img:addClass('icon-' .. args['width']) end
return link
end
function ImageLink.summonerspell(frame)
local args = lib.arguments(frame.args or frame)
local SPD = require('Module:Spell')
args['link'] = args['link'] or SPD.getlink{spell = args['spell']} or ""
args['text'] = args['text'] or args['spell'] or ''
args['image'] = args['image'] or FN.summonerspell{spell=args['spell'], variant=args['variant']}
args['editlink'] = args['editlink'] or 'Module:Spell/data' or ''
local link, img = ImageLink._createLink(args)
if args['notooltip'] == 'true' then
else
link:addClass('spell-icon')
if args['spell'] then link:attr('data-spell', args['spell']) end
if args['variant'] then link:attr('data-variant', args['variant']) end
if args['width'] and img ~= nil then img:addClass('icon-' .. args['width']) end
end
return link
end
function ImageLink.unit(frame)
local args = lib.arguments(frame.args or frame)
local UD = require('Module:Unit')
args['link'] = args['link'] or UD.getlink{unit = args['unit']}
args['text'] = args['text'] or args['unit'] or ''
args['image'] = args['image'] or UD.geticon{unit = args['unit'], variant = args['variant']}
args['editlink'] = args['editlink'] or 'Module:Unit/data' or ''
local link, img = ImageLink._createLink(args)
if args['notooltip'] == 'true' then
else
link:addClass('unit-icon')
if args['unit'] then link:attr('data-unit', args['unit']) end
if args['variant'] then link:attr('data-variant', args['variant']) end
if args['width'] and img ~= nil then img:addClass('icon-' .. args['width']) end
end
return link
end
function ImageLink.ward(frame)
local args = lib.arguments(frame.args or frame)
args['link'] = args['link'] or 'Augenskins'
args['text'] = args['text'] or args['ward'] .. '-Auge' or ''
args['image'] = args['image'] or FN.ward{ward=args['ward']}
args['size'] = args['size'] or 64
args['border'] = args['border'] or 'false'
local link, img = ImageLink._createLink(args)
link:addClass('ward-icon')
if args['width'] and img ~= nil then img:addClass('icon-' .. args['width']) end
return link
end
function ImageLink.basic(frame)
local args = lib.arguments(frame.args or frame)
local link = ImageLink._createLink(args) -- link, image, label
return link
end
function ImageLink._createLink(args)
-- define args.display (default: inline)
args['display'] = (({['inlineblock'] = 'inline-block'})[args['display']]) or args['display'] or 'inline'
-- define args.image (default: '')
args['image'] = args['image'] or ''
if args['image'] == '*none*' then args['image'] = '' end
if args['textonly'] == 'true' then args['image'] = '' end
-- define args.border (true or false; default: true)
args['border'] = args['border'] or true
if args['border'] == 'false' or args['border'] == '0' then args['border'] = false end
-- define args.edit (true or false; default: false)
args['edit'] = args['edit'] or false
if args['edit'] == 'true' or args['edit'] == '1' then args['edit'] = true end
-- define args.style (default: 'white-space:pre')
args['style'] = args['style'] or 'white-space:pre'
if args['style'] == '*none*' then args['style'] = nil end
-- define args.labelstyle (default: 'white-space:normal')
args['labelstyle'] = args['labelstyle'] or 'white-space:normal'
if args['labelstyle'] == '*none*' then args['labelstyle'] = nil end
-- define args.width, args.height (%%x%%px or %%x%% or %%px or %%; default: 20px)
local width, height
if(args['size']) then width, height = getSize(args['size']) end
args['size'] = args['size'] or 20
args['width'] = tonumber(mw.ustring.match(args['width'] or width or '', '%d*'))
args['height'] = tonumber(mw.ustring.match(args['height'] or height or '', '%d*'))
if(not args['height']) then args['width'] = args['width'] or args['size'] end
-- define args.selflink (default: articlename)
args['selflink'] = args['selflink'] or mw.title.getCurrentTitle().prefixedText
-- define args.link (default: '')
args['link'] = args['link'] or ''
if args['link'] == '*none*' then args['link'] = '' end
-- define args.possessive (default: '')
args['possessive'] = args['possessive'] or ''
if args['possessive'] == 'true' or args['possessive'] == '1' then args['possessive'] = true end
-- define args.text (default: '')
args['text'] = args['text'] or args['link'] or ''
if args['newline'] == 'true' then args['text'] = '<br>'..args['text'] end
if args['text'] == '*none*' then args['text'] = '' end
if args['possessive'] == true then
local s = mw.ustring.sub(args['text'], -1)
if s == 's' or s == 'x' or s == 'z' or s == 'ß' then
args['text'] = args['text'] .. '\''
else
args['text'] = args['text'] .. 's'
end
end
-- define args.alttext (default: '')
args['alttext'] = args['alttext'] or ''
-- define args.label (before or after; default: after)
args['label'] = (({['after'] = 'after', ['before'] = 'before'})[args['label']]) or 'after'
if args['image'] == '' then args['label'] = 'only' end
if args['text'] == '' then args['label'] = 'none' end
-- define args.labellink (true or false; default: true)
args['labellink'] = args['labellink'] or true
if args['labellink'] == 'false' or args['labellink'] == '0' then args['labellink'] = false end
--define args.data-param (specified or '')
args['data-param'] = args['data-param'] or ''
if args['data-param'] == '*none*' then args['data-param'] = nil end
-- define args.separator (default: ' ')
args['separator'] = args['separator'] or ' '
local tag = lib.ternary(args['display'] == 'inline', 'span', 'div')
local link = mw.html.create(tag):css('display', args['display']):addClass(args['display'] .. '-image')
if args['class'] then link:addClass(args['class']) end
if args['style'] then link:cssText(args['style']) end
if args['data-param'] then link:attr('data-param', args['data-param']) end
-- //img start
local img = mw.html.create(tag)
if args['image'] ~= '' then
img:css({position = 'relative', display = 'inline-block'})
local size = tostring(args['width'] or '') .. 'x' .. tostring(args['height'] or '') .. 'px'
if args['iconclass'] then img:addClass(args['iconclass']) end
if args['width'] then img:attr('data-width', tostring(args['width'])) end
if args['height'] then img:attr('data-height', tostring(args['height'])) end
if args['border'] == true then img:addClass('border') end
if args['iconstyle'] then img:cssText(args['iconstyle']) end
-- [[File:test.jpg|24px|border|link=test|testing]]
img:wikitext(mw.ustring.format('[[File:%s%s%s|link=%s%s]]',
args['image'],
lib.ternary(size == 'px', '', '|'..size),
lib.ternary(args['border'], '|border', ''),
lib.ternary(args['link'] == args['selflink'], '', args['link']),
lib.ternary(args['alttext'] == '',
lib.ternary(args['text'] == '', '', '|' .. args['text']),
'|' .. args['alttext']
)
))
if args['image2'] then
img:wikitext(mw.ustring.format('[[File:%s%s%s|link=%s%s]]',
args['image2'],
lib.ternary(size == 'px', '', '|'..size),
lib.ternary(args['border'], '|border', ''),
lib.ternary(args['link'] == args['selflink'], '', args['link']),
lib.ternary(args['alttext'] == '',
lib.ternary(args['text'] == '', '', '|' .. args['text']),
'|' .. args['alttext']
)
))
end
if args['image3'] then
img:wikitext(mw.ustring.format('[[File:%s%s%s|link=%s%s]]',
args['image3'],
lib.ternary(size == 'px', '', '|'..size),
lib.ternary(args['border'], '|border', ''),
lib.ternary(args['link'] == args['selflink'], '', args['link']),
lib.ternary(args['alttext'] == '',
lib.ternary(args['text'] == '', '', '|' .. args['text']),
'|' .. args['alttext']
)
))
end
-- //bottom right number start
if args['number'] and args['number'] ~= '' then
local number = mw.html.create('span')
local t = {
['position'] = 'absolute',
['font-size'] = string.gsub(math.min(args['width'] or 1e309, args['height'] or 1e309), 'px', '')/2 ..'px',
['line-height'] = '1em',
['bottom'] = '0.08em',
['right'] = '0.1em',
['font-weight'] = 'bold',
['pointer-events'] = 'none',
['color'] = lib.ternary(args['blacknum'] == 'true', '#111', '#EEE'),
['text-shadow'] = lib.ternary(args['blacknum'] == 'true', '-1px 0 1px #fff, 0 1px 1px #fff, 1px 0 1px #fff, 0 -1px 1px #fff', '-1px 0 1px #000, 0 1px 1px #000, 1px 0 1px #000, 0 -1px 1px #000')
}
number:css(t)
number:wikitext(args['number'])
number:done()
img:node(number)
end
-- //bottom right number end
img:done()
else
img = nil
end
-- //img end
-- //label start
local label = mw.html.create(tag)
if args['text'] ~= '' then
link:addClass('label-' .. args['label'])
if args['labelclass'] then label:addClass(args['labelclass']) end
if args['labelstyle'] then label:cssText(args['labelstyle']) end
if args['link'] == '' or args['labellink'] == false then
label:wikitext(args['text'])
elseif args['selflink'] == args['link'] then
label:wikitext('<strong class="selflink">' .. args['text'] .. '</strong>')
elseif args['text'] == args['link'] then
label:wikitext(formatnil('[[%s]]', args['text']))
else
label:wikitext(formatnil('[[%s|%s]]', args['link'], args['text']))
end
if args['edit'] == true and args['editlink'] ~= nil then
label:wikitext(' <sup>[' .. tostring(mw.uri.fullUrl(args['editlink'], 'action=edit')) .. ' e]</sup>')
end
label:done()
else
label = nil
end
-- //label end
if args['label'] == 'before' then
if label then link:node(label) end
if args['separator'] and img and label then link:wikitext(args['separator']) end
if img then link:node(img) end
else
if img then link:node(img) end
if args['separator'] and img and label then link:wikitext(args['separator']) end
if label then link:node(label) end
end
return link, img, label
end
return ImageLink
-- </pre>
-- [[Category:Module]]