https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AParticles
Module:Particles - Revision history
2025-05-27T19:59:26Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.2
https://en.wikipedia.org/w/index.php?title=Module:Particles&diff=831353959&oldid=prev
Johnuniq: better error message if a particle has no link defined
2018-03-20T04:25:52Z
<p>better error message if a particle has no link defined</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 04:25, 20 March 2018</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 99:</td>
<td colspan="2" class="diff-lineno">Line 99:</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 prefix, suffix</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 prefix, suffix</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> if wantLink then</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> if wantLink then</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> prefix = '[[' .. (particle.link or quit()) .. '|'</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> prefix = '[[' .. (particle.link or quit(<ins style="font-weight: bold; text-decoration: none;">'has no link defined'</ins>)) .. '|'</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> suffix = ']]'</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> suffix = ']]'</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> else</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> else</div></td>
</tr>
<tr>
<td colspan="2" class="diff-lineno">Line 105:</td>
<td colspan="2" class="diff-lineno">Line 105:</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> suffix = ''</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> suffix = ''</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> end</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> end</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> local symbol = particle[1] or quit()</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> local symbol = particle[1] or quit(<ins style="font-weight: bold; text-decoration: none;">'has no symbol defined'</ins>)</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> if particle.anti then</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> if particle.anti then</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> symbol = '<span style="text-decoration:overline;">' .. symbol .. '</span>'</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> symbol = '<span style="text-decoration:overline;">' .. symbol .. '</span>'</div></td>
</tr>
</table>
Johnuniq
https://en.wikipedia.org/w/index.php?title=Module:Particles&diff=830971834&oldid=prev
Johnuniq: efficient implementation of Template:Subatomic particle for List of baryons or other related articles with template expansion size problem
2018-03-18T00:30:09Z
<p>efficient implementation of <a href="/wiki/Template:Subatomic_particle" title="Template:Subatomic particle">Template:Subatomic particle</a> for <a href="/wiki/List_of_baryons" title="List of baryons">List of baryons</a> or other related articles with template expansion size problem</p>
<p><b>New page</b></p><div>-- Low-overhead version of {{Subatomic particle|...}} to avoid exceeding<br />
-- template include size at [[List of baryons]].<br />
<br />
local particleTable, supsub<br />
<br />
local function stripToNil(text)<br />
-- If text is a string, return its trimmed content, or nil if empty.<br />
-- Otherwise return text (which may, for example, be nil).<br />
if type(text) == 'string' then<br />
text = text:match('(%S.-)%s*$')<br />
end<br />
return text<br />
end<br />
<br />
local BREAK = "__BR__"<br />
<br />
-- A group is a list of one or more particles with optional separating text.<br />
-- Some items are defined with special meanings:<br />
-- Parameter Output<br />
-- / " / "<br />
-- + " + "<br />
-- or " or "<br />
-- seen " (seen) "<br />
-- _word1_word2 " word1 word2" (wordN is any text)<br />
-- (text) "(text)" (text is any text)<br />
-- br "<br />" (and separates the group into logical lines)<br />
-- Each logical line in the final text is in a nowrap span.<br />
local Group<br />
Group = {<br />
add = function (self, item)<br />
if item ~= nil then<br />
if item == BREAK then<br />
self:purgeCurrent()<br />
else<br />
self.nrCurrent = self.nrCurrent + 1<br />
self.current[self.nrCurrent] = item<br />
end<br />
end<br />
end,<br />
new = function ()<br />
return setmetatable({<br />
nrCurrent = 0,<br />
current = {},<br />
nrLines = 0,<br />
lines = {},<br />
}, Group)<br />
end,<br />
purgeCurrent = function (self)<br />
if self.nrCurrent > 0 then<br />
self.nrLines = self.nrLines + 1<br />
self.lines[self.nrLines] =<br />
'<span style="white-space:nowrap;">' ..<br />
table.concat(self.current) ..<br />
'</span>'<br />
self.nrCurrent = 0<br />
self.current = {}<br />
end<br />
end,<br />
text = function (self)<br />
self:purgeCurrent()<br />
return table.concat(self.lines, '<br />')<br />
end,<br />
}<br />
Group.__index = Group<br />
<br />
local keyitems = {<br />
['/'] = " / ",<br />
['+'] = " + ",<br />
['or'] = " or ",<br />
['seen'] = " (seen) ",<br />
['br'] = BREAK,<br />
}<br />
<br />
local function expand(item, wantLink)<br />
-- Return text after expanding given item.<br />
-- Throw an error if item is not recognized.<br />
local function quit(reason)<br />
reason = reason or 'has an invalid definition'<br />
error('Particle "' .. item .. '" ' .. reason, 0)<br />
end<br />
local function su(sup, sub, align)<br />
local options = {<br />
align = align,<br />
lineHeight = '1.0em',<br />
}<br />
return supsub(sup, sub, options)<br />
end<br />
local kw = keyitems[item]<br />
if kw then<br />
return kw<br />
end<br />
if item:sub(1, 1) == '_' then<br />
return item:gsub('_', ' ')<br />
end<br />
if item:sub(1, 1) == '(' and item:sub(-1) == ')' then<br />
return item -- no space wanted<br />
end<br />
local particle = particleTable[item:lower()] or quit('is not defined')<br />
local prefix, suffix<br />
if wantLink then<br />
prefix = '[[' .. (particle.link or quit()) .. '|'<br />
suffix = ']]'<br />
else<br />
prefix = ''<br />
suffix = ''<br />
end<br />
local symbol = particle[1] or quit()<br />
if particle.anti then<br />
symbol = '<span style="text-decoration:overline;">' .. symbol .. '</span>'<br />
end<br />
return<br />
prefix ..<br />
su(particle.TL, particle.BL, 'r') ..<br />
symbol ..<br />
su(particle.TR, particle.BR, 'l') ..<br />
suffix<br />
end<br />
<br />
local function main(frame, wantLink)<br />
-- Arguments are passed using #invoke in an article to avoid double-expansion.<br />
local sandbox = frame:getTitle():find('sandbox', 1, true) and '/sandbox' or ''<br />
particleTable = mw.loadData('Module:Particles/data' .. sandbox).particles<br />
supsub = require('Module:Su')._main<br />
local group = Group.new()<br />
for _, arg in ipairs(frame.args) do<br />
arg = stripToNil(arg)<br />
if arg then<br />
group:add(expand(arg, wantLink))<br />
end<br />
end<br />
return group:text()<br />
end<br />
<br />
local function link(frame)<br />
return main(frame, true)<br />
end<br />
<br />
local function nolink(frame)<br />
return main(frame, false)<br />
end<br />
<br />
return {<br />
link = link,<br />
nolink = nolink,<br />
}</div>
Johnuniq