<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://salisford.net/index.php?action=history&amp;feed=atom&amp;title=Module%3AExcerpt%2Ftemplates</id>
	<title>Module:Excerpt/templates - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://salisford.net/index.php?action=history&amp;feed=atom&amp;title=Module%3AExcerpt%2Ftemplates"/>
	<link rel="alternate" type="text/html" href="https://salisford.net/index.php?title=Module:Excerpt/templates&amp;action=history"/>
	<updated>2026-04-30T17:23:29Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.36.1</generator>
	<entry>
		<id>https://salisford.net/index.php?title=Module:Excerpt/templates&amp;diff=3173&amp;oldid=prev</id>
		<title>Cascadia: Created page with &quot;-- Invocation functions for English Wikipedia templates -- May not work properly or at all on other wikis  local e = require(&quot;Module:Excerpt&quot;) local p = {}  -- Shared invocati...&quot;</title>
		<link rel="alternate" type="text/html" href="https://salisford.net/index.php?title=Module:Excerpt/templates&amp;diff=3173&amp;oldid=prev"/>
		<updated>2024-01-07T16:43:19Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;-- Invocation functions for English Wikipedia templates -- May not work properly or at all on other wikis  local e = require(&amp;quot;Module:Excerpt&amp;quot;) local p = {}  -- Shared invocati...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;-- Invocation functions for English Wikipedia templates&lt;br /&gt;
-- May not work properly or at all on other wikis&lt;br /&gt;
&lt;br /&gt;
local e = require(&amp;quot;Module:Excerpt&amp;quot;)&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
-- Shared invocation function used by templates meant for portals&lt;br /&gt;
local function portal(frame, template)&lt;br /&gt;
	local args = e.parseArgs(frame)&lt;br /&gt;
&lt;br /&gt;
	errors = args['errors'] or false -- disable error reporting unless requested&lt;br /&gt;
&lt;br /&gt;
	-- There should be at least one argument except with selected=Foo and Foo=Somepage&lt;br /&gt;
	if #args &amp;lt; 1 and not (template == &amp;quot;selected&amp;quot; and args[template] and args[args[template]]) then&lt;br /&gt;
		return e.wikiError(&amp;quot;noPage&amp;quot;)&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Figure out the page to excerpt&lt;br /&gt;
	local page&lt;br /&gt;
	local candidates = {}&lt;br /&gt;
&lt;br /&gt;
	if template == &amp;quot;lead&amp;quot; then&lt;br /&gt;
		page = args[1]&lt;br /&gt;
		page = mw.text.trim(page)&lt;br /&gt;
		if not page or page == &amp;quot;&amp;quot; then return e.wikiError(&amp;quot;noPage&amp;quot;) end&lt;br /&gt;
		candidates = { page }&lt;br /&gt;
&lt;br /&gt;
	elseif template == &amp;quot;selected&amp;quot; then&lt;br /&gt;
		local key = args[template]&lt;br /&gt;
		local count = #args&lt;br /&gt;
		if tonumber(key) then -- normalise article number into the range 1..#args&lt;br /&gt;
			key = key % count&lt;br /&gt;
			if key == 0 then key = count end&lt;br /&gt;
		end&lt;br /&gt;
		page = args[key]&lt;br /&gt;
		page = mw.text.trim(page)&lt;br /&gt;
		if not page or page == &amp;quot;&amp;quot; then return e.wikiError(&amp;quot;noPage&amp;quot;) end&lt;br /&gt;
		candidates = { page }&lt;br /&gt;
&lt;br /&gt;
	elseif template == &amp;quot;linked&amp;quot; or template == &amp;quot;listitem&amp;quot; then&lt;br /&gt;
		local source = args[1]&lt;br /&gt;
		local text, source = e.getContent(source)&lt;br /&gt;
		if not source then&lt;br /&gt;
			return e.wikiError(&amp;quot;noPage&amp;quot;)&lt;br /&gt;
		elseif not text then&lt;br /&gt;
			return e.wikiError(&amp;quot;noPage&amp;quot;)&lt;br /&gt;
		end&lt;br /&gt;
		local section = args.section&lt;br /&gt;
		if section then -- check relevant section only&lt;br /&gt;
			text = e.getSection(text, section)&lt;br /&gt;
			if not text then return e.wikiError(&amp;quot;sectionNotFound&amp;quot;, section) end&lt;br /&gt;
		end&lt;br /&gt;
		-- Replace annotated links with real links&lt;br /&gt;
		text = mw.ustring.gsub(text, &amp;quot;{{%s*[Aa]nnotated[ _]link%s*|%s*(.-)%s*}}&amp;quot;, &amp;quot;[[%1]]&amp;quot;)&lt;br /&gt;
		if template == &amp;quot;linked&amp;quot; then&lt;br /&gt;
			for candidate in mw.ustring.gmatch(text, &amp;quot;%[%[%s*([^%]|\n]*)&amp;quot;) do table.insert(candidates, candidate) end&lt;br /&gt;
		else -- listitem: first wikilink on a line beginning *, :#, etc. except in &amp;quot;See also&amp;quot; or later section&lt;br /&gt;
			text = mw.ustring.gsub(text, &amp;quot;\n== *See also.*&amp;quot;, &amp;quot;&amp;quot;)&lt;br /&gt;
			for candidate in mw.ustring.gmatch(text, &amp;quot;\n:*[%*#][^\n]-%[%[%s*([^%]|\n]*)&amp;quot;) do table.insert(candidates, candidate) end&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
	elseif template == &amp;quot;random&amp;quot; then&lt;br /&gt;
		for key, value in pairs(args) do&lt;br /&gt;
			if value and type(key) == &amp;quot;number&amp;quot; then table.insert(candidates, value) end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Build an options array for the Excerpt module out of the arguments and the desired defaults&lt;br /&gt;
	local options = {&lt;br /&gt;
		errors = args['errors'] or false,&lt;br /&gt;
		fileargs = args['fileargs'],&lt;br /&gt;
		fileflags = e.numberFlags( args['files'] ),&lt;br /&gt;
		paraflags = e.numberFlags( args['paragraphs'] )&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	-- Select a random candidate and make sure its valid&lt;br /&gt;
	local text&lt;br /&gt;
	local candidateCount = #candidates&lt;br /&gt;
	if candidateCount &amp;gt; 0 then&lt;br /&gt;
		local candidateKey = 1&lt;br /&gt;
		local candidateString&lt;br /&gt;
		local candidateArgs&lt;br /&gt;
		if candidateCount &amp;gt; 1 then math.randomseed(os.time()) end&lt;br /&gt;
		while (not text or text == &amp;quot;&amp;quot;) and candidateCount &amp;gt; 0 do&lt;br /&gt;
			if candidateCount &amp;gt; 1 then candidateKey = math.random(candidateCount) end -- pick a random candidate&lt;br /&gt;
			candidateString = candidates[candidateKey]&lt;br /&gt;
			if candidateString and candidateString ~= &amp;quot;&amp;quot; then&lt;br /&gt;
				-- We have page or [[page]] or [[page|text]], possibly followed by |opt1|opt2...&lt;br /&gt;
				page, candidateArgs = mw.ustring.match(candidateString, &amp;quot;^%s*(%[%b[]%])%s*|?(.*)&amp;quot;)&lt;br /&gt;
				if page and page ~= &amp;quot;&amp;quot; then&lt;br /&gt;
					page = mw.ustring.match(page, &amp;quot;%[%[([^|%]]*)&amp;quot;) -- turn [[page|text]] into page, discarding text&lt;br /&gt;
				else -- we have page or page|opt...&lt;br /&gt;
					page, candidateArgs = mw.ustring.match(candidateString, &amp;quot;%s*([^|]*[^|%s])%s*|?(.*)&amp;quot;)&lt;br /&gt;
				end&lt;br /&gt;
				-- candidate arguments (even if value is &amp;quot;&amp;quot;) have priority over global arguments&lt;br /&gt;
				if candidateArgs and candidateArgs ~= &amp;quot;&amp;quot; then&lt;br /&gt;
					for _, t in pairs(mw.text.split(candidateArgs, &amp;quot;|&amp;quot;)) do&lt;br /&gt;
						local k, v = mw.ustring.match(t, &amp;quot;%s*([^=]-)%s*=(.-)%s*$&amp;quot;)&lt;br /&gt;
						if k == 'files' then options.fileflags = e.numberFlags(v)&lt;br /&gt;
						elseif k == 'paragraphs' then options.paraflags = e.numberFlags(v)&lt;br /&gt;
						elseif k == 'more' then args.more = v&lt;br /&gt;
						else options[k] = v end&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
				if page and page ~= &amp;quot;&amp;quot; then&lt;br /&gt;
					local section = mw.ustring.match(page, &amp;quot;[^#]+#?([^#]*)&amp;quot;) -- save the section&lt;br /&gt;
					text, page = e.getContent(page) -- make sure the page exists&lt;br /&gt;
					if page and page ~= &amp;quot;&amp;quot; and text and text ~= &amp;quot;&amp;quot; then&lt;br /&gt;
						if args.nostubs then&lt;br /&gt;
							local isStub = mw.ustring.find(text, &amp;quot;%s*{{[^{|}]*%-[Ss]tub%s*}}&amp;quot;)&lt;br /&gt;
							if isStub then text = nil end&lt;br /&gt;
						end&lt;br /&gt;
						page = page .. '#' .. section -- restore the section&lt;br /&gt;
						text = e.get(page, options)&lt;br /&gt;
					end&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			table.remove(candidates, candidateKey) -- candidate processed&lt;br /&gt;
			candidateCount = candidateCount - 1 -- ensure that we exit the loop after all candidates are done&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	if not text or text == &amp;quot;&amp;quot; then return e.wikiError(&amp;quot;No valid pages found&amp;quot;) end&lt;br /&gt;
&lt;br /&gt;
	if args.showall then&lt;br /&gt;
		local separator = args.showall&lt;br /&gt;
		if separator == &amp;quot;&amp;quot; then separator = &amp;quot;{{clear}}{{hr}}&amp;quot; end&lt;br /&gt;
		for _, candidate in pairs(candidates) do&lt;br /&gt;
			local t = e.get(candidate, options)&lt;br /&gt;
			if t ~= &amp;quot;&amp;quot; then&lt;br /&gt;
				text = text .. separator .. t&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- If more= then append a link to article for more info&lt;br /&gt;
	if args.more then&lt;br /&gt;
		local more = &amp;quot;Read more...&amp;quot; -- default text&lt;br /&gt;
		if args.more ~= &amp;quot;&amp;quot; then more = args.more end -- use the given text&lt;br /&gt;
		text = text .. &amp;quot; '''[[&amp;quot; .. page .. &amp;quot;|&amp;quot; .. more .. &amp;quot;]]'''&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Add a collapsed list of pages which might appear&lt;br /&gt;
	if args.list and not args.showall then&lt;br /&gt;
		local list = args.list&lt;br /&gt;
		if list == &amp;quot;&amp;quot; then list = &amp;quot;Other articles&amp;quot; end&lt;br /&gt;
		text = text .. &amp;quot;{{collapse top|title={{resize|85%|&amp;quot; ..list .. &amp;quot;}}|bg=fff}}{{hlist&amp;quot;&lt;br /&gt;
		for _, candidate in pairs(candidates) do&lt;br /&gt;
			if mw.ustring.match(candidate, &amp;quot;%S&amp;quot;) then text = text .. &amp;quot;|[[&amp;quot; .. mw.text.trim(candidate) .. &amp;quot;]]&amp;quot; end&lt;br /&gt;
		end&lt;br /&gt;
		text = text .. &amp;quot;}}\n{{collapse bottom}}&amp;quot;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return frame:preprocess(text)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Invocation function used by {{Excerpt}}&lt;br /&gt;
local function excerpt(frame)&lt;br /&gt;
	local args = e.parseArgs(frame)&lt;br /&gt;
&lt;br /&gt;
	-- Make sure the requested page exists&lt;br /&gt;
	local page = args[1] or args.article or args.source or args.page&lt;br /&gt;
	if not page then return e.wikiError(&amp;quot;noPage&amp;quot;) end&lt;br /&gt;
	local title = mw.title.new(page)&lt;br /&gt;
	if not title then return e.wikiError(&amp;quot;noPage&amp;quot;) end&lt;br /&gt;
	if title.isRedirect then title = title.redirectTarget end&lt;br /&gt;
	if not title.exists then return e.wikiError(&amp;quot;pageNotFound&amp;quot;, page) end&lt;br /&gt;
	page = title.prefixedText&lt;br /&gt;
&lt;br /&gt;
	-- Define some useful variables&lt;br /&gt;
	local section = args[2] or args.section or mw.ustring.match(args[1], &amp;quot;[^#]+#([^#]+)&amp;quot;)&lt;br /&gt;
	local tag = args.tag or 'div'&lt;br /&gt;
&lt;br /&gt;
	-- Define the HTML elements&lt;br /&gt;
	local block = mw.html.create(tag):addClass('excerpt-block')&lt;br /&gt;
	if e.is(args.indicator) then block:addClass('excerpt-indicator') end&lt;br /&gt;
&lt;br /&gt;
	local style = frame:extensionTag{ name = 'templatestyles', args = { src = 'Excerpt/styles.css' } }&lt;br /&gt;
&lt;br /&gt;
	local hatnote&lt;br /&gt;
	if not args.nohat then&lt;br /&gt;
		if args.this then&lt;br /&gt;
			hatnote = args.this&lt;br /&gt;
		elseif args.indicator then&lt;br /&gt;
			hatnote = 'This is'&lt;br /&gt;
		elseif args.only == 'file' then&lt;br /&gt;
			hatnote = 'This file is'&lt;br /&gt;
		elseif args.only == 'file' then&lt;br /&gt;
			hatnote = 'These files are'&lt;br /&gt;
		elseif args.only == 'list' then&lt;br /&gt;
			hatnote = 'This list is'&lt;br /&gt;
		elseif args.only == 'lists' then&lt;br /&gt;
			hatnote = 'These lists are'&lt;br /&gt;
		elseif args.only == 'table' then&lt;br /&gt;
			hatnote = 'This table is'&lt;br /&gt;
		elseif args.only == 'tables' then&lt;br /&gt;
			hatnote = 'These tables are'&lt;br /&gt;
		else&lt;br /&gt;
			hatnote = 'This section is'&lt;br /&gt;
		end&lt;br /&gt;
		hatnote = hatnote .. ' an excerpt from '&lt;br /&gt;
		if section then&lt;br /&gt;
			hatnote = hatnote .. '[[' .. page .. '#' .. section .. '|' .. page .. ' § ' .. section .. ']]'&lt;br /&gt;
		else&lt;br /&gt;
			hatnote = hatnote .. '[[' .. page .. ']]'&lt;br /&gt;
		end&lt;br /&gt;
		hatnote = hatnote .. &amp;quot;''&amp;quot; .. '&amp;lt;span class=&amp;quot;mw-editsection-like plainlinks&amp;quot;&amp;gt;&amp;lt;span class=&amp;quot;mw-editsection-bracket&amp;quot;&amp;gt;[&amp;lt;/span&amp;gt;['&lt;br /&gt;
		hatnote = hatnote .. title:fullUrl('action=edit') .. ' edit'&lt;br /&gt;
		hatnote = hatnote .. ']&amp;lt;span class=&amp;quot;mw-editsection-bracket&amp;quot;&amp;gt;]&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;' .. &amp;quot;''&amp;quot;&lt;br /&gt;
		hatnote = require('Module:Hatnote')._hatnote(hatnote, {selfref=true}) or e.wikiError('Error generating hatnote')&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Build the module options out of the template arguments and the desired defaults&lt;br /&gt;
	local options = {&lt;br /&gt;
		fileflags = e.numberFlags( args['files'] or 1 ),&lt;br /&gt;
		paraflags = e.numberFlags( args['paragraphs'] ),&lt;br /&gt;
		filesOnly = e.is( args['only'] == 'file' or args['only'] == 'files' ),&lt;br /&gt;
		listsOnly = e.is( args['only'] == 'list' or args['only'] == 'lists'),&lt;br /&gt;
		tablesOnly = e.is( args['only'] == 'table' or args['only'] == 'tables' ),&lt;br /&gt;
		keepTables = e.is( args['tables'] or true ),&lt;br /&gt;
		keepRefs = e.is( args['references']  or true ),&lt;br /&gt;
		keepSubsections = e.is( args['subsections'] ),&lt;br /&gt;
		nobold = not e.is( args['bold'] ),&lt;br /&gt;
		fragment = args['fragment']&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	-- Get the excerpt itself&lt;br /&gt;
	if section then page = page .. '#' .. section end&lt;br /&gt;
	local ok, excerpt = pcall(e.get, page, options)&lt;br /&gt;
	if not ok then return e.wikiError(excerpt) end&lt;br /&gt;
	excerpt = &amp;quot;\n&amp;quot; .. excerpt -- line break is necessary to prevent broken tables and lists&lt;br /&gt;
	if mw.title.getCurrentTitle().isContentPage then excerpt = excerpt .. '[[Category:Articles with excerpts]]' end&lt;br /&gt;
	excerpt = frame:preprocess(excerpt)&lt;br /&gt;
	excerpt = mw.html.create(tag):addClass('excerpt'):wikitext(excerpt)&lt;br /&gt;
&lt;br /&gt;
	-- Combine and return the elements&lt;br /&gt;
	return block:node(style):node(hatnote):node(excerpt)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Entry points for English Wikipedia templates&lt;br /&gt;
function p.lead(frame) return portal(frame, &amp;quot;lead&amp;quot;) end -- {{Transclude lead excerpt}} reads a randomly selected article linked from the given page&lt;br /&gt;
function p.linked(frame) return portal(frame, &amp;quot;linked&amp;quot;) end -- {{Transclude linked excerpt}} reads a randomly selected article linked from the given page&lt;br /&gt;
function p.listitem(frame) return portal(frame, &amp;quot;listitem&amp;quot;) end -- {{Transclude list item excerpt}} reads a randomly selected article listed on the given page&lt;br /&gt;
function p.random(frame) return portal(frame, &amp;quot;random&amp;quot;) end -- {{Transclude random excerpt}} reads any article (default for invoke with one argument)&lt;br /&gt;
function p.selected(frame) return portal(frame, &amp;quot;selected&amp;quot;) end -- {{Transclude selected excerpt}} reads the article whose key is in the selected= parameter&lt;br /&gt;
function p.excerpt(frame) return excerpt(frame) end -- {{Excerpt}} transcludes part of an article into another article&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Cascadia</name></author>
	</entry>
</feed>