Module:Ability ID

local p = {} local cargo = mw.ext.cargo local aicon = require( 'Module:Ability icon' )._main local caching = require( 'Module:Cache' ).auto local getArgs = require( 'Module:Arguments' ).getArgs

local default = { icon = 'File:Unknown icon.png', icon_size = '16px', } local i18n = { error = { missing_input = 'Hero or ability parameter missing', no_cargo_data = 'Could not find Cargo data for "%s"', }, old_abilities_page = 'Old Abilities', }

function p.main(frame) local args = getArgs(frame, {   wrappers = {      'Template:Ability ID'      }  }) return caching(p._main, args, 'abilityid') end

local function cargo_query( page, ability ) return cargo.query( 'abilities', 'image, title, type', { where='_pageName LIKE "%'..page..'" AND title="'..ability..'"', groupBy='source, title' } )[1] end

function p._main( args ) assert(args and args[1] and args[2], i18n.error.missing_input)

-- Try to get the ability cargo data from the page. local page = args[2] local cargo_output = cargo_query( page, args[1] ) if cargo_output == nil then -- If no data is found look on the /Old Abilities subpage. page = page .. '/' .. i18n.old_abilities_page cargo_output = cargo_query( page, args[1] )

assert( cargo_output, string.format(i18n.error.no_cargo_data, args[1]) ) end

local icon = aicon({source = args[2], name = args[1]}, cargo_output)

return string.format( ' %s|link=%s|class=noprint %s ', icon, (args[3] or default.icon_size), page, page, args[1], (args['text'] or cargo_output['title']) ) end

return p