https://nordiclarp.org/w/index.php?title=Module:Category_see_also&feed=atom&action=historyModule:Category see also - Revision history2024-03-28T10:49:48ZRevision history for this page on the wikiMediaWiki 1.34.2https://nordiclarp.org/w/index.php?title=Module:Category_see_also&diff=8561&oldid=prevJohannes Axner: 1 revision imported2018-12-29T15:49:23Z<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 15:49, 29 December 2018</td>
</tr><tr><td colspan="2" class="diff-notice" lang="en"><div class="mw-diff-empty">(No difference)</div>
</td></tr></table>Johannes Axnerhttps://nordiclarp.org/w/index.php?title=Module:Category_see_also&diff=8560&oldid=preven>Mr. Stradivarius: Protected "Module:Category see also": High-risk Lua module: 50,000+ transclusions ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))2018-01-27T05:50:30Z<p>Protected "<a href="/wiki/Module:Category_see_also" title="Module:Category see also">Module:Category see also</a>": <a href="/w/index.php?title=WP:High-risk_templates&action=edit&redlink=1" class="new" title="WP:High-risk templates (page does not exist)">High-risk Lua module</a>: 50,000+ transclusions ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))</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>en>Mr. Stradivarius