Content deleted Content added
use a local function "messageMixin" to store the message method logic for use in the Row and ArticleHistory classes (does that count as a real mixin? not sure...) |
use a real mixin for message-related methods |
||
Line 30:
local function substituteParams(msg, ...)
return mw.message.newRawMessage(msg, ...):plain()
end▼
local function messageMixin(t, key, ...)▼
local msg = t.cfg.msg[key]▼
if select('#', ...) > 0 then▼
return substituteParams(msg, ...)▼
else▼
return msg▼
end▼
end
Line 61 ⟶ 51:
end
return string.format('[[File:%s|%s%s]]', image, size, caption)
▲end
local function addMixin(class, mixin)
-- Add a mixin to a class. The functions will be shared across classes, so
-- don't use it for functions that keep state.
for name, method in pairs(mixin) do
class[name] = method
▲ end
end▼
-------------------------------------------------------------------------------
-- Message mixin
-- This stores methods used by all classes.
-------------------------------------------------------------------------------
local Message = {}
-- This
▲ if select('#', ...) > 0 then
▲ return substituteParams(msg, ...)
▲ else
▲ return msg
end▼
end
function Message:raiseError(msg, help, level)
local errorText
if help then
errorText = self:message('error-message-help', msg, help)
else
errorText = self:message('error-message-nohelp', msg)
end
level = tonumber(level)
if level and level > 0 then
level = level + 1
end
error(errorText, level)
end
Line 70 ⟶ 99:
local Row = {}
Row.__index = Row
addMixin(Row, Message)
function Row.new(data)
Line 78 ⟶ 108:
obj.categories = {}
return obj
▲end
end
Line 381 ⟶ 407:
local ArticleHistory = {}
ArticleHistory.__index = ArticleHistory
addMixin(ArticleHistory, Message)
function ArticleHistory.new(args, cfg, currentTitle)
Line 434 ⟶ 461:
return nil
end
▲end
end
Line 735 ⟶ 758:
function p._exportClasses()
return {
Message = Message,
Row = Row,
Status = Status,
|