https://en.wikipedia.org/w/index.php?action=history&feed=atom&title=Module%3ATransclude_DYKModule:Transclude DYK - Revision history2025-06-11T04:55:17ZRevision history for this page on the wikiMediaWiki 1.45.0-wmf.4https://en.wikipedia.org/w/index.php?title=Module:Transclude_DYK&diff=851945756&oldid=prevCertes: For use in portals which display randomly selected "Did You Know?" entries2018-07-25T16:07:18Z<p>For use in portals which display randomly selected "Did You Know?" entries</p>
<p><b>New page</b></p><div>local p = {}<br />
<br />
-- Transclude randomly selected "Did you know?" entries<br />
function p.main(frame)<br />
-- args = { 1,2,... = page names, paragraphs = list e.g. "1,3-5", 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("No page name given")<br />
local title = mw.title.new(page) or error("Missing input page " .. page)<br />
local text = title:getContent() or error("No content for page " .. page)<br />
<br />
-- Limit to the DYK section if present<br />
local sectionstart = mw.ustring.find(text, "\n==''Did you know?'' articles==", 1, true)<br />
if sectionstart then<br />
local sectionend = mw.ustring.find(text, "\n==", 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, "\n%*[.…%s]*([^\n]+)") do<br />
if not mw.ustring.find(entry, "article's talk page missing blurb", 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] = "*... " .. entries[j], entries[i]<br />
end<br />
<br />
-- Return the first n entries<br />
text = table.concat(entries, "\n", 1, n)<br />
return frame:preprocess(text)<br />
end<br />
<br />
return p</div>Certes