https://shergoodaviation.com/wiki/index.php?title=Module:Section_link&feed=atom&action=history
Module:Section link - Revision history
2024-03-29T11:46:47Z
Revision history for this page on the wiki
MediaWiki 1.31.0
https://shergoodaviation.com/wiki/index.php?title=Module:Section_link&diff=309&oldid=prev
Tsukino.firethorn: 1 revision imported
2020-06-04T00:32:55Z
<p>1 revision imported</p>
<table class="diff diff-contentalign-left" data-mw="interface">
<tr class="diff-title" lang="en">
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">← Older revision</td>
<td colspan="1" style="background-color: #fff; color: #222; text-align: center;">Revision as of 00:32, 4 June 2020</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>
Tsukino.firethorn
https://shergoodaviation.com/wiki/index.php?title=Module:Section_link&diff=308&oldid=prev
sa>Trappist the monk: percent-decode;
2019-12-19T00:33:27Z
<p>percent-decode;</p>
<p><b>New page</b></p><div>-- This module implements {{section link}}.<br />
require('Module:No globals');<br />
<br />
local checkType = require('libraryUtil').checkType<br />
<br />
local p = {}<br />
<br />
local function makeSectionLink(page, section, display)<br />
display = display or section<br />
page = page or ''<br />
return string.format('[[%s#%s|%s]]', page, section, display)<br />
end<br />
<br />
local function normalizeTitle(title)<br />
title = mw.ustring.gsub(mw.ustring.gsub(title, "'", ""), '"', '')<br />
title = mw.ustring.gsub(title, "%b<>", "")<br />
return mw.title.new(title).prefixedText<br />
end<br />
<br />
function p._main(page, sections, options, title)<br />
-- Validate input.<br />
checkType('_main', 1, page, 'string', true)<br />
checkType('_main', 3, options, 'table', true)<br />
if sections == nil then<br />
sections = {}<br />
elseif type(sections) == 'string' then<br />
sections = {sections}<br />
elseif type(sections) ~= 'table' then<br />
error(string.format(<br />
"type error in argument #2 to '_main' " ..<br />
"(string, table or nil expected, got %s)",<br />
type(sections)<br />
), 2)<br />
end<br />
options = options or {}<br />
title = title or mw.title.getCurrentTitle()<br />
<br />
-- Deal with blank page names elegantly<br />
if page and not page:find('%S') then<br />
page = nil<br />
options.nopage = true<br />
end<br />
<br />
-- Make the link(s).<br />
local isShowingPage = not options.nopage<br />
if #sections <= 1 then<br />
local linkPage = page or ''<br />
local section = sections[1] or 'Notes'<br />
local display = '§&nbsp;' .. section<br />
if isShowingPage then<br />
page = page or title.prefixedText<br />
if options.display and options.display ~= '' then<br />
if normalizeTitle(options.display) == normalizeTitle(page) then<br />
display = options.display .. ' ' .. display<br />
else<br />
error(string.format(<br />
'Display title "%s" was ignored since it is ' ..<br />
"not equivalent to the page's actual title",<br />
options.display<br />
), 0)<br />
end<br />
else<br />
display = page .. ' ' .. display<br />
end<br />
end<br />
return makeSectionLink(linkPage, section, display)<br />
else<br />
-- Multiple sections. First, make a list of the links to display.<br />
local ret = {}<br />
for i, section in ipairs(sections) do<br />
ret[i] = makeSectionLink(page, section)<br />
end<br />
<br />
-- Assemble the list of links into a string with mw.text.listToText.<br />
-- We use the default separator for mw.text.listToText, but a custom<br />
-- conjunction. There is also a special case conjunction if we only<br />
-- have two links.<br />
local conjunction<br />
if #sections == 2 then<br />
conjunction = '&#8203; and '<br />
else<br />
conjunction = ', and '<br />
end<br />
ret = mw.text.listToText(ret, nil, conjunction)<br />
<br />
-- Add the intro text.<br />
local intro = '§§&nbsp;'<br />
if isShowingPage then<br />
intro = (page or title.prefixedText) .. ' ' .. intro<br />
end<br />
ret = intro .. ret<br />
<br />
return ret<br />
end<br />
end<br />
<br />
function p.main(frame)<br />
local yesno = require('Module:Yesno')<br />
local args = require('Module:Arguments').getArgs(frame, {<br />
wrappers = 'Template:Section link',<br />
valueFunc = function (key, value)<br />
value = value:match('^%s*(.-)%s*$') -- Trim whitespace<br />
-- Allow blank first parameters, as the wikitext template does this.<br />
if value ~= '' or key == 1 then<br />
return value<br />
end<br />
end<br />
})<br />
<br />
for k, v in pairs(args) do -- replace underscores in the positional parameter values<br />
if 'number' == type(k) then<br />
if not yesno (args['keep-underscores']) then -- unless |keep-underscores=yes<br />
args[k] = mw.uri.decode (v, 'WIKI'); -- percent-decode; replace underscores with space characters<br />
else<br />
args[k] = mw.uri.decode (v, 'PATH'); -- percent-decode; retain underscores<br />
end<br />
end<br />
end<br />
<br />
-- Sort the arguments.<br />
local page<br />
local sections, options = {}, {}<br />
for k, v in pairs(args) do<br />
if k == 1 then<br />
-- Doing this in the loop because of a bug in [[Module:Arguments]]<br />
-- when using pairs with deleted arguments.<br />
page = mw.text.decode(v, true)<br />
elseif type(k) == 'number' then<br />
sections[k] = v<br />
else<br />
options[k] = v<br />
end<br />
end<br />
<br />
options.nopage = yesno (options.nopage); -- make boolean<br />
<br />
-- Extract section from page, if present<br />
if page then<br />
local p, s = page:match('^(.-)#(.*)$')<br />
if p then page, sections[1] = p, s end<br />
end<br />
<br />
-- Compress the sections array.<br />
local function compressArray(t)<br />
local nums, ret = {}, {}<br />
for num in pairs(t) do<br />
nums[#nums + 1] = num<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 />
sections = compressArray(sections)<br />
<br />
return p._main(page, sections, options)<br />
end<br />
<br />
return p</div>
sa>Trappist the monk