
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://zoophilia.wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ACite_tweet</id>
	<title>Module:Cite tweet - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://zoophilia.wiki/index.php?action=history&amp;feed=atom&amp;title=Module%3ACite_tweet"/>
	<link rel="alternate" type="text/html" href="https://zoophilia.wiki/index.php?title=Module:Cite_tweet&amp;action=history"/>
	<updated>2026-05-07T10:37:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://zoophilia.wiki/index.php?title=Module:Cite_tweet&amp;diff=133642&amp;oldid=prev</id>
		<title>SockyPaws: Import module from English Wikipedia</title>
		<link rel="alternate" type="text/html" href="https://zoophilia.wiki/index.php?title=Module:Cite_tweet&amp;diff=133642&amp;oldid=prev"/>
		<updated>2024-11-23T08:38:48Z</updated>

		<summary type="html">&lt;p&gt;Import module from English Wikipedia&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
local TwitterSnowflake = require(&amp;#039;Module:TwitterSnowflake&amp;#039;)&lt;br /&gt;
local CiteWeb = require(&amp;#039;Module:Cite web&amp;#039;)[&amp;#039;&amp;#039;]&lt;br /&gt;
&lt;br /&gt;
local err_msgs_t = {  -- A sequence of snowflake date error messages; all must be terminated with a semicolon (;).&lt;br /&gt;
	&amp;#039; &amp;lt;kbd&amp;gt;&amp;amp;#124;date=&amp;lt;/kbd&amp;gt; / &amp;lt;kbd&amp;gt;&amp;amp;#124;number=&amp;lt;/kbd&amp;gt; mismatch;&amp;#039;,	 -- [1]&lt;br /&gt;
	&amp;#039; &amp;lt;kbd&amp;gt;&amp;amp;#124;date=&amp;lt;/kbd&amp;gt; required;&amp;#039;,							 -- [2]&lt;br /&gt;
	&amp;#039; Invalid &amp;lt;kbd&amp;gt;&amp;amp;#124;number=&amp;lt;/kbd&amp;gt;;&amp;#039;,							 -- [3]&lt;br /&gt;
	&amp;#039; Missing or empty &amp;lt;kbd&amp;gt;&amp;amp;#124;number=&amp;lt;/kbd&amp;gt;;&amp;#039;,					 -- [4]&lt;br /&gt;
	&amp;#039; Missing or empty &amp;lt;kbd&amp;gt;&amp;amp;#124;user=&amp;lt;/kbd&amp;gt;;&amp;#039;						 -- [5]&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- MAIN&lt;br /&gt;
p.main = function(frame)&lt;br /&gt;
	return p[&amp;#039;&amp;#039;](frame)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
-- SUPPRESS URL IN TITLE&lt;br /&gt;
-- This function searches for and suppresses URLs in the title, script-title and trans-title parameters,&lt;br /&gt;
-- so that Cite web won&amp;#039;t emit error messages when parsed. In the rendering, URLs are correctly formed,&lt;br /&gt;
-- as they were in the original tweet. The function looks for valid schemes, wrapping them in nowiki tags.&lt;br /&gt;
local function suppress_url_in_title (frame, title)&lt;br /&gt;
	local schemes = {  -- Schemes commonly found in tweets.&lt;br /&gt;
		&amp;#039;https://&amp;#039;,&lt;br /&gt;
		&amp;#039;http://&amp;#039;,&lt;br /&gt;
		&amp;#039;ftp://&amp;#039;,&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
	if title then  -- When there is a title, suppress any URLs with known schemes, else abandon.&lt;br /&gt;
		-- Spin through the list of schemes looking for a match.&lt;br /&gt;
		for _, scheme in ipairs (schemes) do&lt;br /&gt;
			-- Replace the scheme with its nowiki&amp;#039;d form (a strip marker).&lt;br /&gt;
			title = title:gsub (scheme, frame:callParserFunction (&amp;#039;#tag&amp;#039;, {&amp;#039;nowiki&amp;#039;, scheme}));&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Return title, modified or not.&lt;br /&gt;
	return title;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- DATE NUMBER URL GET&lt;br /&gt;
-- Extract date and number parameter values, if present. Extract date from number and compare to date.&lt;br /&gt;
-- Construct URL for Cite web from the base URL and number and user. Returns nothing; adds date, number,&lt;br /&gt;
-- URL to &amp;lt;cite_args_t&amp;gt;; adds error message(s) to &amp;lt;errors_t&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
local function date_number_url_get (args_t, cite_args_t, errors_t)&lt;br /&gt;
	local err_msg_index;&lt;br /&gt;
&lt;br /&gt;
	-- Initialize with minimal base URL because Cite web requires it.&lt;br /&gt;
	cite_args_t.url = &amp;#039;https://x.com/&amp;#039;;&lt;br /&gt;
	if not args_t.user then&lt;br /&gt;
		-- Error: Missing or empty user parameter.&lt;br /&gt;
		table.insert (errors_t, err_msgs_t[5]);&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if not args_t.date and not args_t.number then&lt;br /&gt;
		-- Error: Missing or empty number parameter.&lt;br /&gt;
		err_msg_index = 4;&lt;br /&gt;
	-- Have number parameter without date? Use number.&lt;br /&gt;
	elseif tonumber (args_t.number) then&lt;br /&gt;
		if tonumber(args_t.number) then&lt;br /&gt;
			cite_args_t.date = args_t.date or (args_t.number and TwitterSnowflake.snowflakeToDate{ args = {id_str = args_t.number} });&lt;br /&gt;
		else&lt;br /&gt;
			cite_args_t.date = args_t.date;&lt;br /&gt;
		end&lt;br /&gt;
			cite_args_t.number = args_t.number;&lt;br /&gt;
&lt;br /&gt;
			-- Number parameter appears to have a valid value; if user parameter has a value.&lt;br /&gt;
			if args_t.user then&lt;br /&gt;
				-- Construct URL for Cite web.&lt;br /&gt;
				cite_args_t.url = cite_args_t.url .. args_t.user .. &amp;#039;/status/&amp;#039; .. args_t.number;&lt;br /&gt;
			end&lt;br /&gt;
	elseif args_t.number then&lt;br /&gt;
		-- Error: Invalid number that couldn&amp;#039;t be converted to a number.&lt;br /&gt;
		err_msg_index = 3;&lt;br /&gt;
	-- Date parameter without number; use date.&lt;br /&gt;
	elseif not args_t.number then&lt;br /&gt;
		-- Date paramter has a value, use it.&lt;br /&gt;
		cite_args_t.date = args_t.date;&lt;br /&gt;
		-- Error: Missing or empty number parameter.&lt;br /&gt;
		err_msg_index = 4;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if err_msg_index then&lt;br /&gt;
		-- Invalid number or missing necessary parameters, so abandon.&lt;br /&gt;
		table.insert (errors_t, err_msgs_t[err_msg_index]);&lt;br /&gt;
		return;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Returns error message index number on error; else nil.&lt;br /&gt;
	err_msg_index = TwitterSnowflake.datecheck ({ args = {&lt;br /&gt;
		id_str	= args_t.number or &amp;#039;&amp;#039;,&lt;br /&gt;
		date	= args_t.date or &amp;#039;&amp;#039;,&lt;br /&gt;
		-- These numbers are indexes into &amp;lt;err_msgs_t&amp;gt;, to override snowflake default error messages.&lt;br /&gt;
		error1	= 1,&lt;br /&gt;
		-- Done this way to avoid long string comparison looking for the undated-pre-twitter-epoch-post message.&lt;br /&gt;
		error2  = 2,&lt;br /&gt;
		error3	= 3&lt;br /&gt;
		}});&lt;br /&gt;
&lt;br /&gt;
	-- When there&amp;#039;s no date and it was posted before the Twitter epoch.&lt;br /&gt;
	if	2 == err_msg_index then&lt;br /&gt;
		-- Suppress default date because Cite tweet should not claim in its own voice that an undated post was made on 2010-11-04.&lt;br /&gt;
		cite_args_t.date = nil;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	-- Add error message.&lt;br /&gt;
	table.insert (errors_t, err_msgs_t[err_msg_index]);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
-- p[&amp;#039;&amp;#039;]&lt;br /&gt;
-- Construct parameter set for Cite web from Cite tweet parameters, and do some error checking.&lt;br /&gt;
p[&amp;#039;&amp;#039;] = function(frame)&lt;br /&gt;
	local args_t = require (&amp;#039;Module:Arguments&amp;#039;).getArgs (frame);&lt;br /&gt;
&lt;br /&gt;
	local cite_args_t = {&lt;br /&gt;
		title = suppress_url_in_title (frame, args_t.title),&lt;br /&gt;
		[&amp;#039;script-title&amp;#039;] = suppress_url_in_title (frame, args_t[&amp;#039;script-title&amp;#039;]),&lt;br /&gt;
		[&amp;#039;trans-title&amp;#039;] = suppress_url_in_title (frame, args_t[&amp;#039;trans-title&amp;#039;]),&lt;br /&gt;
		language = args_t.language,&lt;br /&gt;
		last1 = args_t.last1 or args_t.last,&lt;br /&gt;
		first1 = args_t.first1 or args_t.first,&lt;br /&gt;
		author1 = args_t.author1 or args_t.author,&lt;br /&gt;
		[&amp;#039;author-link&amp;#039;] = args_t[&amp;#039;author-link&amp;#039;] or args_t.authorlink,&lt;br /&gt;
		others = args_t.retweet and (&amp;#039;Retweeted by &amp;#039; .. args_t.retweet),&lt;br /&gt;
		via = args_t.link == &amp;#039;no&amp;#039; and &amp;#039;Twitter&amp;#039; or &amp;#039;[[wikipedia:Twitter|Twitter]]&amp;#039;,&lt;br /&gt;
		type = args_t.link == &amp;#039;no&amp;#039; and &amp;#039;Tweet&amp;#039; or &amp;#039;[[wikipedia:Tweet (social media)|Tweet]]&amp;#039;,&lt;br /&gt;
		-- Why the location parameter? Tweets are online; there is no publication place.&lt;br /&gt;
		location = args_t.location,&lt;br /&gt;
		[&amp;#039;access-date&amp;#039;] = args_t[&amp;#039;access-date&amp;#039;] or args_t.accessdate,&lt;br /&gt;
		[&amp;#039;archive-date&amp;#039;] = args_t[&amp;#039;archive-date&amp;#039;] or args_t.archivedate,&lt;br /&gt;
		[&amp;#039;archive-url&amp;#039;] = args_t[&amp;#039;archive-url&amp;#039;] or args_t.archiveurl,&lt;br /&gt;
		[&amp;#039;url-status&amp;#039;] = args_t[&amp;#039;url-status&amp;#039;],&lt;br /&gt;
		[&amp;#039;url-access&amp;#039;] = args_t[&amp;#039;url-access&amp;#039;],&lt;br /&gt;
		quote = args_t.quote,&lt;br /&gt;
		ref = args_t.ref,&lt;br /&gt;
		df = args_t.df,&lt;br /&gt;
		mode = args_t.mode&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
	-- Initialize sequence of error messages with style tag.&lt;br /&gt;
	local errors_t = {&amp;#039;&amp;lt;span class=&amp;quot;cs1-visible-error citation-comment&amp;quot;&amp;gt; &amp;lt;kbd&amp;gt;{{[[Template:Cite tweet|Cite tweet]]}}&amp;lt;/kbd&amp;gt;:&amp;#039;};&lt;br /&gt;
	-- Add date, number and url parameters to &amp;lt;cite_args_t&amp;gt;.&lt;br /&gt;
	date_number_url_get (args_t, cite_args_t, errors_t);&lt;br /&gt;
&lt;br /&gt;
	-- Concatenate last parameter with first for author-mask.&lt;br /&gt;
	local author = ((cite_args_t.last1 and cite_args_t.first1) and cite_args_t.last1 .. &amp;#039;, &amp;#039; .. cite_args_t.first1) or&lt;br /&gt;
		-- Only last parameter for author-mask.&lt;br /&gt;
		(cite_args_t.last1 and cite_args_t.last1) or&lt;br /&gt;
		-- Strip author or author1 parameters of accept-as-written markup for author-mask.&lt;br /&gt;
		(cite_args_t.author1 and cite_args_t.author1:gsub(&amp;#039;^%(%((.+)%)%)$&amp;#039;, &amp;#039;%1&amp;#039;));&lt;br /&gt;
&lt;br /&gt;
	if author and args_t.user then&lt;br /&gt;
		-- Concatenate &amp;lt;author&amp;gt; and user parameter into author-mask.&lt;br /&gt;
		cite_args_t[&amp;#039;author-mask&amp;#039;] = author .. &amp;#039; [@&amp;#039; .. (args_t.user or &amp;#039;&amp;#039;) .. &amp;#039;]&amp;#039;&lt;br /&gt;
	elseif args_t.user then&lt;br /&gt;
		-- Just the user name for CS1 &amp;amp; CS2 template metadata.&lt;br /&gt;
		cite_args_t.author1 = &amp;#039;((&amp;#039; .. args_t.user .. &amp;#039;))&amp;#039;;&lt;br /&gt;
		-- Make a mask for display.&lt;br /&gt;
		cite_args_t[&amp;#039;author-mask&amp;#039;] = &amp;#039;@&amp;#039; .. args_t.user;&lt;br /&gt;
	-- Here when neither &amp;lt;author&amp;gt; nor user are available.&lt;br /&gt;
	else&lt;br /&gt;
		-- So unset.&lt;br /&gt;
		cite_args_t.author1 = nil;&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	-- Overwrite frame arguments.&lt;br /&gt;
	frame.args = cite_args_t;&lt;br /&gt;
	-- Render the template.&lt;br /&gt;
	local rendering = CiteWeb (frame);&lt;br /&gt;
&lt;br /&gt;
-- Error messaging&lt;br /&gt;
	-- errors_t[2] is nil when there are no errors.&lt;br /&gt;
	if errors_t[2] then&lt;br /&gt;
		-- Rendered Cite web template with errors will have this string.&lt;br /&gt;
		if rendering:find (&amp;#039;cs1-visible-error&amp;#039;, 1, true) then&lt;br /&gt;
			-- Insert a semicolon to terminate CS1 &amp;amp; CS2 error message string.&lt;br /&gt;
			errors_t[1] = errors_t[1]:gsub (&amp;#039;&amp;gt; &amp;lt;&amp;#039;, &amp;#039;&amp;gt;; &amp;lt;&amp;#039;);&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		-- Replace trailing semicolon with a help link.&lt;br /&gt;
		errors_t[#errors_t] = errors_t[#errors_t]:gsub (&amp;#039;;$&amp;#039;,&amp;#039; ([[Template:Cite_tweet#Error_detection|help]])&amp;#039;);&lt;br /&gt;
		table.insert (errors_t, &amp;#039;&amp;lt;/span&amp;gt;&amp;#039;);										-- close style span tag&lt;br /&gt;
		-- In the Main namespace, only.&lt;br /&gt;
		if mw.title.getCurrentTitle():inNamespace (0) then&lt;br /&gt;
			-- Add error tracking category.&lt;br /&gt;
			table.insert (errors_t, &amp;#039;[[Category:Cite tweet templates with errors]]&amp;#039;);&lt;br /&gt;
		end&lt;br /&gt;
&lt;br /&gt;
		-- Append error messaging, help links and categories.&lt;br /&gt;
		rendering = rendering .. table.concat (errors_t);&lt;br /&gt;
	end&lt;br /&gt;
	return rendering;&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>SockyPaws</name></author>
	</entry>
</feed>