Editing Module:Portal
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | --[==[ This module is a Lua implementation of the old {{Portal}} template. As of | + | --[==[ This module is a Lua implementation of the old {{Portal}} template. As of August 2013 it is used on nearly 5,000,000 articles. |
− | -- Please take care when updating it! It outputs two functions: p.portal, which generates a | + | -- Please take care when updating it! It outputs two functions: p.portal, which generates a table of portals, and p.image, which |
-- produces the image name for an individual portal. | -- produces the image name for an individual portal. | ||
Line 41: | Line 41: | ||
local p = {} | local p = {} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
local function matchImagePage(s) | local function matchImagePage(s) | ||
Line 117: | Line 70: | ||
local function getImageName(s) | local function getImageName(s) | ||
-- Gets the image name for a given string. | -- Gets the image name for a given string. | ||
− | |||
if type(s) ~= 'string' or #s < 1 then | if type(s) ~= 'string' or #s < 1 then | ||
− | return | + | return 'Portal-puzzle.svg' |
end | end | ||
s = mw.ustring.lower(s) | s = mw.ustring.lower(s) | ||
− | return matchImagePage(s) or matchImagePage(getAlias(s)) or | + | return matchImagePage(s) or matchImagePage(getAlias(s)) or 'Portal-puzzle.svg' |
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 132: | Line 80: | ||
-- This function builds the portal box used by the {{portal}} template. | -- This function builds the portal box used by the {{portal}} template. | ||
local root = mw.html.create('div') | local root = mw.html.create('div') | ||
− | + | :addClass('noprint portal') | |
− | |||
− | :addClass('noprint portal | ||
:addClass(args.left and 'tleft' or 'tright') | :addClass(args.left and 'tleft' or 'tright') | ||
− | :css('margin', args.margin or | + | :css('border', 'solid #aaa 1px') |
+ | :css('margin', args.margin or (args.left == 'yes' and '0.5em 1em 0.5em 0') or '0.5em 0 0.5em 1em') | ||
:newline() | :newline() | ||
− | -- | + | -- Start the table. This corresponds to the start of the wikitext table in the old [[Template:Portal]]. |
− | + | local tableroot = root:tag('table') | |
− | + | :css('background', '#f9f9f9') | |
− | + | :css('font-size', '85%') | |
− | + | :css('line-height', '110%') | |
− | + | :css('max-width', '175px') | |
− | + | :css('width', type(args.boxsize) == 'string' and (args.boxsize .. 'px') or nil) | |
− | |||
− | |||
− | |||
− | |||
− | |||
-- If no portals have been specified, display an error and add the page to a tracking category. | -- If no portals have been specified, display an error and add the page to a tracking category. | ||
if not portals[1] then | if not portals[1] then | ||
− | + | tableroot:wikitext('<strong class="error">No portals specified: please specify at least one portal</strong>[[Category:Portal templates without a parameter]]') | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | |||
− | |||
− | |||
− | |||
-- Display the portals specified in the positional arguments. | -- Display the portals specified in the positional arguments. | ||
Line 207: | Line 104: | ||
-- Generate the html for the image and the portal name. | -- Generate the html for the image and the portal name. | ||
− | + | tableroot | |
:newline() | :newline() | ||
− | :tag(' | + | :tag('tr') |
− | :tag(' | + | :css('vertical-align', 'middle') |
− | :wikitext(string.format('[[File:%s|32x28px|class=noviewer]]', image)) | + | :tag('td') |
+ | :css('text-align', 'center') | ||
+ | :wikitext(string.format('[[File:%s|32x28px|alt=Portal icon|class=noviewer]]', image)) | ||
:done() | :done() | ||
− | :tag(' | + | :tag('td') |
+ | :css('padding', '0 0.2em') | ||
+ | :css('vertical-align', 'middle') | ||
+ | :css('font-style', 'italic') | ||
+ | :css('font-weight', 'bold') | ||
:wikitext(string.format('[[Portal:%s|%s%sportal]]', portal, portal, args['break'] and '<br />' or ' ')) | :wikitext(string.format('[[Portal:%s|%s%sportal]]', portal, portal, args['break'] and '<br />' or ' ')) | ||
end | end | ||
Line 220: | Line 123: | ||
function p._image(portals) | function p._image(portals) | ||
+ | |||
-- Wrapper function to allow getImageName() to be accessed through #invoke. | -- Wrapper function to allow getImageName() to be accessed through #invoke. | ||
− | + | return getImageName(portals[1]) | |
− | |||
end | end | ||
Line 319: | Line 222: | ||
end | end | ||
end | end | ||
− | + | return p[funcName](processPortalArgs(args)) -- passes two tables to func: an array of portal names, and a table of named arguments. | |
− | |||
− | |||
− | |||
− | |||
− | return | ||
end | end | ||
end | end |