local p = local TwitterSnowflake = require('Module:TwitterSnowflake')local CiteWeb = require('Module:Cite web')['']
local err_msgs_t =
----------------------------< M A I N >----------------------------------------------------------------------
p.main = function(frame) return p[''](frame)end
--title=, |script-title=, and |trans-title= parameters so thatWeb site: won't emit 'External link in |title=' error messages when rendered In the redering, urls are correctlyformed as they were in the original tweet. The function looks for valid schemes and then wraps them in.. tags.
local function suppress_url_in_title (frame, title) local schemes =
if title then -- when there is a title, suppress any urls with known schemes; abandon else for _, scheme in ipairs (schemes) do -- spin through the list of schemes looking for a match title = title:gsub (scheme, frame:callParserFunction ('#tag',)); -- replace the scheme with its nowiki'd form (a strip marker) end end
return title; -- done; return
--date= and |number= parameter values if present. Extract date from |number= and compare to |date=.
contruct |url= for Web site: from the base url and |number= and |user=
returns nothing; adds date, number, url to
local function date_number_url_get (args_t, cite_args_t, errors_t) local err_msg_index;
cite_args_t.url = 'https://x.com/'; -- initialize with minimal base url because Web site: requires |url= if not args_t.user then table.insert (errors_t, err_msgs_t[5]); -- error: missing or empty |user= end--number= elseif tonumber (args_t.number) then -- |number= without |date=? use number if tonumber(args_t.number) then cite_args_t.date = args_t.date or (args_t.number and TwitterSnowflake.snowflakeToDate); else cite_args_t.date = args_t.date; end cite_args_t.number = args_t.number;
if args_t.user then -- |number= appears to have a valid value; if |user= has a value cite_args_t.url = cite_args_t.url .. args_t.user .. '/status/' .. args_t.number; -- construct |url= for Web site: end elseif args_t.number then -- |number= with a value that can't be converted to a number; invalid err_msg_index = 3; -- error: invalid number (couldn't convert to number) elseif not args_t.number then -- |date= without |number= use date cite_args_t.date = args_t.date; -- |date= has a value, use it err_msg_index = 4; -- error: missing or empty |number= end
local number = args_t.number; local date = args_t.date; if date then cite_args_t.date = date; -- copy to cite_args_t
if number and not tonumber (number) then err_msg_index = 3; -- invalid number end if not number then err_msg_index = 4; -- number required end else -- here when |date= empty or missing if number then if tonumber (number) then -- do we think
else -- here when |number= is empty or missing err_msg_index = 4; -- |number= required end end
if args_t.user and number and 3 ~= err_msg_index and 4 ~= err_msg_index then -- when |user= has a value and |number= appears to be valid cite_args_t.url = cite_args_t.url .. args_t.user .. '/status/' .. number; -- construct |url= for Web site: end
if err_msg_index then table.insert (errors_t, err_msgs_t[err_msg_index]); -- invalid number or missing necessary parameters so abandon return; end
err_msg_index = TwitterSnowflake.datecheck ;
if 2
----------------------------< p[''] >------------------------------------------------------------------------
construct parameter set for Web site: from parameters; do some error checking
p[''] = function(frame) local args_t = require ('Module:Arguments').getArgs (frame);
local cite_args_t =
local errors_t = ; -- initialize sequence of error messages with style tag date_number_url_get (args_t, cite_args_t, errors_t); -- add |date=, |number=, |url= to
local author = ((cite_args_t.last1 and cite_args_t.first1) and cite_args_t.last1 .. ', ' .. cite_args_t.first1) or -- concatenate |last= with |first= for |author-mask= (cite_args_t.last1 and cite_args_t.last1) or -- only |last= for |author-mask= (cite_args_t.author1 and cite_args_t.author1:gsub('^%(%((.+)%)%)$', '%1')); -- |author= or |author1= stripped of accept-as-written markup for |author-mask=
if author and args_t.user then cite_args_t['author-mask'] = author .. ' [@' .. (args_t.user or '') .. ']' -- concatenate
frame.args = cite_args_t; -- overwrite frame arguments local rendering = CiteWeb (frame); -- render the template
---------- error messaging ---------- if errors_t[2] then -- errors_t[2] nil when no errors if rendering:find ('cs1-visible-error', 1, true) then -- rendered Web site: with errors will have this string errors_t[1] = errors_t[1]:gsub ('> <', '>; <'); -- insert semicolon to terminate cs1|2 error message string end
errors_t[#errors_t] = errors_t[#errors_t]:gsub (';$',' (help)'); -- replace trailing semicolon with help link table.insert (errors_t, ''); -- close style span tag if mw.title.getCurrentTitle:inNamespace (0) then -- mainspace only table.insert (errors_t, ''); -- add error category end
rendering = rendering .. table.concat (errors_t); -- append error messaging, help links and catagories end return rendering;end
return p