https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ACategory_see_also%2Fsandbox
Module:Category see also/sandbox - Revision history
2025-05-30T10:43:17Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.3
https://en.wikipedia.org/w/index.php?title=Module:Category_see_also/sandbox&diff=1287093106&oldid=prev
Tule-hog: add lowercase label
2025-04-23T23:34:43Z
<p>add lowercase label</p>
<table style="background-color: #fff; color: #202122;" data-mw="interface">
<col class="diff-marker" />
<col class="diff-content" />
<col class="diff-marker" />
<col class="diff-content" />
<tr class="diff-title" lang="en">
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">← Previous revision</td>
<td colspan="2" style="background-color: #fff; color: #202122; text-align: center;">Revision as of 23:34, 23 April 2025</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 115:</td>
<td colspan="2" class="diff-lineno">Line 115:</td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><br /></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local hatnoteText = formatString:format(</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> local hatnoteText = formatString:format(</div></td>
</tr>
<tr>
<td class="diff-marker" data-marker="−"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;"><div> args.LABEL or 'See also',</div></td>
<td class="diff-marker" data-marker="+"></td>
<td style="color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;"><div> args.LABEL<ins style="font-weight: bold; text-decoration: none;"> or args.label</ins> or 'See also',</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> mw.text.listToText(links, ', ', conjunction)</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> mw.text.listToText(links, ', ', conjunction)</div></td>
</tr>
<tr>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> )</div></td>
<td class="diff-marker"></td>
<td style="background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;"><div> )</div></td>
</tr>
</table>
Tule-hog
https://en.wikipedia.org/w/index.php?title=Module:Category_see_also/sandbox&diff=1287093049&oldid=prev
Tule-hog: cp from main
2025-04-23T23:34:07Z
<p>cp from main</p>
<p><b>New page</b></p><div>-- This module implements {{Category see also}}<br />
<br />
local mHatnote = require('Module:Hatnote')<br />
<br />
local p = {}<br />
<br />
local function makeWikitextError(msg)<br />
return string.format(<br />
'<strong class="error">Error: %s ([[Template:Category see also]])</strong>',<br />
msg<br />
)<br />
end<br />
<br />
-- Gets the length of the sequence seq. Usually this should be done with the #<br />
-- operator, but we need to work with tables that get their values through an<br />
-- __index metamethod.<br />
local function getSequenceLength(seq)<br />
local length = 0<br />
for i in ipairs(seq) do<br />
length = i<br />
end<br />
return length<br />
end<br />
<br />
-- Given a table of options, returns a function that formats categories for<br />
-- those options.<br />
--<br />
-- Options:<br />
-- project - a project code such as "fr" (for the French Wikipedia)<br />
-- showPrefix - a boolean value for whether to show the "Category:" prefix<br />
-- (and the project prefix if specified)<br />
--<br />
-- This is implemented as a function generator rather than a simple function<br />
-- so that we can just process the options once, instead of every time we<br />
-- generate a category.<br />
local function newCategoryLinker(options)<br />
local formatString<br />
if options.project then<br />
if options.showPrefix then<br />
formatString = '[[:' .. options.project .. ':Category:%s]]'<br />
else<br />
formatString = '[[:' .. options.project .. ':Category:%s|%s]]'<br />
end<br />
else<br />
if options.showPrefix then<br />
formatString = '[[:Category:%s]]'<br />
else<br />
formatString = '[[:Category:%s|%s]]'<br />
end<br />
end<br />
return function (category)<br />
local title = mw.title.new(category)<br />
local pageName, display<br />
if not title then<br />
-- category is not a valid title, usually because of invalid<br />
-- characters like < or [. Raise an error and suppress the stack<br />
-- level information so that we can catch it and format the error<br />
-- message as wikitext.<br />
error(string.format(<br />
"'%s' is not a valid category name",<br />
category<br />
), 0)<br />
elseif title.namespace == 14 then -- Category namespace<br />
pageName = title.text<br />
display = title.text<br />
else<br />
pageName = title.prefixedText<br />
display = category<br />
end<br />
-- We can get away with using two arguments even when<br />
-- options.showDisplay is false, as string.format ignores extra<br />
-- arguments as long as there is an argument for each flag in the<br />
-- format string.<br />
return formatString:format(pageName, display)<br />
end<br />
end<br />
<br />
function p._main(args)<br />
local nLinks = getSequenceLength(args)<br />
<br />
if nLinks < 1 then<br />
return makeWikitextError('at least one parameter required')<br />
end<br />
<br />
local makeCategoryLink = newCategoryLinker{<br />
project = args.project,<br />
showPrefix = nLinks == 1,<br />
}<br />
<br />
local links = {}<br />
for i, cat in ipairs(args) do<br />
local success, categoryLink = pcall(makeCategoryLink, cat)<br />
if success then<br />
links[i] = categoryLink<br />
else<br />
-- If there was an error, then categoryLink is the error message.<br />
return makeWikitextError(categoryLink)<br />
end<br />
end<br />
<br />
local formatString<br />
if nLinks == 1 then<br />
formatString = '%s: %s'<br />
else<br />
formatString = '%s the categories %s'<br />
end<br />
<br />
-- Don't output a comma before the "and" if we have only two links.<br />
local conjunction<br />
if nLinks == 2 then<br />
conjunction = ' and '<br />
else<br />
conjunction = ', and '<br />
end<br />
<br />
local hatnoteText = formatString:format(<br />
args.LABEL or 'See also',<br />
mw.text.listToText(links, ', ', conjunction)<br />
)<br />
return mHatnote._hatnote(hatnoteText, {selfref = true})<br />
end<br />
<br />
function p.main(frame)<br />
local args = require('Module:Arguments').getArgs(frame, {<br />
wrappers = 'Template:Category see also',<br />
})<br />
return p._main(args)<br />
end<br />
<br />
return p</div>
Tule-hog