@DeletedUser41170185 (talk | contribs) (pcall) |
@DeletedUser41170185 (talk | contribs) m (Cleanup) |
||
Line 27: | Line 27: | ||
function p.ifexist( file ) |
function p.ifexist( file ) |
||
− | return mw.title.new( |
+ | return mw.title.new( file ).fileExists |
end |
end |
||
Revision as of 19:29, 21 December 2017
▶️
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
- Module:Error
local cargo = mw.ext.cargo
local error = require( 'Module:Error' ).main
local p = {}
function p.main( frame )
local args = frame:getParent().args
return p._main( args )
end
function p._main( args )
if args[1] then
local size = args[2] or '40px'
local icon = 'File:Team icon Default.png'
if pcall( p.cargo, args[1] ) then
icon = 'File:' .. p.cargo( args[1] )
if icon == '' then icon = 'File:Team icon Default.png' end -- On existing pages with an empty icon parameter it returns '' instead of nil
elseif pcall( p.ifexist, 'File:Team icon ' .. args[1] .. '.png' ) then
icon = 'File:Team icon ' .. args[1] .. '.png'
end
return '[[' .. icon .. '|' .. size .. '|link=' .. args[1] .. ']]'
else
return error( 'Check your input.' )
end
end
function p.ifexist( file )
return mw.title.new( file ).fileExists
end
function p.cargo( team )
return cargo.query( 'professional_teams', 'CONCAT(icon)', { where='_pageName="' .. team .. '"', groupBy='_pageID' } )[1]['CONCAT(icon)']
end
return p