Zum Inhalt springen

Modul:Message box: Unterschied zwischen den Versionen

remove the presentButBlank function, fix bug with blank date values, and trim whitespace from all arguments
(change the smalltext logic to work with collapsible text fields)
(remove the presentButBlank function, fix bug with blank date values, and trim whitespace from all arguments)
Zeile 13: Zeile 13:
local tinsert = table.insert
local tinsert = table.insert
local tconcat = table.concat
local tconcat = table.concat
local trim = mw.text.trim


local box = {}
local box = {}
Zeile 24: Zeile 25:
             return title
             return title
         end
         end
    end
end
local function presentButBlank(s)
    if type(s) ~= 'string' then return end
    if s and not mw.ustring.find(s, '%S') then
        return true
    else
        return false
     end
     end
end
end
Zeile 219: Zeile 211:
             self.issue = args.smalltext
             self.issue = args.smalltext
         else
         else
             local sect = args.sect
             local sect
             if presentButBlank(sect) then
             if args.sect == '' then
                 sect = 'This ' .. (cfg.sectionDefault or 'page')
                 sect = 'This ' .. (cfg.sectionDefault or 'page')
             elseif type(sect) == 'string' then
             elseif type(args.sect) == 'string' then
                 sect = 'This ' .. sect
                 sect = 'This ' .. sect
            else
                sect = nil
             end
             end
             local issue = args.issue
             local issue = args.issue
Zeile 240: Zeile 230:
         -- Get the self.talk value.
         -- Get the self.talk value.
         local talk = args.talk
         local talk = args.talk
         if presentButBlank(talk) and self.isTemplatePage then
         if talk == '' and self.isTemplatePage then
             talk = '#'
             talk = '#'
         end
         end
Zeile 267: Zeile 257:
         -- Get other values.
         -- Get other values.
         self.fix = args.fix
         self.fix = args.fix
         local date = args.date
         if args.date and args.date ~= '' then
        self.date = date and format(" <small>''(%s)''</small>", date)
            self.date = format(" <small>''(%s)''</small>", args.date)
         if presentButBlank(self.date) and self.isTemplatePage then
         elseif args.date == '' and self.isTemplatePage then
             self.date = lang:formatDate('F Y')
             self.date = lang:formatDate('F Y')
         end
         end
Zeile 536: Zeile 526:
         -- assume args are being passed directly in from the debug console
         -- assume args are being passed directly in from the debug console
         -- or from another Lua module.
         -- or from another Lua module.
         local args
         local origArgs
         if frame == mw.getCurrentFrame() then
         if frame == mw.getCurrentFrame() then
             args = frame:getParent().args
             origArgs = frame:getParent().args
             for k, v in pairs(frame.args) do
             for k, v in pairs(frame.args) do
                 args = frame.args
                 origArgs = frame.args
                 break
                 break
             end
             end
         else
         else
             args = frame
            origArgs = frame
        end
        -- Trim whitespace.
        local args = {}
        for k, v in pairs(origArgs) do
            if type(v) == 'string' then
                v = trim(v)
            end
             args[k] = v
         end
         end
         return makeBox(boxType, args)
         return makeBox(boxType, args)