https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ATemplateDataGenerator Module:TemplateDataGenerator - Revision history 2025-05-26T01:48:03Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.2 https://en.wikipedia.org/w/index.php?title=Module:TemplateDataGenerator&diff=567535625&oldid=prev Salix alba: don't really want to wrap the result in <pre>, better translation of parameters for getBlock 2013-08-07T13:06:24Z <p>don&#039;t really want to wrap the result in &lt;pre&gt;, better translation of parameters for getBlock</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 13:06, 7 August 2013</td> </tr><tr> <td colspan="2" class="diff-lineno">Line 134:</td> <td colspan="2" class="diff-lineno">Line 134:</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 p = {};</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 p = {};</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" 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>function p.getBlock( <del style="font-weight: bold; text-decoration: none;">about</del>, <del style="font-weight: bold; text-decoration: none;">ahead</del>, alphabetical )</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>function p.getBlock( <ins style="font-weight: bold; text-decoration: none;">pagetitle</ins>, <ins style="font-weight: bold; text-decoration: none;">namespace</ins>, alphabetical )</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> -- Precondition:</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> -- Precondition:</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;">about </del> -- string; page title related to template code</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;">pagetitle</ins> -- string; page title related to template code</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;">ahead </del> -- string, number or nil; namespace (Template:)</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;">namespace</ins> -- string, number or nil; namespace (Template:)</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> -- alphabetical -- boolean or nil; sort parameter list</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> -- alphabetical -- boolean or nil; sort parameter list</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> -- Uses:</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> -- Uses:</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> -- fun()</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> -- fun()</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 title = mw.title.makeTitle( <del style="font-weight: bold; text-decoration: none;">ahead</del> or 10, <del style="font-weight: bold; text-decoration: none;">about</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> local title = mw.title.makeTitle( <ins style="font-weight: bold; text-decoration: none;">namespace</ins> or 10, <ins style="font-weight: bold; text-decoration: none;">pagetitle</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> local lucky, r = pcall( fun, title, alphabetical );</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 lucky, r = pcall( fun, title, alphabetical );</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 r;</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 r;</div></td> </tr> <tr> <td colspan="2" class="diff-lineno">Line 161:</td> <td colspan="2" class="diff-lineno">Line 161:</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> local lucky, r = pcall( fun, mw.title.getCurrentTitle(), luxury );</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 lucky, r = pcall( fun, mw.title.getCurrentTitle(), luxury );</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> return "&lt;pre&gt;" .. r .. "&lt;/pre&gt;";</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;"> --</ins> return "&lt;pre&gt;" .. r .. "&lt;/pre&gt;";</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 r;</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>end -- .f()</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 -- .f()</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> Salix alba https://en.wikipedia.org/w/index.php?title=Module:TemplateDataGenerator&diff=567291380&oldid=prev PerfektesChaos: Created from w:de:Module:Vorlage:TemplateDataGenerator 2013-08-05T18:16:28Z <p>Created from <a href="https://de.wikipedia.org/wiki/Module:Vorlage:TemplateDataGenerator" class="extiw" title="de:Module:Vorlage:TemplateDataGenerator">w:de:Module:Vorlage:TemplateDataGenerator</a></p> <p><b>New page</b></p><div>--[=[ 2013-08-05<br /> {{TemplateDataGenerator}}<br /> Basic idea by [[w:en:User:Salix alba]]<br /> ]=]<br /> <br /> <br /> <br /> local config = {<br /> luxury = false, -- default alphabetical order for parameter list<br /> start = false, -- preceeding lines<br /> shift = &quot; &quot;, -- (not used now) indentation, like &quot; &quot; or &quot;\t&quot;<br /> suffix = false, -- following lines<br /> scheme = [=[&quot;%s&quot;:<br /> { &quot;label&quot;: &quot;%s&quot;,<br /> &quot;description&quot;: &quot;&quot;,<br /> &quot;type&quot;: &quot;string&quot;,<br /> &quot;required&quot;: false<br /> }]=]<br /> -- config.scheme has placeholders %s<br /> -- for the parameter name and for &quot;label&quot;.<br /> -- One of various indentation styles.<br /> -- Feel free to compose a different one, also using config.shift etc.<br /> };<br /> <br /> <br /> <br /> local function factory( analyze, alphabetical )<br /> -- Make parameter sequence from template source text<br /> -- analyze -- string; template source text<br /> -- alphabetical -- boolean or nil; sort parameter list<br /> -- Return:<br /> -- table (sequence) with parameter names<br /> local i, s;<br /> local r = { };<br /> for s in analyze:gmatch( &quot;{{{([^|}\n]+)&quot; ) do<br /> for i = 1, #r do<br /> if r[ i ] == s then<br /> s = false;<br /> break; -- for i<br /> end<br /> end -- for i<br /> if s then<br /> table.insert( r, s );<br /> end<br /> end -- for s in :gmatch()<br /> if alphabetical then<br /> table.sort( r, nil );<br /> end<br /> return r;<br /> end -- factory()<br /> <br /> <br /> <br /> local function format( analyze, alphabetical )<br /> -- Make JSON code from template source text<br /> -- analyze -- string; template source text<br /> -- alphabetical -- boolean or nil; sort parameter list<br /> -- Return:<br /> -- string with JSON code<br /> -- Uses:<br /> -- &gt; config.shift<br /> -- &gt; config.scheme<br /> -- factory()<br /> local i;<br /> local params = factory( analyze, alphabetical );<br /> local r = &#039;{ &quot;description&quot;: &quot;&quot;,\n&#039;;<br /> -- local shift = config.shift or &quot;&quot;; -- currently unused<br /> local start = &quot; &quot;;<br /> local show, symbol;<br /> r = r .. &#039; &quot;params&quot;: { &#039;;<br /> for i = 1, #params do<br /> if i &gt; 1 then<br /> r = string.format( &quot;%s,\n%s &quot;, r, start );<br /> end<br /> symbol = params[ i ];<br /> if mw.ustring.match( symbol, &quot;^%u%u&quot; ) then<br /> show = mw.ustring.sub( symbol, 1, 1 ) ..<br /> mw.ustring.lower( mw.ustring.sub( symbol, 2 ) );<br /> else<br /> show = &quot;&quot;;<br /> end<br /> r = r .. string.format( config.scheme, symbol, show );<br /> -- common JSON pattern is ASCII; string.format() will do<br /> end -- for i<br /> r = string.format( &quot;%s\n%s}\n}&quot;, r, start );<br /> return r;<br /> end -- format()<br /> <br /> <br /> <br /> local function fun( attempt, alphabetical )<br /> -- Retrieve used template params and build TemplateData skeleton<br /> -- Precondition:<br /> -- attempt -- mw.title object; related to template code<br /> -- alphabetical -- boolean or nil; sort parameter list<br /> -- Return:<br /> -- string to be applied<br /> -- Uses:<br /> -- &gt; config.luxury<br /> -- &gt; config.start<br /> -- &gt; config.suffix<br /> -- format()<br /> local r;<br /> local source = string.match( attempt.baseText .. &quot;/&quot;,<br /> &quot;^([^/]+)/&quot; );<br /> -- ensure top page in NS with no subpage property<br /> -- note that pattern is ASCII; string.match() will do<br /> local title = mw.title.makeTitle( attempt.namespace, source );<br /> if title.exists then<br /> local luxury = config.luxury;<br /> local spec = &quot;%s&lt;templatedata&gt;\n%s\n&lt;/templatedata&gt;\n%s&quot;;<br /> if type( alphabetical ) == &quot;boolean&quot; then<br /> luxury = alphabetical;<br /> end<br /> if config.start then<br /> r = config.start .. &quot;\n&quot;;<br /> else<br /> r = &quot;&quot;;<br /> end<br /> r = string.format( spec,<br /> r,<br /> format( title:getContent(), luxury ),<br /> config.suffix or &quot;&quot; );<br /> -- note that format spec is ASCII only; string.format() will do<br /> else -- test only<br /> r = &quot;ERROR * no page &quot; .. title.fullText;<br /> end<br /> return r;<br /> end -- fun()<br /> <br /> <br /> <br /> -- Export<br /> local p = {};<br /> <br /> function p.getBlock( about, ahead, alphabetical )<br /> -- Precondition:<br /> -- about -- string; page title related to template code<br /> -- ahead -- string, number or nil; namespace (Template:)<br /> -- alphabetical -- boolean or nil; sort parameter list<br /> -- Uses:<br /> -- fun()<br /> local title = mw.title.makeTitle( ahead or 10, about );<br /> local lucky, r = pcall( fun, title, alphabetical );<br /> return r;<br /> end -- .getBlock()<br /> <br /> <br /> <br /> function p.f( frame )<br /> -- Precondition:<br /> -- frame -- object<br /> -- Invoked on a template page or template subpage.<br /> -- Uses:<br /> -- fun()<br /> local luxury;<br /> local parental = frame:getParent().args;<br /> local sort = parental[ 1 ] or parental[ &quot;1&quot; ] or parental.sort;<br /> if sort then<br /> luxury = ( tonumber( sort) == 1 );<br /> end<br /> local lucky, r = pcall( fun, mw.title.getCurrentTitle(), luxury );<br /> return &quot;&lt;pre&gt;&quot; .. r .. &quot;&lt;/pre&gt;&quot;;<br /> end -- .f()<br /> <br /> return p;</div> PerfektesChaos