local getPortalImage = require('Module:Portal').image
local p =
local function getArgNums(prefix, args) -- Returns a table containing the numbers of the arguments that exist for the specified prefix. For example, if the -- prefix was 'data', and 'data1', 'data2', and 'data5' exist, it would return . local nums = for k, v in pairs(args) do local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$') if num then table.insert(nums, tonumber(num)) end end table.sort(nums) return numsend
local function makeHorizontalRule local row = mw.html.create('tr') row :tag('td') :attr('colspan', '2') :tag('hr',) return tostring(row)end
local function makeItem(image, text) local root = mw.html.create('li') root :css('float', 'left') :css('margin-left', '0.3em') :css('height', '3.6em') :tag('span') :css('display', 'inline-block') :css('margin-right', '0.3em') :css('width', '30px') :css('line-height', '3.6em') :css('text-align', 'center') :wikitext(image) :done :tag('span') :css('display', 'inline-block') :css('width', '11em') :css('vertical-align', 'middle') :wikitext(text) return tostring(root)end
local function makeRow(items, heading, subheading, options) if #items < 1 then return end local swapHeadingSize = type(options)
local function makeNumberedRow(prefix, args, heading, subheading, getItemValsFunc, options) if args[prefix] then args[prefix .. '1'] = args[prefix] end local argNums = getArgNums(prefix, args) local items = for i, argNum in ipairs(argNums) do local image, text = getItemValsFunc(args[prefix .. tostring(argNum)]) table.insert(items,) end return makeRow(items, heading, subheading, options)end
function p._main(args) local rows =
-- Get the book row text. local bookHeading = "Books" local bookSubheading = 'View or order collections of articles' local function getBookItemVals(book) local image = '' local text = mw.ustring.format("%s", book, book) return image, text end local bookRow = makeNumberedRow('book', args, bookHeading, bookSubheading, getBookItemVals) table.insert(rows, bookRow)
-- Get the portal row text local portalHeading = "Portals" local portalSubheading = 'Access related topics' local function getPortalItemVals(portal) local image = mw.ustring.format('', getPortalImage) local text = mw.ustring.format("%s portal", portal, portal) return image, text end local portalRow = makeNumberedRow('portal', args, portalHeading, portalSubheading, getPortalItemVals) table.insert(rows, portalRow)
-- Get the sister projects row text. local sisters = local sisterItems = for i, t in ipairs(sisters) do if args[t.arg] then -- Get the image value. local image = mw.ustring.format('', t.image) -- Get the text value. local prefix = t.prefix local search = args[t.arg .. '-search'] or mw.title.getCurrentTitle.text local postfix = t.postfix postfix = postfix and ('#' .. postfix) or local display = t.display local from = t.from local text = mw.ustring.format('%s
from %s', prefix, search, postfix, display, from) if t.arg
-- Make the table. local root = mw.html.create('table') root :attr('role', 'presentation') :addClass('noprint') :addClass('metadata') :addClass('plainlist') :css('background-color', '#f9f9f9') :css('border', '1px solid #aaa') :css('clear', 'both') :css('margin-bottom', '0.5em') :css('margin-top', '0.5em') :wikitext(table.concat(rows, makeHorizontalRule))
return tostring(root)end
function p.main(frame) -- If called via #invoke, use the args passed into the invoking template, or the args passed to #invoke if any exist. Otherwise -- assume args are being passed directly in from the debug console or from another Lua module. local origArgs if frame
return p