Editing Module:Protection banner
From MINR.ORG WIKI
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 797: | Line 797: | ||
content = self:renderImage() | content = self:renderImage() | ||
} | } | ||
+ | end | ||
+ | |||
+ | -------------------------------------------------------------------------------- | ||
+ | -- Documentation class | ||
+ | -------------------------------------------------------------------------------- | ||
+ | |||
+ | local Documentation = class('Documentation') | ||
+ | |||
+ | function Documentation:initialize(cfg) | ||
+ | self._cfg = cfg | ||
+ | end | ||
+ | |||
+ | function Documentation:makeReasonTable() | ||
+ | -- Get the data from the cfg.banners table. | ||
+ | local rowData = {} | ||
+ | for action, reasonTables in pairs(self._cfg.banners) do | ||
+ | for reason, t in pairs(reasonTables) do | ||
+ | rowData[#rowData + 1] = { | ||
+ | reason = reason, | ||
+ | action = action, | ||
+ | description = t.description | ||
+ | } | ||
+ | end | ||
+ | end | ||
+ | |||
+ | -- Sort the table into alphabetical order, first by action and then by | ||
+ | -- reason. | ||
+ | table.sort(rowData, function (t1, t2) | ||
+ | if t1.action == t2.action then | ||
+ | return t1.reason < t2.reason | ||
+ | else | ||
+ | return t1.action < t2.action | ||
+ | end | ||
+ | end) | ||
+ | |||
+ | -- Assemble a wikitable of the data. | ||
+ | local msg = self._cfg.msg | ||
+ | local ret = {} | ||
+ | ret[#ret + 1] = '{| class="wikitable"' | ||
+ | if #rowData < 1 then | ||
+ | ret[#ret + 1] = '|-' | ||
+ | ret[#ret + 1] = string.format( | ||
+ | '| colspan="3" | %s', | ||
+ | msg['documentation-blurb-noreasons'] | ||
+ | ) | ||
+ | else | ||
+ | -- Header | ||
+ | ret[#ret + 1] = '|-' | ||
+ | ret[#ret + 1] = string.format( | ||
+ | '! %s\n! %s\n! %s', | ||
+ | msg['documentation-heading-reason'], | ||
+ | msg['documentation-heading-action'], | ||
+ | msg['documentation-heading-description'] | ||
+ | ) | ||
+ | -- Rows | ||
+ | for _, t in ipairs(rowData) do | ||
+ | ret[#ret + 1] = '|-' | ||
+ | ret[#ret + 1] = string.format( | ||
+ | '| %s\n| %s\n| %s', | ||
+ | t.reason, | ||
+ | t.action, | ||
+ | t.description | ||
+ | ) | ||
+ | end | ||
+ | end | ||
+ | ret[#ret + 1] = '|}' | ||
+ | |||
+ | return table.concat(ret, '\n') | ||
end | end | ||
Line 814: | Line 882: | ||
Padlock = Padlock, | Padlock = Padlock, | ||
} | } | ||
+ | end | ||
+ | |||
+ | function p.reasonTable() | ||
+ | local cfg = mw.loadData('Module:Protection banner/config') | ||
+ | local documentationObj = Documentation:new(cfg) | ||
+ | return documentationObj:makeReasonTable() | ||
end | end | ||