Content added Content deleted
(fix talk page links, and fix bug producing spurious WhatLinksHere links (however note that a link will appear for Foo if the code "talk=Foo" is used)) |
(fix bug for data being shared between multiple message boxes called from the same module; allow boxes to be hidden; use Module:Arguments to fetch the arguments) |
||
Line 2: | Line 2: | ||
-- Require necessary modules. |
-- Require necessary modules. |
||
local getArgs = require('Module:Arguments').getArgs |
|||
local htmlBuilder = require('Module:HtmlBuilder') |
local htmlBuilder = require('Module:HtmlBuilder') |
||
local categoryHandler = require('Module:Category handler').main |
local categoryHandler = require('Module:Category handler').main |
||
Line 18: | Line 19: | ||
local trim = mw.text.trim |
local trim = mw.text.trim |
||
-------------------------------------------------------------------------------- |
|||
⚫ | |||
-- Helper functions |
|||
-------------------------------------------------------------------------------- |
|||
local function getTitleObject(page, ...) |
local function getTitleObject(page, ...) |
||
Line 58: | Line 61: | ||
table.sort(nums) |
table.sort(nums) |
||
return nums |
return nums |
||
⚫ | |||
-------------------------------------------------------------------------------- |
|||
-- Box class definition |
|||
-------------------------------------------------------------------------------- |
|||
⚫ | |||
box.__index = box |
|||
function box.new() |
|||
⚫ | |||
setmetatable(obj, box) |
|||
return obj |
|||
end |
end |
||
Line 195: | Line 211: | ||
if self.isSmall then |
if self.isSmall then |
||
self:addClass(cfg.smallClass or 'mbox-small') |
self:addClass(cfg.smallClass or 'mbox-small') |
||
⚫ | |||
if yesno(args.hidden) then |
|||
self:addClass('infobox editsection') |
|||
end |
end |
||
self:addClass(self.typeClass) |
self:addClass(self.typeClass) |
||
Line 534: | Line 553: | ||
local function main(boxType, args) |
local function main(boxType, args) |
||
local outputBox = box.new() |
|||
outputBox:setTitle(args) |
|||
local cfg = |
local cfg = outputBox:getConfig(boxType) |
||
args = box:removeBlankArgs(cfg, args) |
|||
args = outputBox:removeBlankArgs(cfg, args) |
|||
outputBox:setBoxParameters(cfg, args) |
|||
return |
return outputBox:export() |
||
end |
end |
||
local function makeWrapper(boxType) |
local function makeWrapper(boxType) |
||
return function (frame) |
return function (frame) |
||
local args = getArgs(frame, {trim = false, removeBlanks = false}) |
|||
-- 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 == mw.getCurrentFrame() then |
|||
origArgs = frame:getParent().args |
|||
for k, v in pairs(frame.args) do |
|||
origArgs = frame.args |
|||
break |
|||
end |
|||
else |
|||
origArgs = frame |
|||
⚫ | |||
-- Trim whitespace. |
|||
⚫ | |||
for k, v in pairs(origArgs) do |
|||
if type(v) == 'string' then |
|||
v = trim(v) |
|||
end |
|||
args[k] = v |
|||
⚫ | |||
return main(boxType, args) |
return main(boxType, args) |
||
end |
end |