<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://afropedia.world/index.php?action=history&amp;feed=atom&amp;title=Module%3AGetShortDescription</id>
	<title>Module:GetShortDescription - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://afropedia.world/index.php?action=history&amp;feed=atom&amp;title=Module%3AGetShortDescription"/>
	<link rel="alternate" type="text/html" href="https://afropedia.world/index.php?title=Module:GetShortDescription&amp;action=history"/>
	<updated>2026-04-04T10:22:54Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.45.1</generator>
	<entry>
		<id>https://afropedia.world/index.php?title=Module:GetShortDescription&amp;diff=617&amp;oldid=prev</id>
		<title>Djehuti: 1 revision imported</title>
		<link rel="alternate" type="text/html" href="https://afropedia.world/index.php?title=Module:GetShortDescription&amp;diff=617&amp;oldid=prev"/>
		<updated>2024-05-31T19:50:06Z</updated>

		<summary type="html">&lt;p&gt;1 revision imported&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
local function isEmpty(value) return value == nil or value == &amp;#039;&amp;#039; end&lt;br /&gt;
&lt;br /&gt;
local function notEmpty(value) return not isEmpty(value) end&lt;br /&gt;
&lt;br /&gt;
local function isNone(value) return value:lower() == &amp;#039;none&amp;#039; end&lt;br /&gt;
&lt;br /&gt;
local function alarmingMessage(message, preview)&lt;br /&gt;
	message = &amp;#039;&amp;lt;span style=&amp;quot;color:#d33&amp;quot;&amp;gt;[[Module:GetShortDescription]] &amp;#039;..message..&amp;#039;.&amp;lt;/span&amp;gt;&amp;#039;&lt;br /&gt;
	if not preview then&lt;br /&gt;
		message = message..&amp;#039;[[Category:Pages displaying alarming messages about Module:GetShortDescription]]&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	return message&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Grammatically reasonable concatenation of possible issues into one message per problematic link target.&lt;br /&gt;
local function previewWarning(args_name, quantity_of_things)&lt;br /&gt;
	local message = &amp;#039;&amp;#039;&lt;br /&gt;
	if quantity_of_things.params &amp;gt; 3 then&lt;br /&gt;
		message = message..&amp;#039; with extraneous parameters&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	if quantity_of_things.descriptions &amp;gt; 1 then&lt;br /&gt;
		message = message..&amp;#039;, declaring &amp;#039;..quantity_of_things.descriptions..&amp;#039; short descriptions&amp;#039;&lt;br /&gt;
	end&lt;br /&gt;
	if quantity_of_things.templates &amp;gt; 1 or notEmpty(message) then&lt;br /&gt;
		message = &amp;#039;has detected that [[:&amp;#039;..args_name..&amp;#039;|&amp;#039;..args_name..&amp;#039;]] has &amp;#039;..&lt;br /&gt;
			quantity_of_things.templates..&amp;#039; {{tlx|short description}}&amp;#039;..message&lt;br /&gt;
		mw.addWarning(alarmingMessage(message, true))&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getWikidataDescription(title, args, fallback)&lt;br /&gt;
	local wikidata_id = mw.wikibase.getEntityIdForTitle(title)&lt;br /&gt;
	if isEmpty(wikidata_id) then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	local wikidata_description, wikidata_description_lang = mw.wikibase.getDescriptionWithLang(wikidata_id)&lt;br /&gt;
	if isEmpty(wikidata_description) then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	local result = {wikidata = wikidata_description}&lt;br /&gt;
	if isEmpty(args.lang_no) and notEmpty(wikidata_description_lang) and wikidata_description_lang ~= &amp;#039;en&amp;#039; then&lt;br /&gt;
		-- According to the docs this is a possibility...&lt;br /&gt;
		result.wikidata = require(&amp;#039;Module:Lang&amp;#039;)._lang{&lt;br /&gt;
			wikidata_description_lang,&lt;br /&gt;
			wikidata_description,&lt;br /&gt;
			italic = args.lang_italic,&lt;br /&gt;
			nocat = args.lang_nocat,&lt;br /&gt;
			size = args.lang_size,&lt;br /&gt;
			cat = args.lang_cat,&lt;br /&gt;
			rtl = args.lang_rtl&lt;br /&gt;
		}&lt;br /&gt;
	end&lt;br /&gt;
	result.fellback = fallback&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getShortDescriptionTemplates(title_table)&lt;br /&gt;
	local page_content = title_table:getContent()&lt;br /&gt;
	&lt;br /&gt;
	-- Assume no content means a nonexistent title because it&amp;#039;s cheaper than testing if it exists.&lt;br /&gt;
	if isEmpty(page_content) then&lt;br /&gt;
		return {redlink = true}&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local contents_of_all_short_description_templates = {}&lt;br /&gt;
	&lt;br /&gt;
	-- Because there could be any number of short description templates, and not all where there should be; get all the templates.&lt;br /&gt;
	for template in page_content:gmatch(&amp;#039;{%b{}}&amp;#039;) do&lt;br /&gt;
		local short_description_content = mw.ustring.match(template, &amp;#039;^{{%s*[Ss]hort description%s*|%s*(.-)%s*}}&amp;#039;)&lt;br /&gt;
		if notEmpty(short_description_content) then&lt;br /&gt;
			-- Collect the contents of short description templates.&lt;br /&gt;
			contents_of_all_short_description_templates[#contents_of_all_short_description_templates+1] = short_description_content&lt;br /&gt;
		end&lt;br /&gt;
		-- An opportunity for efficiency gain exists - to break if another type of template is found e.g. citation templates,&lt;br /&gt;
		-- but on an appallingly formatted page, a short description template down by the categories would likely be missed.&lt;br /&gt;
	end&lt;br /&gt;
	return contents_of_all_short_description_templates&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getShortDescription(args_name, args_name_title_table, title, title_table, fallback)&lt;br /&gt;
	local contents_of_all_short_description_templates = {}&lt;br /&gt;
	local redirected&lt;br /&gt;
	&lt;br /&gt;
	-- Check for short description templates on redirect pages.&lt;br /&gt;
	if title ~= args_name then&lt;br /&gt;
		contents_of_all_short_description_templates = getShortDescriptionTemplates(args_name_title_table)&lt;br /&gt;
		if contents_of_all_short_description_templates.redlink then&lt;br /&gt;
			return contents_of_all_short_description_templates&lt;br /&gt;
		end&lt;br /&gt;
		redirected = false&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if #contents_of_all_short_description_templates &amp;lt; 1 then&lt;br /&gt;
		contents_of_all_short_description_templates = getShortDescriptionTemplates(title_table)&lt;br /&gt;
		if notEmpty(redirected) then&lt;br /&gt;
			redirected = true&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if contents_of_all_short_description_templates.redlink then&lt;br /&gt;
		return contents_of_all_short_description_templates&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if #contents_of_all_short_description_templates &amp;lt; 1 then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local quantity_of_things = {&lt;br /&gt;
		templates = #contents_of_all_short_description_templates,&lt;br /&gt;
		descriptions = 0,&lt;br /&gt;
		params = 0&lt;br /&gt;
	}&lt;br /&gt;
	&lt;br /&gt;
	local possible_short_descriptions = {}&lt;br /&gt;
	&lt;br /&gt;
	-- Look through the short description templates:&lt;br /&gt;
	for template_content_index, short_description_template_contents in ipairs(contents_of_all_short_description_templates) do&lt;br /&gt;
		-- Split the contents at pipes and trim.&lt;br /&gt;
		local short_description_template_params = mw.text.split(short_description_template_contents, &amp;#039;%s*|%s*&amp;#039;)&lt;br /&gt;
		if #short_description_template_params &amp;gt; quantity_of_things.params then&lt;br /&gt;
			quantity_of_things.params = #short_description_template_params&lt;br /&gt;
		end&lt;br /&gt;
		possible_short_descriptions[template_content_index] = {}&lt;br /&gt;
		-- Look through the params:&lt;br /&gt;
		for i, param in ipairs(short_description_template_params) do&lt;br /&gt;
			if param == &amp;#039;noreplace&amp;#039; or mw.ustring.match(param, &amp;#039;^2%s*=%s*noreplace$&amp;#039;) then&lt;br /&gt;
				-- Take note of &amp;#039;noreplace&amp;#039;-ing for establishment of hierarchy later.&lt;br /&gt;
				possible_short_descriptions[template_content_index].noreplace = true&lt;br /&gt;
			else&lt;br /&gt;
				local has_equals = param:match(&amp;#039;=&amp;#039;)&lt;br /&gt;
				if not has_equals or param:match(&amp;#039;^1&amp;#039;) then&lt;br /&gt;
					-- Grab the short description.&lt;br /&gt;
					if has_equals then&lt;br /&gt;
						param = mw.ustring.gsub(param, &amp;#039;^1%s*=%s*&amp;#039;, &amp;#039;&amp;#039;)&lt;br /&gt;
					end&lt;br /&gt;
					-- If the template has both a numbered and an unnumbered short description;&lt;br /&gt;
					-- whichever comes last (ltr) will be used by that template, so overwriting works out great.&lt;br /&gt;
					possible_short_descriptions[template_content_index].description = param&lt;br /&gt;
					-- And we want to know the total quantity of descriptions being declared.&lt;br /&gt;
					quantity_of_things.descriptions = quantity_of_things.descriptions + 1&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local short_descriptions = {}&lt;br /&gt;
	&lt;br /&gt;
	-- Look through the possible short descriptions for definite short descriptions,&lt;br /&gt;
	-- and prepare for working out which of possibly multiple short descriptions is actually being applied for the page:&lt;br /&gt;
	for i, possible_short_description in ipairs(possible_short_descriptions) do&lt;br /&gt;
		if possible_short_description.description then&lt;br /&gt;
			-- If a description is &amp;#039;noreplace&amp;#039;-ing or &amp;#039;none&amp;#039;; demote it.&lt;br /&gt;
			if (possible_short_description.noreplace or isNone(possible_short_description.description)) and&lt;br /&gt;
				#possible_short_descriptions &amp;gt; 1 then&lt;br /&gt;
				-- But don&amp;#039;t demote it if it&amp;#039;s already at the bottom.&lt;br /&gt;
				if i &amp;gt; 1 then&lt;br /&gt;
					table.insert(short_descriptions, #short_descriptions, possible_short_description)&lt;br /&gt;
				else&lt;br /&gt;
					short_descriptions[#short_descriptions+1] = possible_short_description&lt;br /&gt;
				end&lt;br /&gt;
			else&lt;br /&gt;
				short_descriptions[#short_descriptions+1] = possible_short_description&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Let previewWarning() work out if these numbers are bad.&lt;br /&gt;
	previewWarning(args_name, quantity_of_things)&lt;br /&gt;
	&lt;br /&gt;
	if #short_descriptions &amp;gt;= 1 then&lt;br /&gt;
		-- Pop!&lt;br /&gt;
		local short_description = short_descriptions[#short_descriptions].description&lt;br /&gt;
		if notEmpty(short_description) then&lt;br /&gt;
			return {explicit = short_description, fellback = fallback, redirected = redirected}&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return nil&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function isSisterProjectLink(title)&lt;br /&gt;
	local sister_project_prefixes = {&lt;br /&gt;
		&amp;#039;wiktionary&amp;#039;, &amp;#039;wikt&amp;#039;,&lt;br /&gt;
		&amp;#039;wikinews&amp;#039;, &amp;#039;n&amp;#039;,&lt;br /&gt;
		&amp;#039;wikibooks&amp;#039;, &amp;#039;b&amp;#039;,&lt;br /&gt;
		&amp;#039;wikiquote&amp;#039;, &amp;#039;q&amp;#039;,&lt;br /&gt;
		&amp;#039;wikisource&amp;#039;, &amp;#039;s&amp;#039;,&lt;br /&gt;
		&amp;#039;wikispecies&amp;#039;, &amp;#039;species&amp;#039;,&lt;br /&gt;
		&amp;#039;wikiversity&amp;#039;, &amp;#039;v&amp;#039;,&lt;br /&gt;
		&amp;#039;wikivoyage&amp;#039;, &amp;#039;voy&amp;#039;,&lt;br /&gt;
		&amp;#039;commons&amp;#039;, &amp;#039;c&amp;#039;,&lt;br /&gt;
		&amp;#039;wikidata&amp;#039;, &amp;#039;d&amp;#039;,&lt;br /&gt;
		&amp;#039;mediawikiwiki&amp;#039;, &amp;#039;mw&amp;#039;,&lt;br /&gt;
		&amp;#039;wikimedia&amp;#039;, &amp;#039;foundation&amp;#039;, &amp;#039;wmf&amp;#039;,&lt;br /&gt;
		&amp;#039;meta&amp;#039;, &amp;#039;m&amp;#039;,&lt;br /&gt;
		&amp;#039;incubator&amp;#039;,&lt;br /&gt;
		&amp;#039;phabricator&amp;#039;, &amp;#039;phab&amp;#039;&lt;br /&gt;
	}&lt;br /&gt;
	local pre_colon = title:match(&amp;#039;^(%a+):&amp;#039;)&lt;br /&gt;
	if pre_colon then&lt;br /&gt;
		for i, sister in ipairs(sister_project_prefixes) do&lt;br /&gt;
			if pre_colon == sister then&lt;br /&gt;
				return true&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return false&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- Literally testing if title_table.isRedirect can be expensive;&lt;br /&gt;
-- processing this way resolves (multiple) redirects without the possibly expensive check.&lt;br /&gt;
local function getTitleAndTable(orig_name)&lt;br /&gt;
	local title_table = mw.title.new(orig_name)&lt;br /&gt;
	title_table = title_table.redirectTarget or title_table&lt;br /&gt;
	local title = title_table.prefixedText&lt;br /&gt;
	if title == orig_name then&lt;br /&gt;
		return title, title_table&lt;br /&gt;
	end&lt;br /&gt;
	return getTitleAndTable(title)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function getDescription(args)&lt;br /&gt;
	local args_name = args.name&lt;br /&gt;
	if isEmpty(args_name) then&lt;br /&gt;
		return {alarm = &amp;#039;requires a page name (including namespace)&amp;#039;}&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Keep the orginal name, cleaned up, and its title_table for later.&lt;br /&gt;
	local args_name_title_table = mw.title.new(args_name)&lt;br /&gt;
	args_name = args_name_title_table.prefixedText&lt;br /&gt;
	&lt;br /&gt;
	if isSisterProjectLink(args_name) then&lt;br /&gt;
		return nil&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local title, title_table = getTitleAndTable(args_name)&lt;br /&gt;
	&lt;br /&gt;
	if title ~= args_name then&lt;br /&gt;
		if isSisterProjectLink(title) then&lt;br /&gt;
			return nil&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local only = args.only&lt;br /&gt;
	local prefer = args.prefer or &amp;#039;explicit&amp;#039;&lt;br /&gt;
	&lt;br /&gt;
	-- Pass args_name to getShortDescription() so previewWarning()s won&amp;#039;t be confusing for redirects.&lt;br /&gt;
	&lt;br /&gt;
	if notEmpty(only) then&lt;br /&gt;
		if only == &amp;#039;explicit&amp;#039; then&lt;br /&gt;
			return getShortDescription(args_name, args_name_title_table, title, title_table)&lt;br /&gt;
		end&lt;br /&gt;
		if only == &amp;#039;wikidata&amp;#039; then&lt;br /&gt;
			return getWikidataDescription(title, args)&lt;br /&gt;
		end&lt;br /&gt;
		return {alarm = &amp;#039;accepts either &amp;quot;explicit&amp;quot; or &amp;quot;wikidata&amp;quot; as the value of |only=&amp;#039;}&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if notEmpty(prefer) then&lt;br /&gt;
		if prefer == &amp;#039;explicit&amp;#039; then&lt;br /&gt;
			local short_description = getShortDescription(args_name, args_name_title_table, title, title_table)&lt;br /&gt;
			if notEmpty(short_description) then&lt;br /&gt;
				-- Assume a Wikidata search would be a bad idea for an assumed nonexistent title.&lt;br /&gt;
				if short_description.redlink or (not isNone(short_description.explicit) or args.none_is_valid) then&lt;br /&gt;
					return short_description&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
			return getWikidataDescription(title, args, true)&lt;br /&gt;
		end&lt;br /&gt;
		if prefer == &amp;#039;wikidata&amp;#039; then&lt;br /&gt;
			return getWikidataDescription(title, args) or getShortDescription(args_name, args_name_title_table, title, title_table, true)&lt;br /&gt;
		end&lt;br /&gt;
		return {alarm = &amp;#039;accepts either &amp;quot;explicit&amp;quot; or &amp;quot;wikidata&amp;quot; as the value of |prefer=&amp;#039;}&lt;br /&gt;
	end&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function main(args)&lt;br /&gt;
	local result = getDescription(args)&lt;br /&gt;
	if notEmpty(result) then&lt;br /&gt;
		if result.alarm then&lt;br /&gt;
			result.alarm = alarmingMessage(result.alarm)&lt;br /&gt;
		end&lt;br /&gt;
		if args.stringify then&lt;br /&gt;
			if result.alarm then&lt;br /&gt;
				result = result.alarm&lt;br /&gt;
			else&lt;br /&gt;
				result = result.explicit or result.wikidata&lt;br /&gt;
				if args.none_is_nil and isNone(result) then&lt;br /&gt;
					result = nil&lt;br /&gt;
				end&lt;br /&gt;
			end&lt;br /&gt;
		elseif not result.alarm and args.none_is_nil then&lt;br /&gt;
			local description = result.explicit or result.wikidata&lt;br /&gt;
			if description and args.none_is_nil and isNone(description) then&lt;br /&gt;
				result = nil&lt;br /&gt;
			end&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	return result&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function p.main(frame)&lt;br /&gt;
	local args = require(&amp;#039;Module:Arguments&amp;#039;).getArgs(frame)&lt;br /&gt;
	if isEmpty(args) then&lt;br /&gt;
		return alarmingMessage(&amp;#039;could not getArgs&amp;#039;) -- This really would be alarming.&lt;br /&gt;
	end&lt;br /&gt;
	return main(args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Djehuti</name></author>
	</entry>
</feed>