Module:Skill link: Difference between revisions
		
		
		
		Jump to navigation
		Jump to search
		
>OmegaK2  (Created page with "-- -- Module for skill linking --  local m_util = require('Module:Util') local getArgs = require('Module:Arguments').getArgs  local p = {}  -- --------------------------------...")  | 
				>OmegaK2  m (Show screenshot if set)  | 
				||
| Line 13: | Line 13: | ||
local i18n = {  | local i18n = {  | ||
    errors = {  | |||
        missing_id_parameter = 'Id parameter must be specified.',  | |||
    },  | |||
}  | }  | ||
| Line 33: | Line 36: | ||
     if tpl_args.id == nil then  |      if tpl_args.id == nil then  | ||
         error(  |          error(i18n.errors.missing_id_parameter)  | ||
     end  |      end  | ||
     local results = m_util.cargo.query(  |      local results = m_util.cargo.query(  | ||
         {'skill'},  |          {'skill'},  | ||
         {'skill.html'},  |          {  | ||
            'skill.html',  | |||
            'skill.skill_screenshot',  | |||
        },  | |||
         {  |          {  | ||
             where=string.format('skill.skill_id = "%s"', tpl_args.id),  |              where=string.format('skill.skill_id = "%s"', tpl_args.id),  | ||
| Line 49: | Line 55: | ||
     container:attr('class', 'skill-box-page-container')  |      container:attr('class', 'skill-box-page-container')  | ||
     container:wikitext(results['skill.html'])  |      container:wikitext(results['skill.html'])  | ||
    if results['skill.skill_screenshot'] then  | |||
        container:wikitext(results['skill.skill_screenshot'])  | |||
    end  | |||
     return tostring(container)  |      return tostring(container)  | ||
Revision as of 22:53, 1 April 2018
Module for creating links to skills via cargo.
Implemented templates
- {{Skill link}}
 - {{Query skill infobox}}
 
The above documentation is transcluded from Module:Skill link/doc. 
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
--
-- Module for skill linking
--
local m_util = require('Module:Util')
local getArgs = require('Module:Arguments').getArgs
local p = {}
-- ----------------------------------------------------------------------------
-- Strings
-- ----------------------------------------------------------------------------
local i18n = {
    errors = {
        missing_id_parameter = 'Id parameter must be specified.',
    },
}
-- ----------------------------------------------------------------------------
-- Helper functions and globals
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- Page functions
-- ----------------------------------------------------------------------------
local p = {}
function p.skill_infobox_link(frame)
    -- Get args
    tpl_args = getArgs(frame, {
        parentFirst = true
    })
    frame = m_util.misc.get_frame(frame)
    
    if tpl_args.id == nil then
        error(i18n.errors.missing_id_parameter)
    end
    
    local results = m_util.cargo.query(
        {'skill'},
        {
            'skill.html',
            'skill.skill_screenshot',
        },
        {
            where=string.format('skill.skill_id = "%s"', tpl_args.id),
            limit=1,
        }
    )
    results = results[1]
    
    local container = mw.html.create('span')
    container:attr('class', 'skill-box-page-container')
    container:wikitext(results['skill.html'])
    if results['skill.skill_screenshot'] then
        container:wikitext(results['skill.skill_screenshot'])
    end
    
    return tostring(container)
end
-- ----------------------------------------------------------------------------
-- End
-- ----------------------------------------------------------------------------
return p