Editing Module:Shortcut
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 6: | Line 6: | ||
-- Load required modules | -- Load required modules | ||
local checkType = require('libraryUtil').checkType | local checkType = require('libraryUtil').checkType | ||
− | |||
local p = {} | local p = {} | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
function p._main(shortcuts, options, frame, cfg) | function p._main(shortcuts, options, frame, cfg) | ||
Line 24: | Line 15: | ||
frame = frame or mw.getCurrentFrame() | frame = frame or mw.getCurrentFrame() | ||
cfg = cfg or mw.loadData(CONFIG_MODULE) | cfg = cfg or mw.loadData(CONFIG_MODULE) | ||
− | local | + | local nShortcuts = #shortcuts |
-- Validate shortcuts | -- Validate shortcuts | ||
− | for i, shortcut in ipairs(shortcuts) do | + | if nShortcuts < 1 then |
− | + | return nil | |
− | + | else | |
− | + | for i, shortcut in ipairs(shortcuts) do | |
− | + | if type(shortcut) ~= 'string' or #shortcut < 1 then | |
− | + | error(string.format( | |
− | + | 'shortcut #%d was invalid (shortcuts must be strings of ' .. | |
− | + | 'least one character in length)' | |
− | + | ), 2) | |
− | + | end | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
− | |||
end | end | ||
Line 69: | Line 46: | ||
-- Shortcut heading | -- Shortcut heading | ||
− | local shortcutHeading | + | local shortcutHeading = mw.message.newRawMessage( |
− | + | cfg['shortcut-heading'], | |
− | + | nShortcuts | |
− | + | ):plain() | |
− | + | shortcutHeading = frame:preprocess(shortcutHeading) | |
− | |||
− | |||
− | |||
− | |||
-- Shortcut box | -- Shortcut box | ||
local shortcutList = root | local shortcutList = root | ||
− | :tag(' | + | :tag('table') |
− | :addClass('shortcutbox | + | :addClass('shortcutbox noprint') |
− | |||
:css('float', 'right') | :css('float', 'right') | ||
:css('border', '1px solid #aaa') | :css('border', '1px solid #aaa') | ||
:css('background', '#fff') | :css('background', '#fff') | ||
:css('margin', '.3em .3em .3em 1em') | :css('margin', '.3em .3em .3em 1em') | ||
− | :css('padding', ' | + | :css('padding', '3px') |
:css('text-align', 'center') | :css('text-align', 'center') | ||
− | + | :tag('tr') | |
− | + | :tag('th') | |
− | + | :addClass('plainlist') | |
− | + | :css('border', 'none') | |
− | + | :css('background', 'transparent') | |
− | for i, | + | :tag('small') |
− | shortcutList:tag('li'):wikitext( | + | :wikitext(shortcutHeading) |
+ | :newline() | ||
+ | :tag('ul') | ||
+ | for i, shortcut in ipairs(shortcuts) do | ||
+ | local url = mw.uri.fullUrl(shortcut, {redirect = 'no'}) | ||
+ | url = tostring(url) | ||
+ | local link = string.format('[%s %s]', url, shortcut) | ||
+ | shortcutList:tag('li'):wikitext(link) | ||
+ | end | ||
+ | if options.msg then | ||
+ | shortcutList:tag('li'):wikitext(options.msg) | ||
+ | end | ||
+ | |||
+ | -- Error category | ||
+ | do | ||
+ | local title = mw.title.new(shortcuts[1]) | ||
+ | if not title or not title.exists then | ||
+ | root:wikitext(string.format( | ||
+ | '[[%s:%s]]', | ||
+ | mw.site.namespaces[14].name, | ||
+ | cfg['first-parameter-error-category'] | ||
+ | )) | ||
+ | end | ||
end | end | ||