Dota 2 Wiki
m (variable names ...)
mNo edit summary
 
(32 intermediate revisions by the same user not shown)
Line 1: Line 1:
local cargo = mw.ext.cargo
 
local error = require( 'Module:Error' ).main
 
 
local p = {}
 
local p = {}
 
local cargo = mw.ext.cargo
  +
local fileExists = require('Module:FileExists')
 
local getArgs = require('Module:Arguments').getArgs
  +
local mFileLink = require('Module:File link')._main
   
function p.main( frame )
 
local args = frame:getParent().args
 
return p._main( args )
 
end
 
   
function p._main( args )
+
function p.main(frame)
  +
local args = getArgs(frame, {
local size = args[2] or '40px'
 
  +
wrappers = {
local icon = 'File:Team icon Default.png'
 
  +
'Template:Team icon'
 
  +
}
if pcall( p.cargo, args[1] ) then
 
  +
})
icon = p.cargo( args[1] )
 
 
return p._main(args)
elseif mw.title.new( 'File:Team icon ' .. args[1] .. '.png' ).fileExists == true then
 
icon = 'File:Team icon ' .. args[1] .. '.png'
 
end
 
 
return '[[' .. icon .. '|' .. size .. '|link=' .. args[1] .. ']]'
 
 
end
 
end
   
function p.cargo( team )
+
function p._main(args)
  +
assert(args[1], 'Check your input')
return mw.logObject( cargo.query( 'professional_teams', 'CONCAT(icon)', { where='_pageName="' .. team .. '"', groupBy='_pageID' } )[1]['CONCAT(icon)'] )
 
  +
  +
local name = args[1]
 
local size = args[2] or '40px'
 
local icon = 'Team icon Default.png'
  +
  +
-- Attempt to get the data through Cargo.
  +
-- _pageName matches are prioritized over matches in the names table.
  +
-- If multiple teams have the same name in their names table the first one is used.
 
local cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='_pageName="' .. args[1] .. '"', groupBy='_pageID' } )[1]
  +
if not cargo_output then
  +
cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='names HOLDS "' .. args[1] .. '"', groupBy='_pageID' } )[1]
 
end
  +
  +
if cargo_output and cargo_output['icon'] ~= '' then
  +
name = cargo_output['name']
  +
icon = cargo_output['icon']
  +
else
 
if fileExists('File:Team icon ' .. args[1] .. '.png') then
 
icon = 'Team icon ' .. args[1] .. '.png'
  +
end
 
end
  +
  +
return mFileLink{
  +
file = icon,
  +
size = size,
  +
link = args[1],
  +
alt = name
  +
}
 
end
 
end
  +
   
 
return p
 
return p

Latest revision as of 20:36, 17 May 2018

Documentation for Module:Team icon Jump to code ↴ [ edit | purge ]

Reality Rift icon
▶️ Planeshift.
The documentation for this module can be found at Template:Team icon.
You may be forwarded to another wiki language, in case a translation is not available.


Dependencies

local p = {}
local cargo = mw.ext.cargo
local fileExists = require('Module:FileExists')
local getArgs = require('Module:Arguments').getArgs
local mFileLink = require('Module:File link')._main


function p.main(frame)
  local args = getArgs(frame, {
    wrappers = {
      'Template:Team icon'
    }
  })
  return p._main(args)
end

function p._main(args)
  assert(args[1], 'Check your input')
  
  local name = args[1]
  local size = args[2] or '40px'
  local icon = 'Team icon Default.png'
    
  -- Attempt to get the data through Cargo.
  -- _pageName matches are prioritized over matches in the names table.
  -- If multiple teams have the same name in their names table the first one is used.
  local cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='_pageName="' .. args[1] .. '"', groupBy='_pageID' } )[1]
  if not cargo_output then
    cargo_output = cargo.query( 'professional_teams', 'icon, name', { where='names HOLDS "' .. args[1] .. '"', groupBy='_pageID' } )[1]
  end

  if cargo_output and cargo_output['icon'] ~= '' then
    name = cargo_output['name']
    icon = cargo_output['icon']
  else
    if fileExists('File:Team icon ' .. args[1] .. '.png') then
      icon = 'Team icon ' .. args[1] .. '.png'
    end
  end
  
  return mFileLink{
    file = icon,
    size = size,
    link = args[1],
    alt = name
  }
end


return p