A documentação para este módulo pode ser criada em Módulo:Codename/doc
--------------------------------------------------------------------------------
-- This Módulo calls information from releases and series by their Codename. --
-- Functions are invoked for use in various templates and for generation of --
-- site CSS. --
-- See [[Help:Codenames]] for details on how they are used. --
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Set up and component functions
------------------------------------------------------------------------A--------
--SET UP
local Codename = {tables = {odr={}}}
local hf = require('Módulo:HF')
local getArgs = require('Dev:Arguments').getArgs
local uoTables = mw.loadData('Módulo:Codename/data')
local orel, oser = hf.orderedList(uoTables, 'rel'), hf.orderedList(uoTables, 'ser')
Codename.tables.ser, Codename.tables.odr.ser = oser[1], oser[2]
Codename.tables.rel, Codename.tables.odr.rel = orel[1], orel[2]
local namedtbls = {
ser = 'Series',
rel = 'Releases',
}
--REL AND SER CALLS
local function dive(t, f)
--Returns t[f[1]f[2]f[3]...f[#f]] from Codename.tables
for i=1, #f do
if t then t = t[f[i]]
else return nil end
end
local y = type(t)
-- if y == 'table' and array.isarray(t) then y = 'array' end
if y == 'table' then return table.tostring(t)
-- elseif y == 'array' then return array.tostring(t)
elseif y == 'nil' then return nil
elseif y == 'function' then return 'function'
else return t end
end
function Codename.rel(frame)
return dive(Codename.tables.rel, hf.reargs(getArgs(frame)))
end
function Codename.ser(frame)
return dive(Codename.tables.ser, hf.reargs(getArgs(frame)))
end
--------------------------------------------------------------------------------
-- Sideicons ({{sideicon}})
--------------------------------------------------------------------------------
--This function takes an icon table and formats it
function Codename.icontext(icon, style)
--Stylizes userbox 'icon'
local defaultstyle= 'standard'
local lines = {}
if icon.firstline then table.insert(lines, tostring(mw.html.create('span')
:wikitext(icon['firstline'])
:cssText(style[(icon['firstsize'] or defaultstyle) .. ' style'] or '')
)) end
if icon.secondline then table.insert(lines, tostring(mw.html.create('span')
:wikitext(icon['secondline'])
:cssText(style[(icon['secondsize'] or defaultstyle) .. ' style'] or '')
)) end
return table.concat(lines, '<br/>')
end
--
--[1] = Rel codename
--[* style] = style for line styles
--line styles e.g. "small" (as in "firstsize='small'")
--line style default = 'standard'
function Codename.relicontext(frame)
local f = getArgs(frame)
if not Codename.tables.rel[f[1]] then return require "Módulo:FFWiki".err("?") end
return Codename.icontext(Codename.tables.rel[f[1]]['sideicon'], f)
end
local function sideicon(link, html, class)
--Return wikitext of the individual sideicon
local span = mw.html.create('span'):addClass('page-info-icon'):addClass(class):node(html):allDone()
return '[[' .. link .. '|' .. tostring(span) .. ']]'
end
local function relsicon(cname)
local sitbl = Codename.tables.rel[cname]['sideicon']
local span = mw.html.create('span'):addClass('text-container')
if sitbl.secondline then
if (sitbl.firstsize or '') == 'small' then
span:tag('span'):addClass('two-line-small'):wikitext(sitbl.firstline)
span:tag('span'):addClass('two-line'):wikitext(sitbl.secondline)
else
span:tag('span'):addClass('two-line'):wikitext(sitbl.firstline)
span:tag('span'):addClass('two-line-small'):wikitext(sitbl.secondline)
end
else
span:tag('span'):addClass('one-line'):wikitext(sitbl.firstline)
end
return sideicon(Codename.tables.rel[cname]['link'], span, cname .. 'a')
end
function Codename.artinf(frame)
--Generates a <span> containing everything to be added to Article Information.
return mw.html.create('span'):addClass('titleicon'):wikitext(relsicon(hf.reargs(getArgs(frame))[1]))
end
--------------------------------------------------------------------------------
-- Generators for lists (for use on [[Help:Codename]])
--------------------------------------------------------------------------------
local function li(elem, info)
--Generates an individual <li> for generator()
local addedinfo = ''
if info then addedinfo = ': (' .. elem[info] .. ')' end
if elem then return mw.html.create('li'):wikitext('[[' .. elem['link'] .. "|''" .. elem['name'] .. "'']]" .. addedinfo)
else return mw.html.create('li'):wikitext('null') end
end
function Codename.generator(frame)
--Generates an ordered list of media. frame[1] == 'rel' or 'ser'. Used in project:scope.
--optional frame[2] allows it to display some info from /data.
local ul = mw.html.create('ul')
local arg = hf.reargs(getArgs(frame))[1]
local info = hf.reargs(getArgs(frame))[2] or null
local tbl = Codename.tables[arg]
local odr = Codename.tables.odr[arg]
for i, x in ipairs(odr) do
if not tbl[x].sub then
local thisLi = li(tbl[x], info)
local ulFlag
local str = ''
if arg == 'rel' then for j, y in ipairs(odr) do --get rid of the conditional if nested ser's
if tbl[y].sub == x then
if not ulFlag then
ulFlag = true
str = '<ul>'
end
str = str .. tostring(li(tbl[y], info))
end
end end
if ulFlag then thisLi:wikitext(str .. '</ul>') end
ul:node(thisLi)
end
end
return ul
end
local function ctblunit(dset)
--Generate table of class colors for ctbl(). text == 'Series' or 'Releases' and dset == 'ser' or 'rel'
local tbl = mw.html.create('table'):addClass('full-width table darktext'):cssText('text-align:center;font-family:monospace;'):tag('tr'):cssText('background:#F5F5F5;font-style:italic;'):tag('th'):attr('colspan','9'):wikitext(namedtbls[dset]):allDone()
local set = Codename.tables[dset]
local odr = {}
for i, x in ipairs(Codename.tables.odr[dset]) do
table.insert(odr,x)
end
--tbl = mw.html.create('p'):wikitext(#odr) --for debugging
local i, j = 0, 1
while (i * 8 + j) <= #odr do
local tr1 = tbl:tag('tr'):cssText('background:#CCC;font-style:italic;'):tag('th'):cssText('width:74px;'):wikitext(namedtbls[dset]):done()
local tr2 = tbl:tag('tr'):cssText('background:#DDD;'):tag('th'):wikitext('Header'):done()
local tr3 = tbl:tag('tr'):cssText('background:#DDD;'):tag('th'):wikitext('Subheader'):done()
while j <= 8 do
local name = odr[i * 8 + j] or 0
if name == 0 then
j = 9 --break without breaking outer while
else
local elem = set[name]
tr1:tag('th'):cssText('width:74px;'):wikitext('[[' .. elem.link .. '|' .. name .. ']]')
tr2:tag('td'):addClass(name .. 'a'):wikitext(name .. 'a')
tr3:tag('td'):addClass(name .. 'b'):wikitext(name .. 'b')
j = j + 1
end
end
i, j = i + 1, 1
end
return tbl
end
function Codename.ctbl()
--Generate tables of all class colors
local container = mw.html.create('div')
local sertbl = container:node(ctblunit('ser'))
local reltbl = container:node(ctblunit('rel'))
return container
end
--------------------------------------------------------------------------------
-- CSS ([[MediaWiki:Custom-releases.css]])
-- Use [[Módulo:Codename/Logger]] to generate then paste it into pages
--------------------------------------------------------------------------------
--Maybe move these data tables to /data, idk
Codename.linkcolors = {
['a:link'] = {
white = 'B0E0E6 !important',
black = '002BB8 !important',
},
['a:visited'] = {
white = 'D8BFD8 !important',
black = '5A3696 !important',
},
['a.new:link'] = {
white = 'FFAAAA !important',
black = 'CC2200 !important',
},
['a.new:visited'] = {
white = 'FFAAAA !important',
black = 'A5585A !important',
},
}
local colordecs = { --Each CSS color declaration and its equivalent in the database.
background = 'bg',
color = 'font',
}
local function classset(cname) --Returns what classes reuse link colors
return {
['aclass'] = {
cname .. 'a',
cname .. '.a',
cname .. ' .a',
'portable-infobox.pi-theme-' .. cname .. ' .pi-title',
'portable-infobox.pi-theme-' .. cname .. ' .pi-header',
},
['bclass'] = {
cname .. 'b',
cname .. '.b',
cname .. ' .b',
'portable-infobox.pi-theme-' .. cname .. ' .pi-data .pi-data-label',
'portable-infobox.pi-theme-' .. cname .. ' .pi-horizontal-group-item.pi-data-label',
},
}
end
local function getcolor(cname,table,abclass,typ) -- Returns the color or white
return Codename.tables[table][cname][abclass][typ] or 'white'
end
local function linkcolors(cname,table)
str = ''
for abclass, classes in pairs(classset(cname)) do
for linktype, color in pairs(Codename.linkcolors) do
for cset, class in ipairs(classes) do
str = str .. '.' .. class .. ' ' .. linktype .. ', '
end
str = str .. [[.q {
color: #]] .. color[getcolor(cname,table,abclass,'font')] .. [[;
}
]]
end end
return str
end
local function cssbgcolorline(cname,table)
str = ''
for abclass, classes in pairs(classset(cname)) do
for cset, class in ipairs(classes) do
str = str .. '.' .. class .. ', '
end
str = str .. [[.q {
]]
for css, lua in pairs(colordecs) do
str = str ..
[[ ]] .. css .. ': ' .. getcolor(cname,table,abclass,lua) .. [[;
]]
end
str = str .. [[}
]]
end
return str
end
local function cssbgimageline(cname,table)
local tbl = Codename.tables[table][cname]
local infoboxline = ''
local navboxline = ''
local clr
local infoboxline = '.portable-infobox.pi-theme-'..cname.. [[ .pi-navigation {
background-image: url("]] .. tbl['nav']['bg'] .. [["), linear-gradient(to right, white 100px, transparent 300px);
background-repeat: no-repeat;
color: ]] .. tbl['aclass']['bg'] .. [[;
text-shadow: 1px 1px 1px ]] .. tbl['aclass']['font'] .. [[;
}
.portable-infobox.pi-theme-]] .. cname .. [[ .pi-navigation a:link {
color: ]] .. tbl['aclass']['bg'] .. [[;
}
.portable-infobox.pi-theme-]] .. cname .. [[ .pi-navigation a:visited {
color: ]] .. tbl['aclass']['bg'] .. [[;
}
]]
local navboxline = '#'..cname..[[-nav .navbox .maintitle {
background-image: url("]]..tbl['nav']['bg']..'"), linear-gradient(to right, white 100px, transparent 300px); background-repeat: no-repeat;\n}\n'
return infoboxline .. navboxline
end
local function tshadow(cname,table)
local tbl = Codename.tables[table][cname]
if tbl.nav and tbl.nav.tshadow then return '#'..cname..[[-nav .navbox .editlink + .titletext {
text-shadow: 0 0 2px black, 0 0 2px black, 0 0 2px black, 0 0 2px black, 0 0 2px black, 0 0 2px black;
}
]]
end
return ''
end
local function picsscollapsibleline(cname,table)
local tbl = Codename.tables[table][cname]
return '.portable-infobox.pi-theme-'..cname..[[ .pi-collapse .pi-header::after {
border-color: ]]..tbl.aclass.font..';\n}\n'
end
function Codename.cssgen(frame) --Creates MediaWiki:Custom-releases.css
local container = ''--will possibly put everything in this bit later
local docheader = [[/* ################################################## */
/* ### RELEASE CLASSES ### */
/* ################################################## */
/* These are generated from Módulo:Codename */
/* Módulo:Codename/data contains styles */
/* cssgen function in Módulo:Codename turns into this */
/* FFWiki */
.FFWikia, .FFWiki.a, .FFWiki .a, .FFWikib, .FFWiki.b, .FFWiki .b {
color: black;
background: #FBEC5D;
}
]]
for k, v in pairs(Codename.tables.odr) do
container = container .. '/* ' .. namedtbls[k] .. ' */\n\n'
for i, x in ipairs(v) do
local tbl = Codename.tables[k][x]
container = container .. '/* ' .. x .. ' - ' .. tbl.name .. ' */\n'
container = container .. cssbgcolorline(x,k) .. linkcolors(x,k) .. picsscollapsibleline(x,k)
container = container .. (tbl.nav and cssbgimageline(x,k) or '') .. tshadow(x,k)
container = container .. '\n\n'
end
end
return docheader .. container
end
return Codename