https://wiki.seshstation.com/index.php?title=Module:Shortcut&feed=atom&action=history
Module:Shortcut - Revision history
2024-03-29T05:42:39Z
Revision history for this page on the wiki
MediaWiki 1.36.1
https://wiki.seshstation.com/index.php?title=Module:Shortcut&diff=438&oldid=prev
SESHstation: 1 revision imported
2021-11-21T11:11:28Z
<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 11:11, 21 November 2021</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
SESHstation
https://wiki.seshstation.com/index.php?title=Module:Shortcut&diff=437&oldid=prev
tmpl>Jonesey95: attempt fix suggested in 2019 talk archive
2021-03-11T14:27:25Z
<p>attempt fix suggested in 2019 talk archive</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 templateMode = options.template and yesno(options.template)<br />
local redirectMode = options.redirect and yesno(options.redirect)<br />
local isCategorized = not options.category or 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 />
local templatePath, prefix<br />
if templateMode then<br />
-- Namespace detection<br />
local titleObj = mw.title.new(shortcut, 10)<br />
if titleObj.namespace == 10 then<br />
templatePath = titleObj.fullText<br />
else<br />
templatePath = shortcut<br />
end<br />
prefix = options['pre' .. i] or options.pre or ''<br />
end<br />
if options.target and yesno(options.target) then<br />
listItems[i] = templateMode<br />
and string.format("&#123;&#123;%s[[%s|%s]]&#125;&#125;", prefix, templatePath, shortcut)<br />
or string.format("[[%s]]", shortcut)<br />
else<br />
listItems[i] = frame:expandTemplate{<br />
title = 'No redirect',<br />
args = templateMode and {templatePath, shortcut} or {shortcut, shortcut}<br />
}<br />
if templateMode then<br />
listItems[i] = string.format("&#123;&#123;%s%s&#125;&#125;", prefix, listItems[i])<br />
end<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<br />
redirectMode and cfg['redirect-heading'] or<br />
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 options.float and options.float:lower() == 'left' then<br />
shortcutList:addClass('module-shortcutboxleft')<br />
end<br />
if options.clear and options.clear ~= '' then<br />
shortcutList:css('clear', options.clear)<br />
end<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>
tmpl>Jonesey95