https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3APerson_weight%2Fsandbox Module:Person weight/sandbox - Revision history 2025-06-07T19:12:21Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.4 https://en.wikipedia.org/w/index.php?title=Module:Person_weight/sandbox&diff=958976825&oldid=prev Zyxw: ‎ Remove periods or commas after unit names. Fixes trailing character after single unit conversion. Fixes no conversion when multiple units separated by either character. 2020-05-26T15:35:31Z <p>‎ Remove periods or commas after unit names. Fixes trailing character after single unit conversion. Fixes no conversion when multiple units separated by either character.</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 15:35, 26 May 2020</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 4:</td> <td colspan="2" class="diff-lineno">Line 4:</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 function clean_weight(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>local function clean_weight(s)</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;"><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> s = mw.ustring.gsub(s, 'kilogram', 'kg')</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> s = mw.ustring.gsub(s, 'kilogram', 'kg')</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_7_2_rhs">&#x26AB;</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_3_0_lhs"></a> s = mw.ustring.gsub(s, 'stone', 'st')</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_5_2_rhs">&#x26AB;</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_3_1_lhs"></a> s = mw.ustring.gsub(s, 'pound', 'lb')</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> s = mw.ustring.gsub(s, 'kgs', 'kg')</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> s = mw.ustring.gsub(s, 'kgs', 'kg')</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> s = mw.ustring.gsub(s, 'kg[%.,]', 'kg')</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;"><br /></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_3_1_lhs">&#x26AB;</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_5_2_rhs"></a> s = mw.ustring.gsub(s, 'pound', 'lb')</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> s = mw.ustring.gsub(s, 'lbs', 'lb')</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> s = mw.ustring.gsub(s, 'lbs', 'lb')</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> s = mw.ustring.gsub(s, 'lb[%.,]', 'lb')</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;"><br /></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_3_0_lhs">&#x26AB;</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_7_2_rhs"></a> s = mw.ustring.gsub(s, 'stone', 'st')</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> s = mw.ustring.gsub(s, 'sts', 'st')</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> s = mw.ustring.gsub(s, 'sts', 'st')</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> s = mw.ustring.gsub(s, 'st[%.,]', 'st')</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;"><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> s = mw.ustring.gsub(s, '%[%[kg%]%]s', '[[Kilogram|kg]]')</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> s = mw.ustring.gsub(s, '%[%[kg%]%]s', '[[Kilogram|kg]]')</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;"><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> </table> Zyxw https://en.wikipedia.org/w/index.php?title=Module:Person_weight/sandbox&diff=958941134&oldid=prev Zyxw: Test fix for when Convert template outputs [&thinsp;[kilogram]&thinsp;]s - module changed that to [&thinsp;[kg]&thinsp;]s - should be [&thinsp;[Kilograms|kg]&thinsp;] instead. 2020-05-26T11:41:08Z <p>Test fix for when Convert template outputs [ [kilogram] ]s - module changed that to [ [kg] ]s - should be [ [Kilograms|kg] ] instead.</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 11:41, 26 May 2020</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 10:</td> <td colspan="2" class="diff-lineno">Line 10:</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> s = mw.ustring.gsub(s, 'lbs', 'lb')</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> s = mw.ustring.gsub(s, 'lbs', 'lb')</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> s = mw.ustring.gsub(s, 'sts', 'st')</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> s = mw.ustring.gsub(s, 'sts', 'st')</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> s = mw.ustring.gsub(s, '%[%[kg%]%]s', '[[Kilogram|kg]]')</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;"><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> return 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 s</div></td> </tr> </table> Zyxw https://en.wikipedia.org/w/index.php?title=Module:Person_weight/sandbox&diff=958911789&oldid=prev Zyxw: Create sandbox version of Module:Person weight 2020-05-26T08:05:13Z <p>Create sandbox version of <a href="/wiki/Module:Person_weight" title="Module:Person weight">Module:Person weight</a></p> <p><b>New page</b></p><div>-- This module implements [[Template:Infobox person/weight]]<br /> <br /> local p = {}<br /> <br /> local function clean_weight(s)<br /> s = mw.ustring.gsub(s, &#039;kilogram&#039;, &#039;kg&#039;)<br /> s = mw.ustring.gsub(s, &#039;stone&#039;, &#039;st&#039;)<br /> s = mw.ustring.gsub(s, &#039;pound&#039;, &#039;lb&#039;)<br /> s = mw.ustring.gsub(s, &#039;kgs&#039;, &#039;kg&#039;)<br /> s = mw.ustring.gsub(s, &#039;lbs&#039;, &#039;lb&#039;)<br /> s = mw.ustring.gsub(s, &#039;sts&#039;, &#039;st&#039;)<br /> <br /> return s<br /> end<br /> <br /> local function isnumber(s)<br /> if s then<br /> s = mw.ustring.gsub(s, &#039;%+%s*%d+%s*/%s*%d+%s*$&#039;, &#039;&#039;)<br /> s = mw.ustring.gsub(s, &#039;%s*[–%-]%s*&#039;, &#039;&#039;)<br /> return tonumber(s)<br /> end<br /> return nil<br /> end<br /> <br /> local function get_convert_weight_args(s, kg_stlb, lb_stlb)<br /> local prefer_m = (prefer or &#039;&#039;) == &#039;m&#039;<br /> local force_m = (enforce or &#039;&#039;) == &#039;m&#039;<br /> local prefer_cm = (prefer or &#039;&#039;) == &#039;cm&#039;<br /> local force_cm = (enforce or &#039;&#039;) == &#039;cm&#039;<br /> <br /> unconverted = clean_weight(s or &#039;&#039;) -- basic unit cleaning<br /> <br /> s = mw.ustring.gsub(unconverted, &#039;&amp;[Nn][Bb][Ss][Pp];&#039;, &#039; &#039;)<br /> <br /> local kg = mw.ustring.find(s, &#039;kg&#039;)<br /> local st = mw.ustring.find(s, &#039;st&#039;)<br /> local lb = mw.ustring.find(s, &#039;lb&#039;)<br /> <br /> if kg == nil and st == nil and lb == nil then<br /> return &#039;&#039;, unconverted<br /> end<br /> <br /> if kg ~= nil and st == nil and lb == nil then<br /> local n = mw.ustring.sub(s, 1, kg - 1)<br /> if isnumber(n) then<br /> return {n,&#039;kg&#039;,kg_stlb and &#039;lb stlb&#039; or &#039;lb&#039;,0,[&#039;abbr&#039;]=&#039;on&#039;}, mw.ustring.sub(s, kg+2)<br /> end<br /> return &#039;&#039;, unconverted<br /> end<br /> <br /> if lb ~= nil and kg == nil and st == nil then<br /> local n = mw.ustring.sub(s, 1, lb - 1)<br /> if isnumber(n) then<br /> return {n,&#039;lb&#039;,lb_stlb and &#039;kg stlb&#039; or &#039;kg&#039;,0,[&#039;abbr&#039;]=&#039;on&#039;}, mw.ustring.sub(s, lb+2)<br /> end<br /> return &#039;&#039;, unconverted<br /> end<br /> <br /> if st ~= nil and kg == nil and lb == nil then<br /> local n = mw.ustring.sub(s, 1, st - 1)<br /> if isnumber(n) then<br /> return {n,&#039;st&#039;,&#039;lb kg&#039;,0,[&#039;abbr&#039;]=&#039;on&#039;}, mw.ustring.sub(s, st+2)<br /> end<br /> return &#039;&#039;, unconverted<br /> end<br /> <br /> if lb ~= nil and st ~=nil and kg == nil then<br /> local n1 = mw.ustring.sub(s, 1, st - 1)<br /> local n2 = mw.ustring.sub(s, st+2, lb - 1)<br /> if isnumber(n1) and isnumber(n2) then<br /> return {n1,&#039;st&#039;,n2,&#039;lb&#039;, &#039;lb kg&#039;,0,[&#039;abbr&#039;]=&#039;on&#039;}, mw.ustring.sub(s, lb+2)<br /> end<br /> return &#039;&#039;, unconverted<br /> end<br /> <br /> return &#039;&#039;, unconverted<br /> end<br /> <br /> function convert_weight(frame, args)<br /> local targs, str = get_convert_weight_args(args[1], (args[&#039;kg-stlb&#039;] or &#039;&#039;) ~= &#039;&#039;, (args[&#039;lb-stlb&#039;] or &#039;&#039;) ~= &#039;&#039;)<br /> <br /> if type(targs) == &#039;table&#039; then<br /> return frame:expandTemplate{ title = &#039;convert&#039;, args = targs} .. str<br /> else<br /> return str<br /> end<br /> end<br /> <br /> function p.weight(frame)<br /> return convert_weight(frame, frame.args[1] and frame.args or frame:getParent().args)<br /> end<br /> <br /> return p</div> Zyxw