Module:Common
local p = {}
function p.getRedirectContent( pageTitle )
if pageTitle.isRedirect then
local redirectPageName = pageTitle:getContent():match( "%[%[(.-)%]%]" )
return p.getContent( redirectPageName, pageTitle.nsText, true )
else
return pageTitle:getContent( )
end
end
function p.getContent( pageName, namespace, fromRedirect )
--Create new title object with given page name and namespace (EXPENSIVE)
local titleObj = mw.title.new( pageName, namespace )
--Return page content if the page exists otherwise nil if titleObj and titleObj.exists then if not fromRedirect then return p.getRedirectContent( titleObj ) else return titleObj:getContent( ) end else return nil end
--return titleObj.exists and titleObj:getContent() or nil
end
function p.getCharacterStatus( characterName )
local content = p.getContent(characterName)
if content then content = content:gsub( "%s+", "" ) :gsub( "_", "" ) :lower() :gsub( "(.+)", "" ) else return "Unknown" end
if not content:find( "({{%w-[-_]-infobox.-}})" ) then if not content:find( "({{%w-[-_]-2.0character.-}})" ) then return "Unknown" else content = content:sub( content:find( "({{%w-[-_]-2.0character.-}})" ), -1 ) :match('%b{}') end else content = content:sub( content:find( "({{%w-[-_]-infobox.-}})" ), -1 ) :match('%b{}') end
--content = content:sub( content:find( "({{%w-[-_]-infobox.-}})" ), -1 ) -- :match('%b{}')
local matches = {} local validStatuses = {"active", "inactive", "banned", "deceased"}
for s in content:gmatch("|status=(.-)[|}]") do for _, status in pairs(validStatuses) do if s == status then table.insert(matches, s) break end end end
if matches[#matches] == "banned" then return "Inactive" elseif matches[#matches] then return mw.language.new("en"):ucfirst(matches[#matches]) else return "Active" end end
function p.getNamedArgs( argNames, frameArgs, templateArgs )
local argVals = {}
local argCount = 1
for i=1, #argNames do if frameArgs[i] ~= nil and frameArgs[i] ~= then argVals[argNames[i][1]:lower()] = mw.text.trim(frameArgs[i])
for _, a in ipairs(argNames[i]) do if templateArgs[a] then argCount = argCount+1 break end end end end
return argCount, argVals end
function p.boxShadow( val ) if val then return '-o-box-shadow: ' .. val .. '; ' .. '-ms-box-shadow: ' .. val .. '; ' .. '-moz-box-shadow: ' .. val .. '; ' .. '-webkit-box-shadow: ' .. val .. '; ' .. 'box-shadow: ' .. val .. '; ' else return end end
return p