https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ATransclude_DYK Module:Transclude DYK - Revision history 2025-06-11T04:55:17Z Revision history for this page on the wiki MediaWiki 1.45.0-wmf.4 https://en.wikipedia.org/w/index.php?title=Module:Transclude_DYK&diff=851945756&oldid=prev Certes: For use in portals which display randomly selected "Did You Know?" entries 2018-07-25T16:07:18Z <p>For use in portals which display randomly selected &quot;Did You Know?&quot; entries</p> <p><b>New page</b></p><div>local p = {}<br /> <br /> -- Transclude randomly selected &quot;Did you know?&quot; entries<br /> function p.main(frame)<br /> -- args = { 1,2,... = page names, paragraphs = list e.g. &quot;1,3-5&quot;, files = list, more = text}<br /> local args = {} -- args[k] = frame.args[k] or frame:getParent().args[k] for all k in either (numeric or not)<br /> for k, v in pairs(frame:getParent().args) do args[k] = v end<br /> for k, v in pairs(frame.args) do args[k] = v end -- args from a Lua call have priority over parent args from template<br /> <br /> -- Read the input page<br /> local page = args[1] or error(&quot;No page name given&quot;)<br /> local title = mw.title.new(page) or error(&quot;Missing input page &quot; .. page)<br /> local text = title:getContent() or error(&quot;No content for page &quot; .. page)<br /> <br /> -- Limit to the DYK section if present<br /> local sectionstart = mw.ustring.find(text, &quot;\n==&#039;&#039;Did you know?&#039;&#039; articles==&quot;, 1, true)<br /> if sectionstart then<br /> local sectionend = mw.ustring.find(text, &quot;\n==&quot;, sectionstart + 1, true) or -1<br /> text = mw.ustring.sub(text, sectionstart, sectionend)<br /> end<br /> <br /> -- Parse the entries<br /> entries = {}<br /> for entry in mw.ustring.gmatch(text, &quot;\n%*[.…%s]*([^\n]+)&quot;) do<br /> if not mw.ustring.find(entry, &quot;article&#039;s talk page missing blurb&quot;, 1, true) then<br /> table.insert(entries, entry)<br /> end<br /> end<br /> <br /> -- Swap some random entries into the first n positions<br /> local n = math.min(#entries, args.count or 10) -- the number of entries to produce<br /> math.randomseed(os.time())<br /> for i = 1, n do<br /> j = math.random(i, #entries)<br /> entries[i], entries[j] = &quot;*... &quot; .. entries[j], entries[i]<br /> end<br /> <br /> -- Return the first n entries<br /> text = table.concat(entries, &quot;\n&quot;, 1, n)<br /> return frame:preprocess(text)<br /> end<br /> <br /> return p</div> Certes