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', orderBy='game' } )[1] end

function p._main( args ) assert(args and args[1], i18n.error.missing_input) local arg_name = '' local arg_source = '' if args[2] ~= nil then arg_name = args[1] arg_source = args[2] end if args[2] == nil then local t={} for str in string.gmatch(args[1], "([^&]+)") do     table.insert(t, str) end arg_name = t[1] arg_source = t[2] assert(args[2], i18n.error.missing_input) end

-- Try to get the ability cargo data from the page. local page = arg_source local cargo_output = cargo_query( page, arg_name ) 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, arg_name )

assert( cargo_output, string.format(i18n.error.no_cargo_data, arg_name) ) end

local icon = aicon({source = arg_source, name = arg_name}, cargo_output)

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

return p