https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3AChange%2Fsandbox
Module:Change/sandbox - Revision history
2025-05-29T03:06:53Z
Revision history for this page on the wiki
MediaWiki 1.45.0-wmf.2
https://en.wikipedia.org/w/index.php?title=Module:Change/sandbox&diff=1149260702&oldid=prev
Lemondoge: Simplification
2023-04-11T03:46:23Z
<p>Simplification</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 03:46, 11 April 2023</td>
</tr><tr>
<td colspan="2" class="diff-lineno">Line 119:</td>
<td colspan="2" class="diff-lineno">Line 119:</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 dsp == 'row2' 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 dsp == 'row2' 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> return style .. '|' .. s .. pre2 .. n2 .. suf2 .. s</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> return style .. '|' .. s .. pre2 .. n2 .. suf2 .. s</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_6_0_lhs">⚫</a></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><a name="movedpara_1_0_rhs"></a> .. '\n|' .. style .. '|' .. pcrf, errorflag</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_4_0_lhs">⚫</a></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><a name="movedpara_1_1_rhs"></a> <ins style="font-weight: bold; text-decoration: none;">elseif</ins> inv == 'off' then</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_6_2_lhs">⚫</a></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><a name="movedpara_1_2_rhs"></a> return style .. '|' .. s .. pre1 .. <ins style="font-weight: bold; text-decoration: none;">n1</ins> .. suf1 .. s</div></td>
</tr>
<tr>
<td colspan="2" class="diff-empty diff-side-deleted"></td>
<td class="diff-marker"><a class="mw-diff-movedpara-right" title="Paragraph was moved. Click to jump to old location." href="#movedpara_6_3_lhs">⚫</a></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><a name="movedpara_1_3_rhs"></a> .. '\n|' .. style .. '|' .. s .. pre2 .. <ins style="font-weight: bold; text-decoration: none;">n2</ins> .. suf2 .. s</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> .. '\n|' .. style .. '|' .. pcrf, errorflag</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> .. '\n|' .. style .. '|' .. pcrf, errorflag</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-empty diff-side-deleted"></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> return style .. '|' .. s .. pre1 .. n2 .. suf1 .. s</div></td>
</tr>
<tr>
<td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_1_1_rhs">⚫</a></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><a name="movedpara_4_0_lhs"></a> <del style="font-weight: bold; text-decoration: none;"> if</del> inv == 'off' then</div></td>
<td colspan="2" class="diff-empty diff-side-added"></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> <del style="font-weight: bold; text-decoration: none;">return</del> style .. '|' .. s .. <del style="font-weight: bold; text-decoration: none;">pre1</del> .. n1 .. <del style="font-weight: bold; text-decoration: none;">suf1</del> .. s</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> <ins style="font-weight: bold; text-decoration: none;">.. '\n|' ..</ins> style .. '|' .. s .. <ins style="font-weight: bold; text-decoration: none;">pre2</ins> .. n1 .. <ins style="font-weight: bold; text-decoration: none;">suf2</ins> .. s</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><del style="font-weight: bold; text-decoration: none;"> </del> .. '\n|' .. style .. '|' .. <del style="font-weight: bold; text-decoration: none;">s</del> <del style="font-weight: bold; text-decoration: none;">.. pre2 .. n2 .. suf2 .. s</del></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> .. '\n|' .. style .. '|' .. <ins style="font-weight: bold; text-decoration: none;">pcrf,</ins> <ins style="font-weight: bold; text-decoration: none;">errorflag</ins></div></td>
</tr>
<tr>
<td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_1_0_rhs">⚫</a></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><a name="movedpara_6_0_lhs"></a><del style="font-weight: bold; text-decoration: none;"> </del> .. '\n|' .. style .. '|' .. pcrf, errorflag</div></td>
<td colspan="2" class="diff-empty diff-side-added"></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> else</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_1_2_rhs">⚫</a></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><a name="movedpara_6_2_lhs"></a><del style="font-weight: bold; text-decoration: none;"> </del> return style .. '|' .. s .. pre1 .. <del style="font-weight: bold; text-decoration: none;">n2</del> .. suf1 .. s</div></td>
<td colspan="2" class="diff-empty diff-side-added"></td>
</tr>
<tr>
<td class="diff-marker"><a class="mw-diff-movedpara-left" title="Paragraph was moved. Click to jump to new location." href="#movedpara_1_3_rhs">⚫</a></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><a name="movedpara_6_3_lhs"></a><del style="font-weight: bold; text-decoration: none;"> </del> .. '\n|' .. style .. '|' .. s .. pre2 .. <del style="font-weight: bold; text-decoration: none;">n1</del> .. suf2 .. s</div></td>
<td colspan="2" class="diff-empty diff-side-added"></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> .. '\n|' .. style .. '|' .. pcrf, errorflag</div></td>
<td colspan="2" class="diff-empty diff-side-added"></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> end</div></td>
<td colspan="2" class="diff-empty diff-side-added"></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"></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>
</table>
Lemondoge
https://en.wikipedia.org/w/index.php?title=Module:Change/sandbox&diff=1149260663&oldid=prev
Lemondoge: Create sandbox version of Module:Change
2023-04-11T03:45:52Z
<p>Create sandbox version of <a href="/wiki/Module:Change" title="Module:Change">Module:Change</a></p>
<p><b>New page</b></p><div>-- This implements {{change}}<br />
local p = {}<br />
<br />
local function ntsh(outvalue)<br />
local sortkey = '0000000000000000000'<br />
if outvalue == nil then<br />
return '<span style="display:none" data-sort-value="' .. sortkey .. '♠"></span>'<br />
end<br />
<br />
-- This code was copied from [[Template:Convert]] <br />
if outvalue == 0 then<br />
sortkey = '5000000000000000000'<br />
else<br />
local mag = math.floor(math.log10(math.abs(outvalue)) + 1e-14)<br />
local prefix<br />
if outvalue > 0 then<br />
prefix = 7000 + mag<br />
else<br />
prefix = 2999 - mag<br />
outvalue = outvalue + 10^(mag+1)<br />
end<br />
sortkey = string.format('%d', prefix) .. string.format('%015.0f', math.floor(outvalue * 10^(14-mag)))<br />
end<br />
return '<span style="display:none" data-sort-value="' .. sortkey .. '♠"></span>'<br />
end<br />
<br />
local function trim(s)<br />
return s:match('^%s*(.-)%s*$')<br />
end<br />
<br />
local function isnotempty(s)<br />
return s and trim(s) ~= ''<br />
end<br />
<br />
function change(args)<br />
local rnd = require('Module:Math')._round<br />
local prec_format = require('Module:Math')._precision_format<br />
local lang = mw.getContentLanguage()<br />
local function formatnum(num)<br />
return lang:parseFormattedNumber(num) and lang:formatNum(lang:parseFormattedNumber(num)) or num<br />
end<br />
<br />
local errorflag = nil<br />
<br />
local dsp = args['disp'] or 'row'<br />
local inv = args['invert'] or 'off'<br />
local srt = args['sort'] or ((isnotempty(args['pre']) or isnotempty(args['sort'])) and 'on' or 'off')<br />
local n1 = (inv == 'on') and tonumber(lang:parseFormattedNumber(args['2'])) or tonumber(lang:parseFormattedNumber(args['1']))<br />
local n2 = (inv == 'on') and tonumber(lang:parseFormattedNumber(args['1'])) or tonumber(lang:parseFormattedNumber(args['2']))<br />
local dec = args['dec'] or '2'<br />
local s = ((args['italics'] or 'off') == 'on' and "''" or "")<br />
.. ((args['bold'] or 'off') == 'on' and "'''" or "")<br />
<br />
local pc, pcr, pcrf = 'NA', 'NA'<br />
<br />
if n1 and n2 and n1 ~= 0 then<br />
pc = 100*(n2/n1 - 1)<br />
pcr = rnd(pc, dec)<br />
if pcr > 0 then<br />
pcrf = '<span style="color:green">' ..<br />
s .. '+' .. prec_format(pc, dec) .. '%' .. s .. '</span>'<br />
elseif pcr < 0 then<br />
pcrf = '<span style="color:red">' ..<br />
s .. prec_format(pc, dec) .. '%' .. s .. '</span>'<br />
else<br />
pcrf = s .. prec_format(0, dec) .. '%' .. s<br />
end<br />
pcrf = ntsh(pcr) .. pcrf<br />
else<br />
pcrf = ntsh(nil) .. s .. 'NA' .. s<br />
if n1 == nil or n2 == nil then<br />
errorflag = 1<br />
end<br />
end<br />
<br />
if dsp == 'out' then<br />
return pcrf, errorflag<br />
else<br />
local pre1 = args['pre1'] or args['pre'] or ''<br />
local pre2 = args['pre2'] or args['pre'] or ''<br />
local suf1 = args['suf1'] or args['suf'] or ''<br />
local suf2 = args['suf2'] or args['suf'] or ''<br />
<br />
local rspn = 'rowspan=' .. (args['rowspan'] or '1') .. ' '<br />
local algn = 'text-align:' .. (args['align'] or 'right') .. ';'<br />
local bg = 'background-color:' .. (args['bgcolour'] or args['bgcolor'] or 'inherit') .. ';'<br />
<br />
if rspn == 'rowspan=1 ' then rspn = '' end<br />
if bg == 'background-color:inherit;' then bg = '' end<br />
local style = rspn .. 'style="' .. algn .. bg .. '"'<br />
<br />
local sk1, sk2 = '', ''<br />
<br />
if srt == 'on' then<br />
sk1 = ntsh(n1)<br />
sk2 = ntsh(n2)<br />
end<br />
<br />
if n1 ~= nil then<br />
if n1 < 0 then<br />
n1 = '−' .. formatnum(-1*n1)<br />
else<br />
n1 = formatnum(n1)<br />
end<br />
else<br />
n1 = (inv == 'on') and (args['2'] or '') or (args['1'] or '')<br />
end<br />
<br />
if n2 ~= nil then<br />
if n2 < 0 then<br />
n2 = '−' .. formatnum(-1*n2)<br />
else<br />
n2 = formatnum(n2)<br />
end<br />
else<br />
n2 = (inv == 'on') and (args['1'] or '') or (args['2'] or '')<br />
end<br />
<br />
if dsp == 'row2' then<br />
return style .. '|' .. s .. pre2 .. n2 .. suf2 .. s<br />
.. '\n|' .. style .. '|' .. pcrf, errorflag<br />
else<br />
if inv == 'off' then<br />
return style .. '|' .. s .. pre1 .. n1 .. suf1 .. s<br />
.. '\n|' .. style .. '|' .. s .. pre2 .. n2 .. suf2 .. s<br />
.. '\n|' .. style .. '|' .. pcrf, errorflag<br />
else<br />
return style .. '|' .. s .. pre1 .. n2 .. suf1 .. s<br />
.. '\n|' .. style .. '|' .. s .. pre2 .. n1 .. suf2 .. s<br />
.. '\n|' .. style .. '|' .. pcrf, errorflag<br />
end<br />
end<br />
end<br />
end<br />
<br />
function p.main(frame)<br />
local res, eflag = change((frame.args[1] or frame.args[2]) and frame.args or frame:getParent().args)<br />
if eflag then<br />
res = res .. frame:expandTemplate{title = 'change/error'}<br />
end<br />
return res<br />
end<br />
<br />
return p</div>
Lemondoge