<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AExtract_short_description</id>
	<title>Module:Extract short description - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3AExtract_short_description"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Extract_short_description&amp;action=history"/>
	<updated>2026-05-24T12:48:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Extract_short_description&amp;diff=136139&amp;oldid=prev</id>
		<title>imported&gt;WOSlinker: use require(&#039;strict&#039;) instead of require(&#039;Module:No globals&#039;)</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Extract_short_description&amp;diff=136139&amp;oldid=prev"/>
		<updated>2022-10-21T21:19:43Z</updated>

		<summary type="html">&lt;p&gt;use require(&amp;#039;strict&amp;#039;) instead of require(&amp;#039;Module:No globals&amp;#039;)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;require(&amp;#039;strict&amp;#039;);&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E X T R A C T _ F R O M _ T E M P L A T E &amp;gt;------------------------------------&lt;br /&gt;
&lt;br /&gt;
no direct template access&lt;br /&gt;
&lt;br /&gt;
extracts short description text from a named template in the named article when that template is found in article&lt;br /&gt;
wiki source&lt;br /&gt;
&lt;br /&gt;
requires three arguments:&lt;br /&gt;
	frame: frame object required to preprocess template_name&lt;br /&gt;
	article_title: the name of the article to inspect - correct spelling and captialization is required&lt;br /&gt;
	template_names_tbl: a single template name (a string) or a table of one or more template names all without&lt;br /&gt;
		namespace to be inspected - correct spelling and captialization is required&lt;br /&gt;
&lt;br /&gt;
returns two values:&lt;br /&gt;
	on success, returns the short description text and true&lt;br /&gt;
	on failure, returns error message and nil&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function extract_from_template (frame, article_title, template_names_tbl)&lt;br /&gt;
	local content = mw.title.new (article_title):getContent();					-- read the unparsed article source&lt;br /&gt;
	if not content then&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: no article: &amp;#039; .. article_title .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local template_name_pattern;&lt;br /&gt;
	local start;&lt;br /&gt;
	&lt;br /&gt;
	if &amp;#039;string&amp;#039; == type (template_names_tbl) then								-- when single template name passed in as a string&lt;br /&gt;
		template_names_tbl = {template_names_tbl};								-- convert to a table&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local templateName&lt;br /&gt;
	for _, template_name in ipairs (template_names_tbl) do						-- loop through the name in the table&lt;br /&gt;
		template_name_pattern = template_name:gsub (&amp;#039;^%a&amp;#039;, string.lower):gsub (&amp;#039;^%a&amp;#039;, &amp;#039;%[%1%1%]&amp;#039;):gsub (&amp;#039;%[%a&amp;#039;, string.upper);	-- make lua pattern for initial letter upper or lower case: A -&amp;gt; [Aa]&lt;br /&gt;
		start = content:find (&amp;#039;{{%s*&amp;#039; .. template_name_pattern);				-- find the start of {{template name ...;&lt;br /&gt;
		if start then&lt;br /&gt;
			templateName = template_name&lt;br /&gt;
			break;																-- found a matching template&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if not start then															-- no templates found: return name of first template in template_names_tbl in error message&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: no template: &amp;#039; .. template_names_tbl[1] .. &amp;#039; in: &amp;#039; .. article_title .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local text = string.match (content, &amp;#039;%b{}&amp;#039;, start);							-- start points to first { of the templateName&lt;br /&gt;
	if not text then&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: failed to extract template: &amp;#039; .. templateName .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	text = text:gsub (&amp;#039;&amp;lt;ref[^&amp;gt;]-&amp;gt;[^&amp;lt;]-&amp;lt;/ref&amp;gt;&amp;#039;, &amp;#039;&amp;#039;);								-- delete references before preprocessing; they do not belong in shortdesc text&lt;br /&gt;
	text = text:gsub (&amp;#039;&amp;lt;ref[^&amp;gt;]-/ *&amp;gt;&amp;#039;, &amp;#039;&amp;#039;);										-- also delete self-closed named references&lt;br /&gt;
	text = text:gsub (&amp;#039;{{%s*sfn[^}]-}}&amp;#039;, &amp;#039;&amp;#039;);									-- delete sfn template which make references using {{#tag:}} parser functions&lt;br /&gt;
	text = text:gsub (&amp;#039;{{#tag:ref[^}]-}}&amp;#039;, &amp;#039;&amp;#039;);									-- and delete these too&lt;br /&gt;
&lt;br /&gt;
	text = frame:preprocess (text):match (&amp;#039;&amp;lt;div[^&amp;gt;]-class=&amp;quot;shortdescription.-&amp;gt;(.-)&amp;lt;/div&amp;gt;&amp;#039;);		-- preprocess and extract shortdescription text&lt;br /&gt;
	if not text then&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: no short description text in: &amp;#039; .. templateName .. &amp;#039; in &amp;#039;.. article_title .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	return mw.text.trim (text), true;											-- trim whitespace and done&lt;br /&gt;
																				-- preprocess the template then apply syntax highlighting&lt;br /&gt;
																				-- this will display the preprocessed template; not usable here&lt;br /&gt;
																				-- for much other than debugging because syntaxhighlight returns a stripmarker&lt;br /&gt;
--	return template_name .. frame:callParserFunction (&amp;#039;#tag:syntaxhighlight&amp;#039;, frame:preprocess (text));&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E X T R A C T _ F R O M _ A R T I C L E &amp;gt;--------------------------------------&lt;br /&gt;
&lt;br /&gt;
no direct template access&lt;br /&gt;
&lt;br /&gt;
extracts short description text from {{short description}} template when that template is found in article wiki&lt;br /&gt;
source; searches for both the long name (short description) and the short-name redirect (SHD); if both are present&lt;br /&gt;
long name controls; if multiples of the same name are present, the first-found controls.&lt;br /&gt;
&lt;br /&gt;
requires one argument: article_title is the name of the article to be inspected&lt;br /&gt;
&lt;br /&gt;
on success, returns the short description text; error message else&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function extract_from_article (article_title)&lt;br /&gt;
	local content = mw.title.new (article_title):getContent();					-- read the unparsed article source&lt;br /&gt;
	if not content then&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: no article: &amp;#039; .. article_title .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local text, start;&lt;br /&gt;
	&lt;br /&gt;
	start = string.find (content, &amp;#039;{{%s*[Ss]hort description&amp;#039;) or				-- find the start of {{Short description}} template&lt;br /&gt;
		string.find (content, &amp;#039;{{%s*SHD&amp;#039;);										-- not full name, try the {{SHD}} redirect&lt;br /&gt;
&lt;br /&gt;
	if not start then&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: no short description in: &amp;#039; .. article_title .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	text = content:match (&amp;#039;%b{}&amp;#039;, start);										-- get the short description template; start points to first { of the template&lt;br /&gt;
	if not text then&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: failed to extract short description template from &amp;#039; .. article_title .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	text = text:match (&amp;#039;^[^|}]+|%s*(.+)%s*}}$&amp;#039;);								-- strip &amp;#039;{{template name|&amp;#039; and &amp;#039;}}&amp;#039;; trim leading and trailing whitespace&lt;br /&gt;
	&lt;br /&gt;
	return text and text or &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: no short description text in: &amp;#039; .. article_title .. &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E X T R A C T _ S H O R T _ D E S C R I P T I O N &amp;gt;----------------------------&lt;br /&gt;
&lt;br /&gt;
template entry point:&lt;br /&gt;
	{{#invoke:extract short description|extract_short_description}}&lt;br /&gt;
&lt;br /&gt;
search for and return text that is used by the {{short description}} template.  {{Short description}}, also {{SHD}}&lt;br /&gt;
may be located in article wikisource or embedded in a template (commonly an infobox template).  When neither of&lt;br /&gt;
|template= and {{{2|}}} are set, this code will look in the article wiki source; when set, this code look inside the&lt;br /&gt;
named template.&lt;br /&gt;
&lt;br /&gt;
This template entry takes two parameters:&lt;br /&gt;
	{{{1}}} or |article=: required; name of wiki article from which to extract the short description&lt;br /&gt;
	{{{2}}} or |template=; optional; name of template that holds the {{short description}} template&lt;br /&gt;
&lt;br /&gt;
on success, returns the short description text; error message else&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function extract_short_description (frame)&lt;br /&gt;
	local getArgs = require(&amp;#039;Module:Arguments&amp;#039;).getArgs;&lt;br /&gt;
	local args = getArgs(frame);&lt;br /&gt;
	&lt;br /&gt;
	if args[1] and args.article then											-- both assigned, fail with an error message&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: conflicting |{{{1}}} and |article= parameters&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local article_title = args[1] or args.article;								-- the required parameter&lt;br /&gt;
	&lt;br /&gt;
	if not article_title then													-- not supplied, fail with an error message&lt;br /&gt;
		return &amp;#039;&amp;lt;span style=&amp;quot;font-size:100%;&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;error: article title required&amp;lt;/span&amp;gt;&amp;#039;;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local template_name = args[2] or args.template;								-- optional&lt;br /&gt;
	&lt;br /&gt;
	if template_name then&lt;br /&gt;
		local text, _ = extract_from_template (frame, article_title, template_name);	-- ignore second return value&lt;br /&gt;
		return text;&lt;br /&gt;
	else&lt;br /&gt;
		return extract_from_article (article_title);&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; E X P O R T E D   F U N C T I O N S &amp;gt;------------------------------------------&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	extract_short_description = extract_short_description,&lt;br /&gt;
	extract_from_template = extract_from_template,&lt;br /&gt;
	extract_from_article = extract_from_article,&lt;br /&gt;
	}&lt;/div&gt;</summary>
		<author><name>imported&gt;WOSlinker</name></author>
	</entry>
</feed>