Dota 2 Вики
Регистрация
Advertisement

Документация для Модуль:Ability ID Перейти к коду ↴ [ править | очистить ]

Reality Rift icon
▶️ Planeshift.
Документацию для этого шаблона или модуля можно найти в Template:Ability ID.
Вы можете быть перенаправлены на другой язык вики, если перевод недоступен.


Зависимости

local p = {}
local cargo = mw.ext.cargo
local aicon = require( 'Модуль:Ability icon' )._main
local caching = require( 'Модуль:Cache' ).auto
local getArgs = require( 'Модуль:Arguments' ).getArgs

local default = {
  icon = 'Файл:Unknown icon.png',
  icon_size = '18px',
}

local i18n = {
  error = {
    missing_input = 'Отсутствует параметр героя или способности',
    no_cargo_data = 'Не найдено данных Cargo для "%s"',
  },
  old_abilities_page = 'Старые способности',
}


function p.main(frame)
  local args = getArgs(frame, {
    wrappers = {
      'Шаблон: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_source = t[1]
    arg_name = t[2]
    assert(arg_source and arg_name, 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( '<span class="image-link">[[%s|%s|link=%s|alt=|class=noprint]] [[%s#%s|%s]]</span>', icon, (args[3] or default.icon_size), page, page, arg_name, (args['text'] or cargo_output['title']) )
end


return p
Advertisement