Module:Update

--

--TODO - Implement OSRSUpdate into Lua and modify Update template with field for pre-osrs.

-- IMPORTS local pt = require('Module:Paramtest') local hc = pt.has_content local dt = pt.default_to

-- exposed table local p = {}

--[=[ -- -- HELPER TABLES AND FUNCTIONS -- --]=]

-- replacement before calling encode -- as lua patterns local repl_before = { ['%('] = ,	['%)'] = ,	['%!'] = '', }

-- replacements after calling encode -- as lua patterns local repl_after = { ['%+'] = '-',	['%%2C'] = '', ['%%2F'] = '', ['%%3F'] = '', ['%%26%%2338%%3B'] = '', ['%%E2%%80%%93'] = '', ['%.'] = ,	['%%26quot%%3B'] = , ['%%E2%%80%%99'] = '', ['%%26%%2339%%3B'] = '', ['%%C3%%B6'] = 'o', ['%%3A'] = '', }

-- converting month names to hex for sortkeys local hexmonthconv = { January = '1', February = '2', March = '3', April = '4', May = '5', June = '6', July = '7', August = '8', September = '9', October = 'A', November = 'B', December = 'C', }

-- category mapping: {category name, type for use on date pages (eg 28 November) local category_info = { bts = {'Behind the Scenes updates', 'Behind the Scenes'}, community = {'Community updates', 'Community'}, devblog = {'Developer Blogs', 'Developer Blog'}, game = {'Game updates', 'Game update'}, future = {'Future Updates', 'Future update'}, mobile = {'Mobile updates', 'Mobile update'}, shop = {'Shop updates', 'Shop update'}, support = {'Support updates', 'Support'}, technical = {'Technical updates', 'Technical'}, website = {'Website updates', 'Website update'}, ['#default'] = {'Missing update category', ''}, } -- input mapping: accepted inputs -> keys for above table local cat_switch = { bts = 'bts', ['behind the scenes'] = 'bts', comm = 'community', community = 'community', dev = 'devblog', blog = 'devblog', ['dev blog'] = 'devblog', devblog = 'devblog', game = 'game', future = 'future', mobile = 'mobile', shop = 'shop', cs = 'support', customer = 'support', ['customer support'] = 'support', support = 'support', tech = 'technical', technical = 'technical', th = 'th', site = 'website', ws = 'website', website = 'website', ['#default'] = '#default' }

-- given a supported 'category' code, return the name of the category function get_update_category(catarg) if hc(catarg) then catarg = string.gsub(string.lower(catarg), ' ?updates?', '') if cat_switch[catarg] and category_info[cat_switch[catarg]] then return category_info[cat_switch[catarg]][1] else return category_info[cat_switch['#default']][1] end else return category_info[cat_switch['#default']][1] end end

-- given d,m,y, return the relevant time-based categories (with sorting) function get_time_categories(day, month, year) local ret = {} local hexmonth, dayzero if not day or not month or not hexmonthconv[month] or not year then table.insert(ret, '') else dayzero = ((tonumber(day) < 10 and '0'..day) or day) hexmonth = hexmonthconv[month] --, sorted by year (eg 2015) table.insert(ret, string.format('', day, month, year, hexmonth, dayzero)) --, sorted by monthday, months converted to hex, eg B28 (28 November) table.insert(ret, string.format('', year, hexmonth, dayzero)) --, sorted year month day table.insert(ret, string.format('', year, hexmonth, dayzero)) end

-- Historical or OSRS updates if tonumber(year) < 2008 then table.insert(ret, '') else table.insert(ret, '') end return table.concat(ret) end

-- lang for formatting date local lang = mw.getContentLanguage -- current title local title = mw.title.getCurrentTitle

--[=[ -- -- TEMPLATES -- --]=]

-- Template:Update function p.update(frame) local a = frame:getParent.args local div = mw.html.create('div') :addClass('official update') :done local link if hc(a.link) then if a.link == 'no' then link = 'official news post' else link = '[' .. a.link .. ' official news post]' end else link = string.lower(title.baseText) for i,v in pairs(repl_before) do			link = string.gsub(link, i, v)		end link = mw.uri.encode(link) for i,v in pairs(repl_after) do			link = string.gsub(link, i, v)		end link = '[http://services.runescape.com/m=news/' .. link .. ' official news post]' end local date_link, day, month, year if hc(a.date) then day = lang:formatDate('j', a.date) month = lang:formatDate('F', a.date) year = lang:formatDate('Y', a.date) date_link =  .. day .. ' ' .. month .. ' ' .. year ..  else date_link = '(missing date)' end if hc(a.rev) then date_link = date_link .. ', and revised on ' .. lang:formatDate('j F Y', a.rev) end if hc(a.author) then date_link = date_link .. ' by ' .. a.author end -- Determine whether message is historical (pre-osrs), osrs. local message = '' local website = '' if hc(a.time) then --Historical updates if a.time == 'historical' then message = ' is from before the launch of \'\'Old School RuneScape\'\' and is copied verbatim from the ' website = '\'\'RuneScape\'\' website' end --OSRS updates else message = ' is copied verbatim from the ' website = '\'\'Old School RuneScape\'\' website' end div:wikitext('This ' .. link .. message) :tag('span') :addClass('plainlinks') :wikitext(website) :done :wikitext('. It is copyrighted by Jagex.') :tag('br'):done :wikitext('It was added on ' .. date_link .. '.') :done local div2 = ''

if hc(a.article) then div2 = mw.html.create('div') :addClass('update-redirect') :wikitext('This is a newspost. For the wiki article, see ' .. a.article .. '') :done if hc(a.nuke) then if a.nuke == 'yes' then div2:addClass('nuke') :done end end end local cat = '' -- cats only in update namespace if title.namespace == 112 then cat = '' cat = cat .. get_time_categories(day, month, year) end local ret = ' ' .. tostring(div2) .. tostring(div) .. cat .. ' '	return ret end

-- Template:Patch Notes no links available as Patch Note Archive have been removed from Jagex's website function p.patchnotes(frame) local a = frame:getParent.args local cat = '' local div = mw.html.create('div') :addClass('official update') :done local date_link local day, month, year = , , '' if hc(a.date) then day = lang:formatDate('j', a.date) month = lang:formatDate('F', a.date) year = lang:formatDate('Y', a.date) date_link = string.format('%s %s %s', day, month, year) else date_link = '(missing date)' end if hc(a.rev) then date_link = date_link .. ', and revised on ' .. lang:formatDate('j F Y', a.rev) end div:wikitext('These official Patch Notes are copied verbatim from Patch Notes Archive and no longer available. It is copyrighted by Jagex.') :done :tag('br'):done :wikitext('These Patch Notes were announced on ' .. date_link .. '.') :done cat = cat .. ''	cat = cat .. get_time_categories(day, month, year) -- not update namespace, remove cat if title.namespace ~= 112 then cat = '' end local ret = frame:getParent:preprocess(string.format('', day, month, year)) .. '' .. tostring(div) .. cat .. ' '	return ret end

-- Template:DevBlog function p.devblog(frame) local a = frame:getParent.args local blogtitle = dt(a.title, title.baseTitle) local cat = '' local div = mw.html.create('div') :addClass('official devblog') :done local link if hc(a.link) then if a.link == 'no' then link = "RuneScape website" else link = '[' .. a.link .. " RuneScape website]" end else link = title.baseText for i,v in pairs(repl_before) do			link = string.gsub(link, i, v)		end link = mw.uri.encode(link) for i,v in pairs(repl_after) do			link = string.gsub(link, i, v)		end link = '[http://services.runescape.com/m=rswiki/en/DevBlog:' .. link .. " RuneScape website]" end local date_link, day, month, year if hc(a.date) then day = lang:formatDate('j', a.date) month = lang:formatDate('F', a.date) year = lang:formatDate('Y', a.date) date_link =  .. day .. ' ' .. month .. ' ' .. year ..  else date_link = '(missing date)' end local authorstr = '' if hc(a.author) then authorstr = "'''" .. a.author .. "'''"	else authorstr = '(missing author)' cat = cat .. ''	end div:wikitext('This Developer Blog is copied verbatim from the ') :tag('span') :addClass('plainlinks') :wikitext(link) :done :wikitext('. It is copyrighted by Jagex.') :tag('br'):done :wikitext('It is written by ' .. authorstr .. ' and is dated ' .. date_link .. '.') :done local div2 = mw.html.create('div') :css({					['font-size'] = '150%',					background = 'transparent none repeat scroll 0 0',					['border-bottom'] = '1px solid #aaa',					['font-weight'] = 'normal',					['margin-bottom'] = '15px',					['padding-bottom'] = '0.17em',					['padding-top'] = '0.5em',					['text-align'] = 'center',				}) :wikitext(blogtitle) :done -- cats only in update namespace if title.namespace == 112 then cat = '' cat = cat .. get_time_categories(day, month, year) else cat = '' end local ret = ' ' .. tostring(div) .. cat .. tostring(div2) return ret end

--[=[ -- -- CATEGORY FORMATTERS -- --]=]

-- etc function p.date_cat(frame) local f = frame:getParent local d	if hc(f.args[1]) then d = f.args[1] else -- assumes 2016 so that leap years work d = string.gsub(title.text, ' ?updates?', '') .. ' 2016'	end local ret = 'This category contains updates posted on ' .. lang:formatDate('j F', d) .. ', sorted chronologically.' -- cats only in category namespace if title.namespace == 14 then --updates by day, sorted by hexmonth,day: B28 (28 November) ret = ret .. ''		--updates by month, sorted by [space]day ret = ret .. ''	end return ret end

-- etc function p.year_cat(frame) local f = frame:getParent local d	if hc(f.args[1]) then d = f.args[1] else d = string.gsub(title.text, ' ?updates?', '') end local ret = 'This category contains updates posted in ' .. d .. ', sorted chronologically.' -- cats only in category namespace if title.namespace == 14 then --updates by year, sorted by [space]year ret = ret .. ''	end return ret end

--[=[ -- -- DPL HANDLERS -- --]=]

function p.datedpl(frame) local a = frame:getParent.args local year local cat local page = a['%TITLE%'] if hc(a.year) then year = a.year else year = lang:formatDate('Y', a.date) end if hc(a.category) then -- if it has category, cat = category_info[cat_switch[string.gsub(string.lower(a.category), ' ?updates?', '')]][2] else -- missing both probably means cat = 'Patch Notes' end return string.format("%s – %s: %s",year,cat,page,page) end

--TODO --p.updatedpl --p.patchnotesdpl --etc

return p