Module:Cite tweet/sandbox explained

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 modified or notend</p> <p>--date= and |number= parameter values if present. Extract date from |number= and compare to |date=.<p>contruct |url= for Web site: from the base url and |number= and |user=</p> <p>returns nothing; adds date, number, url to <cite_args_t>; adds error message(s) to <errors_t>.</p> </p> <p>local function date_number_url_get (args_t, cite_args_t, errors_t) local err_msg_index;</p> <p>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;<p>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</p> </p> <p>local number = args_t.number; local date = args_t.date; if date then cite_args_t.date = date; -- copy to cite_args_t</p> <p>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 <number> may be valid? <number> cite_args_t.date = TwitterSnowflake.snowflakeToDate ; -- no date supplied so extract a date from |number= else -- here when <number> cannot be converted to a number (invalid)) err_msg_index = 3; -- invalid number end</p> <p>else -- here when |number= is empty or missing err_msg_index = 4; -- |number= required end end</p> <p>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</p> <p>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</p> <p>err_msg_index = TwitterSnowflake.datecheck ;</p> <p>if 2</p> <h2>err_msg_index then -- when no date and posted before twitter epoch cite_args_t.date = nil; -- suppress default date because should not claim in its own voice that the undated post was posted 2010-11-04 end table.insert (errors_t, err_msgs_t[err_msg_index]); -- add error messageend</h2> <p>----------------------------< p[''] >------------------------------------------------------------------------<p>construct parameter set for Web site: from parameters; do some error checking</p> </p> <p>p[''] = function(frame) local args_t = require ('Module:Arguments').getArgs (frame);</p> <p>local cite_args_t =</p> <p>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 <cite_args_t></p> <p>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=</p> <p>if author and args_t.user then cite_args_t['author-mask'] = author .. ' [@' .. (args_t.user or '') .. ']' -- concatenate <author> and |user= into |author-mask= elseif args_t.user then cite_args_t.author1 = '((' .. args_t.user .. '))'; -- just the user name for cs1|2 metadata cite_args_t['author-mask'] = '@' .. args_t.user; -- make a mask for display else -- here when neither <author> nor |user= cite_args_t.author1 = nil; -- so unset end</p> <p>frame.args = cite_args_t; -- overwrite frame arguments local rendering = CiteWeb (frame); -- render the template</p> <p>---------- 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</p> <p>errors_t[#errors_t] = errors_t[#errors_t]:gsub (';$',' (help)'); -- replace trailing semicolon with help link table.insert (errors_t, '</span>'); -- close style span tag if mw.title.getCurrentTitle:inNamespace (0) then -- mainspace only table.insert (errors_t, ''); -- add error category end</p> <p>rendering = rendering .. table.concat (errors_t); -- append error messaging, help links and catagories end return rendering;end</p> <p>return p</p><div class="Footer"> <div class="robots-noindex"><p>This article is licensed under the <a href="http://www.gnu.org/copyleft/fdl.html" rel="nofollow">GNU Free Documentation License</a>. It uses material from the Wikipedia article "<a href="http://en.wikipedia.org/wiki/Module%3aCite_tweet%2fsandbox" rel="nofollow">Module:Cite tweet/sandbox</a>".</p></div> <p>Except where otherwise indicated, Everything.Explained.Today is © Copyright 2009-2024, A B Cryer, All Rights Reserved. <a href="http://explained.today/cookie_policy.htm">Cookie policy</a>.</p> </div> </div> </body> </html>