https://grlucas.net/index.php?title=Module:Shortcut&feed=atom&action=history
Module:Shortcut - Revision history
2024-03-29T11:18:31Z
Revision history for this page on the wiki
MediaWiki 1.39.0
https://grlucas.net/index.php?title=Module:Shortcut&diff=11315&oldid=prev
Grlucas: 1 revision imported
2020-07-22T19:47:01Z
<p>1 revision imported</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<tr class="diff-title" lang="en">
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 15:47, 22 July 2020</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
Grlucas
https://grlucas.net/index.php?title=Module:Shortcut&diff=11314&oldid=prev
en>Trialpears: Implement merger code by Pppery
2020-06-17T15:18:18Z
<p>Implement merger code by Pppery</p>
<p><b>New page</b></p><div>-- This module implements {{shortcut}}.<br />
<br />
-- Set constants<br />
local CONFIG_MODULE = 'Module:Shortcut/config'<br />
<br />
-- Load required modules<br />
local checkType = require('libraryUtil').checkType<br />
local yesno = require('Module:Yesno')<br />
<br />
local p = {}<br />
<br />
local function message(msg, ...)<br />
return mw.message.newRawMessage(msg, ...):plain()<br />
end<br />
<br />
local function makeCategoryLink(cat)<br />
return string.format('[[%s:%s]]', mw.site.namespaces[14].name, cat)<br />
end<br />
<br />
function p._main(shortcuts, options, frame, cfg)<br />
checkType('_main', 1, shortcuts, 'table')<br />
checkType('_main', 2, options, 'table', true)<br />
options = options or {}<br />
frame = frame or mw.getCurrentFrame()<br />
cfg = cfg or mw.loadData(CONFIG_MODULE)<br />
local isCategorized = yesno(options.category) ~= false<br />
<br />
-- Validate shortcuts<br />
for i, shortcut in ipairs(shortcuts) do<br />
if type(shortcut) ~= 'string' or #shortcut < 1 then<br />
error(message(cfg['invalid-shortcut-error'], i), 2)<br />
end<br />
end<br />
<br />
-- Make the list items. These are the shortcuts plus any extra lines such<br />
-- as options.msg.<br />
local listItems = {}<br />
for i, shortcut in ipairs(shortcuts) do<br />
if yesno(options['target']) then<br />
listItems[i] = string.format("[[%s]]",shortcut)<br />
else<br />
listItems[i] = frame:expandTemplate{<br />
title = 'No redirect',<br />
args = {shortcut}<br />
}<br />
end<br />
end<br />
table.insert(listItems, options.msg)<br />
<br />
-- Return an error if we have nothing to display<br />
if #listItems < 1 then<br />
local msg = cfg['no-content-error']<br />
msg = string.format('<strong class="error">%s</strong>', msg)<br />
if isCategorized and cfg['no-content-error-category'] then<br />
msg = msg .. makeCategoryLink(cfg['no-content-error-category'])<br />
end<br />
return msg<br />
end<br />
<br />
local root = mw.html.create()<br />
root:wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Shortcut/styles.css'} })<br />
-- Anchors<br />
local anchorDiv = root<br />
:tag('div')<br />
:addClass('module-shortcutanchordiv')<br />
for i, shortcut in ipairs(shortcuts) do<br />
local anchor = mw.uri.anchorEncode(shortcut)<br />
anchorDiv:tag('span'):attr('id', anchor)<br />
end<br />
<br />
-- Shortcut heading<br />
local shortcutHeading<br />
do<br />
local nShortcuts = #shortcuts<br />
if nShortcuts > 0 then<br />
local headingMsg = options['shortcut-heading'] or cfg['shortcut-heading']<br />
shortcutHeading = message(headingMsg, nShortcuts)<br />
shortcutHeading = frame:preprocess(shortcutHeading)<br />
end<br />
end<br />
<br />
-- Shortcut box<br />
local shortcutList = root<br />
:tag('div')<br />
:addClass('module-shortcutboxplain plainlist noprint')<br />
:attr('role', 'note')<br />
if shortcutHeading then<br />
shortcutList<br />
:tag('div')<br />
:addClass('module-shortcutlist')<br />
:wikitext(shortcutHeading)<br />
end<br />
local list = shortcutList:tag('ul')<br />
for i, item in ipairs(listItems) do<br />
list:tag('li'):wikitext(item)<br />
end<br />
return tostring(root)<br />
end<br />
<br />
function p.main(frame)<br />
local args = require('Module:Arguments').getArgs(frame)<br />
<br />
-- Separate shortcuts from options<br />
local shortcuts, options = {}, {}<br />
for k, v in pairs(args) do<br />
if type(k) == 'number' then<br />
shortcuts[k] = v<br />
else<br />
options[k] = v<br />
end<br />
end<br />
<br />
-- Compress the shortcut array, which may contain nils.<br />
local function compressArray(t)<br />
local nums, ret = {}, {}<br />
for k in pairs(t) do<br />
nums[#nums + 1] = k<br />
end<br />
table.sort(nums)<br />
for i, num in ipairs(nums) do<br />
ret[i] = t[num]<br />
end<br />
return ret<br />
end<br />
shortcuts = compressArray(shortcuts)<br />
<br />
return p._main(shortcuts, options, frame)<br />
end<br />
<br />
return p</div>
en>Trialpears