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 lang = mw.language.getContentLanguage local function authorref(author, date, title, section, authorid, platform) local authoroutput = author if authorid and platform == 'youtube' then authoroutput = '[https://www.youtube.com/channel/' .. authorid .. ' ' .. author .. ']'   elseif authorid and platform == 'twitter' then authoroutput = '[https://twitter.com/' .. authorid .. ' ' .. author .. ']'   end if section then return string.format('%s (%s). %s in %s.', authoroutput, date, section, title) else return string.format('%s (%s). %s.', authoroutput, date, title) end end local function gameref(game) game = string.lower(game) assert(data[game]['media'] == 'game', "Did not reference a game") local dev = data[game]['developer'] local releasedate = lang:formatDate('Y', data[game]['release']) local page = data[game]['pagename'] local title = data[game]['title'] local platform = data[game]['platform'] return string.format("%s (%s). " .. "[" .. "[" .. "%s|%s]]. PUBLISHER.", dev, releasedate, page, title, platform) end local function guideref(game) game = string.lower(game) assert(data[game]['guide']['title'], "Cannot find a guide for this release") local author = data[game]['guide']['author'] local releasedate = lang:formatDate('F Y', data[game]['guide']['release']) local title = data[game]['guide']['title'] local publisher = data[game]['guide']['publisher'] local isbn = data[game]['guide']['isbn'] return string.format("%s (%s). %s. %s. ISBN %s", author, releasedate, title, publisher, isbn, isbn) end local function movieref(movie) movie = string.lower(movie) assert(data[movie]['media'] == 'movie', "Did not reference a movie") local director = data[movie]['director'] local releasedate = lang:formatDate('F Y', data[movie]['release']) local title = data[movie]['title'] local studio = data[movie]['studio'] return string.format("%s (%s). %s. %s.", director, releasedate, title, studio) end local function bookref(book) book = string.lower(book) assert(data[book]['media'] == 'book' or data[book]['media'] == 'comic', "Did not reference a book") local author = data[book]['author'] local releasedate = lang:formatDate('F Y', data[book]['release']) local title = data[book]['title'] local publisher = data[book]['publisher'] local isbn = data[book]['isbn'] if data[book]['series'] then return string.format("%s (%s). %s. %s in %s. ISBN %s", author, releasedate, data[book]['series'], title, publisher, isbn, isbn) else return string.format("%s (%s). %s. %s. ISBN %s", author, releasedate, title, publisher, isbn, isbn) end end local function basicref(title, date) return string.format('%s. %s.', title, date) end local function urllinkformat(link, title, platform, publisherlink) if platform == 'youtube' then link = 'https://www.youtube.com/watch?v=' .. link elseif platform == 'twitter' then link = 'https://twitter.com/' .. publisherlink .. '/status/' .. link end return string.format('[%s %s]', link, title) end local function archiveformat(url, accessdate, archiveurl, archivedate) local link = '' if archiveurl then link = archiveurl else link = 'https://web.archive.org/web/' .. url end if archivedate then return string.format('Accessed %s. [%s Archived] from the original at %s. ', archivedate, link, acessdate) else return string.format('[%s Archived] from the original at %s. ', link, accessdate) end end local function publisherformat(publisher, publisherlink, platform) if publisherlink then publisher = '[' .. publisherlink .. ' ' .. publisher .. ']'   elseif publisher == 'sony' then publisher = 'Sony Interactive Entertainment' else publisher = publisher end return publisher .. '. ' end

local function platformformat(platform) if platform == 'youtube' then return 'YouTube' elseif platform == 'twitter' then return 'Twitter' else return platform end end -- Produces the ref template. function ref.main(frame) local args = getArgs(frame) local title = args['title'] or '' if args['archive-url'] and args['brokenlink'] then title = string.format('[%s %s]', args['archive-url'], args['title']) elseif args['url'] then title = string.format('[%s %s]', args['url'], args['title']) elseif args['youtube-id'] then title = string.format('%s', args['youtube-id'], args['title']) elseif args['tweet-id'] and args['author-id'] then title = string.format('%s', args['tweet-id'], args['author-id'], 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'], args['author-id'], args['platform']) elseif args['game'] then refoutput = gameref(args['game']) elseif args['guide'] then refoutput = guideref(args['guide']) elseif args['movie'] then refoutput = movieref(args['movie']) elseif args['book'] then refoutput = bookref(args['book']) 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 extra = extra .. publisherformat(args['publisher'], args['publisher-link'], args['platform']) 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['url'] and not args['broken-link'] then extra = extra .. archiveformat(args['url'], args['access-date'], args['archive-url'], args['archive-date']) elseif args['broken-link'] then extra = extra .. string.format('Archived from the [%s original] on %s. ', args['url'], args['acceess-date'] or 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

--