RuneScape Wiki
Advertisement

Documentation for this module may be created at Module:References/doc

--<pre>

local p = {} --all template entrance points here
local r = {} --reference formatters here to not expose them to #invoke, and to not clutter p

local onmain = require('Module:Mainonly').on_main
local tag = require('Module:Reftag')
local paramtest = require('Module:Paramtest')
local hc = paramtest.has_content
local dt = paramtest.default_to
local yn = require('Module:Yesno')
local postbags = mw.loadData('Module:CitePostbag/data')

--create the ref tag to be returned
local function reftag(frame, reftype)
    local args = frame:getParent().args
    local s = ''
    local opts = {}
    if args.name then
        opts.name = args.name
    end
    if args.group then
        opts.group = args.group
    end
    
    local ref, cat = r[reftype](args)
    opts.text = ref
    
    --return frame:extensionTag({name = 'ref', content = reference, args = opts})
    return tag(opts) .. cat
end

local function plainref(frame, reftype)
    local ref, cat = r[reftype](frame:getParent().args)
    return ref .. cat
end

------------ Helper Templates -----------------

--[==[
Template:NamedRef
--]==]
p.namedref = function(frame)
    local args = frame:getParent().args
    local opts = {}
    opts.name = args.name
    if args.group then
        opts.group = args.group
    end
    opts.selfClosing = true
    return tag(opts)
end


--[==[
Template:Reflist
--]==]
p.reflist = function(frame)
    local args = frame:getParent().args
    local div = mw.html.create('div')
    div :addClass('references-small')
        :wikitext(frame:preprocess('<references />'))
    if args.quotes then
        div:addClass('hideQuotes')
    end
    if args.colwidth then
        div :css({  ['-moz-column-width'] = args.colwidth,
                    ['-webkit-column-width'] = args.colwidth,
                    ['column-width'] = args.colwidth
                })
    elseif args[1] then
        div :css({  ['-moz-column-count'] = args[1],
                    ['-webkit-column-count'] = args[1],
                    ['column-count'] = args[1]
                })
    end
    
    return div
end

------------RuneScape Citation templates--------------

--[==[
Template:CiteDevBlog and Template:PlainCiteDevBlog
--]==]
p.devblogref = function(frame)
    return reftag(frame, 'devblog')
end

p.devblogplain = function(frame)
    return plainref(frame, 'devblog')
end

r.devblog = function(a)
    local ref
    local c = ''
    ref = dt(a.author, 'Jagex') --author, defaults to Jagex
    ref = ref .. '. '
    if hc(a.url) then --url, if present makes a link
        ref = ref .. '[' .. a.url
        if hc(a.title) then
            ref = ref .. ' "' .. a.title .. '."'--if title not present leave as link
        end
        ref = ref .. ']'
    else
        if hc(a.title) then
            ref = ref .. '"' .. a.title .. '."'
        end
    end
    ref = ref .. ' '
    if hc(a.blogdate) then
        ref = ref .. a.blogdate .. '.'
    end
    ref = ref .. " Developers' Blogs. "
    ref = ref .. (a.notes or '')
    
    if onmain() and not (hc(a.author) and hc(a.url) and hc(a.title) and hc(a.blogdate)) then --validation, required params are author, url, title and blogdate (mainonly)
        c = '[[Category:Incomplete References]]'
    end
    return ref, c
end


--[==[
Template:CiteDevDiary and Template:PlainCiteDevDiary
--]==]
p.devdiaryref = function(frame)
    return reftag(frame, 'devdiary')
end

p.devdiaryplain = function(frame)
    return plainref(frame, 'devdiary')
end

r.devdiary = function(a)
    local ref
    local c = ''
    ref = dt(a.author, 'Jagex') --author, defaults to Jagex
    ref = ref .. '. '
    if hc(a.url) then --url, if present makes a link
        ref = ref .. '[' .. a.url
        if hc(a.title) then
            ref = ref .. ' "' .. a.title .. '."'--if title not present leave as link
        end
        ref = ref .. ']'
    else
        if hc(a.title) then
            ref = ref .. '"' .. a.title .. '."'
        end
    end
    ref = ref .. ' '
    if hc(a.diarydate) then
        ref = ref .. a.diarydate .. '.'
    end
    ref = ref .. ' Development Diaries. '
    ref = ref .. (a.notes or '')
    
    if onmain() and not (hc(a.author) and hc(a.url) and hc(a.title) and hc(a.diarydate)) then
        c = '[[Category:Incomplete References]]'
    end
    return ref, c
end


--[==[
Template:CiteForum and Template:PlainCiteForum
--]==]
p.forumref = function(frame)
    return reftag(frame, 'forum')
end

p.forumplain = function(frame)
    return plainref(frame, 'forum')
end

r.forum = function(a)
    local ref
    local c = ''
    ref = dt(a.author, 'Jagex') --author, defaults to Jagex
    ref = ref .. '. '
    if hc(a.url) then --url, if present makes a link
        ref = ref .. '[' .. a.url
        if hc(a.title) then
            ref = ref .. ' "' .. a.title .. '."'--if title not present leave as link
        end
        ref = ref .. ']'
    else
        if hc(a.title) then
            ref = ref .. '"' .. a.title .. '."'
        end
    end
    ref = ref .. ' '
    if hc(a.postdate) then
        ref = ref .. a.postdate .. '.'
    end
    ref = ref .. " ''" .. dt(a.forum, 'RuneScape') .. "'' Forums. "
    ref = ref .. (a.notes or '')
    
    if onmain() then
        if not (hc(a.author) and hc(a.url) and hc(a.title) and hc(a.postdate)) then
            c = c .. '[[Category:Incomplete References]]'
        end
        if a.url and (string.find(a.url, 'forum.runescape.com/', 1, true) or string.find(a.url, 'services.runescape.com/m=forum/', 1, true)) then
            c = c .. '[[Category:Unarchived forum references]]'
        end
    end
    return ref, c
end


--[==[
Template:CiteGodLetter and Template:PlainCiteGodLetter
--]==]
p.godletterref = function(frame)
    return reftag(frame, 'godletter')
end

p.godletterplain = function(frame)
    return plainref(frame, 'godletter')
end

r.godletter = function(a)
    local ref
    local c = ''
    ref = 'Jagex. '
    
    local str = ''
    if hc(a.issue) then
        str = str .. 'God Letter ' .. a.issue
        if hc(a.title) then
            str = str .. ' - ' .. a.title
        end
    else
        str = str .. (a.title or '')
    end
    if hc(a.letter) then
        str = str .. ', ' .. a.letter
    end
    if str ~= '' then
        str = '"' .. str .. '."'
    end
    
    
    if hc(a.url) then --url, if present makes a link
        ref = ref .. '[' .. a.url
        if str ~= '' then
            ref = ref .. ' ' .. str--if title not present leave as link
        end
        ref = ref .. ']'
    else
        ref = ref .. str
    end
    ref = ref .. " ''RuneScape'' god letters. "
    ref = ref .. (a.notes or '')
    
    if onmain() and not (hc(a.url) and hc(a.title) and hc(a.issue)) then
        c = c .. '[[Category:Incomplete References]]'
    end
    return ref, c
end


--[==[
Template:CiteLore and Template:PlainCiteLore
--]==]
p.loreref = function(frame)
    return reftag(frame, 'lore')
end

p.loreplain = function(frame)
    return plainref(frame, 'lore')
end

r.lore = function(a)
    local ref
    local c = ''
    ref = 'Jagex. '
    
    local str = ''
    if hc(a.title) then
        str = str .. a.title
        if hc(a.sectitle) then
            str = str .. ', ' .. a.sectitle
        end
    else
        str = str .. (a.sectitle or '')
    end
    if str ~= '' then
        str = '"' .. str .. '."'
    end
    
    
    if hc(a.url) then --url, if present makes a link
        ref = ref .. '[' .. a.url
        if str ~= '' then
            ref = ref .. ' ' .. str--if title not present leave as link
        end
        ref = ref .. ']'
    else
        ref = ref .. str
    end
    ref = ref .. " ''RuneScape'' Lores and Histories. "
    ref = ref .. (a.notes or '')
    
    if onmain() and not (hc(a.url) and hc(a.title) and hc(a.sectitle)) then
        c = c .. '[[Category:Incomplete References]]'
    end
    return ref, c
end


--[==[
Template:CiteNews and Template:PlainCiteNews
--]==]
p.newsref = function(frame)
    return reftag(frame, 'news')
end

p.newsplain = function(frame)
    return plainref(frame, 'news')
end

r.news = function(a)
    local ref
    local c = ''
    ref = a.author or 'Jagex'
    ref = ref .. '. '
    
    if hc(a.url) then --url, if present makes a link
        ref = ref .. '[' .. a.url
        if hc(a.title) then
            ref = ref .. ' "' .. a.title .. '."'--if title not present leave as link
        end
        ref = ref .. ']'
    else
        if hc(a.title) then
            ref = ref .. '"' .. a.title .. '."'
        end
    end
    ref = ref .. ' '
    if hc(a.newsdate) then
        ref = ref .. a.newsdate .. '.'
    end
    ref = ref .. " ''RuneScape'' News. "
    ref = ref .. (a.notes or '')
    
    if onmain() and not (hc(a.url) and hc(a.title) and hc(a.newsdate)) then
        c = c .. '[[Category:Incomplete References]]'
    end
    return ref, c
end


--[==[
Template:CiteNPC and Template:PlainCiteNPC
--]==]
p.npcref = function(frame)
    return reftag(frame, 'npc')
end

p.npcplain = function(frame)
    return plainref(frame, 'npc')
end

r.npc = function(a)
    local ref = ''
    local c = ''
    if hc(a.npc) then
        ref = ref .. '[[' .. a.npc .. ']], '
    end
    if hc(a.loc) then
        ref = ref .. '"[[' .. a.loc .. ']],"'
    end
    ref = ref .. "''RuneScape''. "
    
    if hc(a.quote) then
        local span =    mw.html.create('span')
                            :addClass('refhide')
                            :wikitext('"' .. a.quote .. '" ')
        ref = ref .. tostring(span)
    end
    
    ref = ref .. (a.notes or '')
    
    if onmain() and not (hc(a.npc) and hc(a.quote)) then
        c = c .. '[[Category:Incomplete References]]'
    end
    return ref, c
end


--[==[
Template:CitePoll and Template:PlainCitePoll
--]==]
p.pollref = function(frame)
    return reftag(frame, 'poll')
end

p.pollplain = function(frame)
    return plainref(frame, 'poll')
end

r.poll = function(a)
    local ref = 'Jagex. '
    local c = ''
    
    local str = ''
    if hc(a.poll) then
        str = str .. '"' .. a.poll .. '"'
        if hc(a.question) and string.lower(a.question) ~= 'no' then
            str = str .. ', Question ' .. a.question
        end
    elseif hc(a.question) and string.lower(a.question) ~= 'no' then
        str = str .. 'Question ' .. a.question
    end
    if str ~= '' then
        str = str .. '.'
    end
    
    if hc(a.url) then --url, if present makes a link
        ref = ref .. '[' .. a.url
        if str ~= '' then
            ref = ref .. ' ' .. str--if title not present leave as link
        end
        ref = ref .. ']'
    else
        ref = ref .. str
    end
    ref = ref .. ' '
    if hc(a.polldate) then
        ref = ref .. a.polldate .. '.'
    end
    ref = ref .. " ''RuneScape'' Polls. "
    ref = ref .. (a.notes or '')
    
    if onmain() and not (hc(a.url) and hc(a.poll) and hc(a.question) and hc(a.polldate)) then
        c = c .. '[[Category:Incomplete References]]'
    end
    return ref, c
end


--[==[
Template:CitePostbag and Template:PlainCitePostbag
--]==]
p.postbagref = function(frame)
    return reftag(frame, 'postbag')
end

p.postbagplain = function(frame)
    return plainref(frame, 'postbag')
end

r.postbag = function(a)
    local ref = 'Jagex. '
    local c = ''
    
    local issue, anchor
    
    if hc(a.letter) then
        anchor = a.letter
        if anchor == tostring(tonumber(anchor)) then
            anchor = tonumber(anchor)
            if anchor == floor(anchor) and anchor >= 1 and anchor <= 15 then
                anchor = true
            end
        end
    end
    
    if hc(a.issue) then
        if postbags[a.issue] then
            issue = 'Postbag ' .. a.issue .. ' - [[' .. postbags[a.issue] .. '#'
            if anchor then
                issue = issue .. 'letter ' .. a.letter
            else
                issue = issue .. a.letter
            end
            issue = issue .. '|' .. postbags[a.issue] .. ']]'
        else
            issue = 'Postbag ' .. a.issue
        end
        ref = ref .. issue
        if hc(a.title) then
            ref = ref .. ' - "' .. a.title .. '"'
        end
    elseif hc(a.title) then
        ref = ref .. '" ' .. a.title .. '"'
    end
    if hc(a.letter) then
        if ref ~= '' then
            ref = ref .. ', '
        end
        if anchor then
            ref = ref .. 'letter #' .. a.letter
        else
            ref = ref .. a.letter
        end
    end
    
    if hc(a.author) then
        ref = ref .. ', by' .. a.author
    end
    
    ref = ref .. ". '''RuneScape''' Postbags from the Hedge. "
    ref = ref .. (a.notes or '')
    
    if onmain() and not (hc(a.issue) and hc(a.letter) and hc(a.author)) then
        c = c .. '[[Category:Incomplete References]]'
    end
    return ref, c
end


--[==[
Template:CiteSupport and Template:PlainCiteSupport
--]==]
p.supportref = function(frame)
    return reftag(frame, 'support')
end

p.supportplain = function(frame)
    return plainref(frame, 'support')
end

r.support = function(a)
    local ref = 'Jagex. '
    local c = ''
    
    local str = ''
    if hc(a.title) then
        str = str .. a.title
        if hc(a.sectitle) then
            str = str .. ', ' .. a.sectitle
        end
    else
        str = str .. (a.sectitle or '')
    end
    if str ~= '' then
        str = '"' .. str .. '."'
    end
    
    
    if hc(a.url) then --url, if present makes a link
        ref = ref .. '[' .. a.url
        if str ~= '' then
            ref = ref .. ' ' .. str--if title not present leave as link
        end
        ref = ref .. ']'
    else
        ref = ref .. str
    end
    ref = ref .. " ''RuneScape'' Customer Support. "
    ref = ref .. (a.notes or '')
    
    if onmain() and not (hc(a.url) and hc(a.title) and hc(a.sectitle)) then
        c = c .. '[[Category:Incomplete References]]'
    end
    return ref, c
end


------------ General Citation Templates -----------------


--[==[
Template:CitePub and Template:PlainCitePub
--]==]
p.pubref = function(frame)
    return reftag(frame, 'pub')
end

p.pubplain = function(frame)
    return plainref(frame, 'pub')
end

r.pub = function(a)
    local ref = ''
    local c = ''
    
    ref = a.author or ''
    ref = ref .. '. '
    
    local str = ''
    if hc(a.title) then
        ref = ref .. "''" .. a.title .. "''"
        if hc(a.pages) then
            ref = ref .. ', (' .. a.pages .. ')'
        end
        ref = ref .. '.'
    end
    if hc(a.publisher) then
        ref = ref .. a.publisher
        if hc(a.pubyear) then
            ref = ref .. ', ' .. a.pubyear
        end
    elseif hc(a.pubyear) then
        ref = ref .. a.pubyear
    end
    ref = ref .. '.'
    ref = ref .. (a.notes or '')
    
    if onmain() and not (hc(a.title) and hc(a.publisher) and hc(a.pubyear)) then
        c = c .. '[[Category:Incomplete References]]'
    end
    return ref, c
end


--[==[
Template:CiteTwitter and Template:PlainCiteTwitter
--]==]
p.twitterref = function(frame)
    return reftag(frame, 'twitter')
end

p.twitterplain = function(frame)
    return plainref(frame, 'twitter')
end

r.twitter = function(a)
    local ref
    local c = ''
    ref = 'Jagex. '
    
    if hc(a.url) then --url, if present makes a link
        ref = ref .. '[' .. a.url
        if hc(a.author) then
            ref = ref .. ' ' .. a.author .. "'s Twitter account"--if title not present leave as link
        end
        ref = ref .. ']'
    elseif hc(a.author) then
        ref = ref .. ' ' .. a.author .. "'s Twitter account"
    end
    ref = ref .. '. '
    if hc(a.date) then
        ref = ref .. a.date .. '.'
    end
    if hc(a.quote) then
        if hc(a.author) then
            ref = ref .. a.author .. ': '
        end
        ref = ref .. '"' .. a.quote .. '"'
    end
    ref = ref .. (a.notes or '')
    
    if onmain() and not (hc(a.url) and hc(a.author) and hc(a.quote) and hc(a.date)) then
        c = c .. '[[Category:Incomplete References]]'
    end
    return ref, c
end



--[==[
Template:CiteGeneral and Template:PlainCiteGeneral
--]==]
p.generalref = function(frame)
    return reftag(frame, 'general')
end

p.generalplain = function(frame)
    return plainref(frame, 'general')
end

r.general = function(a)
    local ref = ''
    local c = ''
    
    if hc(a.author) or hc(a.last) then
        local str = ''
        if hc(a.last) then
            str = last
            if hc(a.first) then
                str = str .. ', ' .. a.first
            end
        else
            str = a.author
        end
        
        if hc(a.authorlink) then
            ref = ref .. '[' .. a.authorlink
            if str ~= '' then
                ref = ref .. ' ' .. str
            end
            ref = ref .. ']'
        else
            ref = ref .. str
        end
        
        if hc(a.coauthors) then
            ref = ref .. '; ' .. a.coauthors
        end
        
        ref = ref .. '. '
    end
    
    if hc(a.title) then
        if hc(a.archiveurl) then
            ref = ref .. '[' .. a.archiveurl .. ' ' .. a.title .. ']'
        elseif hc(a.url) then
            ref = ref .. '[' .. a.url .. ' ' .. a.title .. ']'
        end
    end
    
    if hc(a.language) then
        local span =    mw.html.create('span')
                            :css({['font-size'] = '0.95em', color = '#555', position = 'relative'})
                            :wikitext('(' .. a.language .. ')')
        ref = ref .. ' ' .. tostring(span)
    end
    
    if hc(a.format) then
        ref = ref .. ' (' .. a.format .. ')'
    end
    
    if hc(a.work) then
        ref = ref .. ". ''" .. a.work .. "''"
    end
    
    if hc(a.pages) then
        ref = ref .. ' pp. ' .. a.pages .. ')'
    end
    
    if hc(a.publisher) then
        ref = ref .. '. ' .. a.publisher .. ')'
    end
    
    if hc(a.date) then
        ref = ref .. '. ' .. a.date
    elseif hc(a.year) then
        if hc(a.month) then
            ref = ref .. '. ' .. a.month .. ' ' .. a.year
        else
            ref = ref .. '. ' .. a.year
        end
    end
    
    ref = ref .. '.'
    
    if hc(a.archivedate) then
        ref = ref .. ' (Archived from [' .. a.url .. ' the original on ' .. a.archivedate .. '.)'
    end
    
    if hc(a.quote) then
        ref = ref .. ' "' .. a.quote .. '"'
    end
    
    local err = ''
    if (hc(a.url) and hc(a.title)) then
        err = err .. "Error calling CiteGeneral: parameters '''url''' and '''title''' must be specified  "
    end
    if hc(a.archiveurl) ~= hc(a.archivedate) then --xor
        err = err .. "Error calling CiteGeneral: parameters '''archiveurl''' and '''archivedate''' must both be specified or both be unspecified"
    end
    ref = err .. ref
    
    if onmain() and err ~= '' then
        c = c .. '[[Category:Incomplete References]]'
    end
    return ref, c
end


return p
Advertisement