Module:Ref

-- This module implements ref templates. -- See for the base template and a documentation. local ref = {} local getArgs = require('Dev:Arguments').getArgs local data = mw.loadData('Module:Codename')

local function authorref(author, date, title, section) if section then return string.format('%s (%s). %s in %s.', author, date, section, title) else return string.format('%s (%s). %s.', author, date, title) end end

local function gameref(game) game = string.lower(game) local dev = data[game]['developer'] local releaseyear = string.sub(data[game]['release'], 1, 4) local gamelink = data[game]['link'] local platform = data[game]['platform'] return string.format("%s (%s). %s. %s. Sony Interactive Entertainment.", dev, releaseyear, gamelink, platform) end

local function basicref(title, date) return string.format('%s. %s.', title, date) end

local function linkformat(linktype, link, title) if linktype == 'url' then return string.format('[%s %s]', link, title) elseif linktype == 'wiki' then return string.format('[' .. '[' .. '%s|%s]]', link, title) end end

local function platformformat(platform) if platform == 'ps2' then return 'PlayStation 2' elseif platform == 'ps3' then return 'PlayStation 3' elseif platform == 'ps4' then return 'PlayStation 4' elseif platform == 'psp' then return 'PlayStation Portable' elseif platform == 'psvita' then return 'PlayStation Vita' else return platform end end

-- Produces the ref template. function ref.main(frame) local args = getArgs(frame) local title = args['title'] or '' if args['wikilink'] then title = linkformat('wiki', args['wikilink'], args['title']) elseif args['url'] then title = linkformat('url', args['url'], args['title']) end if args['noitalictitle'] then title = title else title = string.format("%s", title) end

local refoutput = '' if args['author'] then refoutput = authorref(args['author'], args['date'], title, args['section']) elseif args['game'] then refoutput = gameref(args['game']) else refoutput = basicref(title, args['date']) end local extra = '' if args['additional-authors'] then extra = extra .. string.format('%s. ', args['additional-authors']) end if args['publisher'] then local publisher = '' if args['publisher'] == 'sony' then publisher = 'Sony Interactive Entertainment' else publisher = args['publisher'] end extra = extra .. string.format('%s. ', publisher) end if args['platform'] then extra = extra .. platformformat(args['platform']) .. '. '   end

if args['isbn'] then extra = extra .. string.format('ISBN %s. ', args['isbn'], args['isbn']) end

if args['access-date'] then extra = extra .. string.format('Accessed %s. ', args['access-date']) end

if args['archive-url'] then extra = extra .. string.format('[%s Archied] from the original on %s. ', args['archive-url'], args['archive-date']) end refoutput = refoutput .. ' ' .. extra if args['id'] then refoutput = string.format(' %s ', args['id'], refoutput) end return frame:preprocess(refoutput) end

return ref