Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Module:Cite tweet

Permanently protected module
From Wikipedia, the free encyclopedia
Module documentation[view] [edit] [history] [purge]
Thismodule is rated asready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned onhelp pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed throughsandbox testing rather than repeated trial-and-error editing.
Page template-protectedThis module is currentlyprotected from editing.
See theprotection policy andprotection log for more details. Please discuss any changes on thetalk page; you maysubmit an edit request to ask anadministrator to make an edit if it isuncontroversial or supported byconsensus. You may alsorequest that this page be unprotected.
WarningThis Lua module is used onapproximately 47,000 pages and changes may be widely noticed. Test changes in the module's/sandbox or/testcases subpages, or in your ownmodule sandbox. Consider discussing changes on thetalk page before implementing them.
This module depends on the following other modules:

Usage

This template implements{{Cite tweet}}, as{{#invoke:Cite tweet|main}}.

In templates, or in articles which cannot otherwise fit within theWP:PEIS limit, the module may be called directly as{{#invoke:Cite tweet|main|<normal arguments for cite tweet>}}: i.e. exactly the same as{{Cite tweet}} except for the extra first positional parameter.

In all normal articles use{{Cite tweet}} instead, perWikipedia:Template namespace#Modules.

The abovedocumentation istranscluded fromModule:Cite tweet/doc.(edit |history)
Editors can experiment in this module'ssandbox(edit |diff) and testcases(create) pages.
Subpages of this module.

localTwitterSnowflake=require('Module:TwitterSnowflake')localerr_msgs_t={-- a sequence of snowflake date error messages; all must be terminated with a semicolon (;)' <kbd>&#124;date=</kbd> / <kbd>&#124;number=</kbd> mismatch;',-- [1]' <kbd>&#124;date=</kbd> required;',-- [2]' Invalid <kbd>&#124;number=</kbd>;',-- [3]' Missing or empty <kbd>&#124;number=</kbd>;',-- [4]' Missing or empty <kbd>&#124;user=</kbd>;'-- [5]}--[[--------------------------< S U P P R E S S _ U R L _ I N _ T I T L E >------------------------------------This function searches for and suppresses urls in |title=, |script-title=, and |trans-title= parameters so that{{cite web}} 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<nowiki>..</nowiki> tags.]]localfunctionsuppress_url_in_title(frame,title)localschemes={-- schemes commonly found in tweets'https://','http://','ftp://',}iftitlethen-- when there is a title, suppress any urls with known schemes; abandon elsefor_,schemeinipairs(schemes)do-- spin through the list of schemes looking for a matchtitle=title:gsub(scheme,frame:callParserFunction('#tag',{'nowiki',scheme}));-- replace the scheme with its nowiki'd form (a strip marker)endendreturntitle;-- done; return <title> modified or notend--[[--------------------------< D A T E _ N U M B E R _ U R L _ G E T >----------------------------------------extract |date= and |number= parameter values if present.  Extract date from |number= and compare to |date=.contruct |url= for {{cite web}} from the base url and |number= and |user=returns nothing; adds date, number, url to <cite_args_t>; adds error message(s) to <errors_t>.]]localfunctiondate_number_url_get(args_t,cite_args_t,errors_t)localerr_msg_index;cite_args_t.url='https://x.com/';-- initialize with minimal base url because {{cite web}} requires |url=ifnotargs_t.userthentable.insert(errors_t,err_msgs_t[5]);-- error: missing or empty |user=endifnotargs_t.dateandnotargs_t.numberthenerr_msg_index=4;-- error: missing or empty |number=elseiftonumber(args_t.number)then-- |number= without |date=? use numberiftonumber(args_t.number)thencite_args_t.date=args_t.dateor(args_t.numberandTwitterSnowflake.snowflakeToDate{args={id_str=args_t.number}});elsecite_args_t.date=args_t.date;endcite_args_t.number=args_t.number;ifargs_t.userthen-- |number= appears to have a valid value; if |user= has a valuecite_args_t.url=cite_args_t.url..args_t.user..'/status/'..args_t.number;-- construct |url= for {{cite web}}endelseifargs_t.numberthen-- |number= with a value that can't be converted to a number; invaliderr_msg_index=3;-- error: invalid number (couldn't convert to number)elseifnotargs_t.numberthen-- |date= without |number= use datecite_args_t.date=args_t.date;-- |date= has a value, use iterr_msg_index=4;-- error: missing or empty |number=endiferr_msg_indexthentable.insert(errors_t,err_msgs_t[err_msg_index]);-- invalid number or missing necessary parameters so abandonreturn;enderr_msg_index=TwitterSnowflake.datecheck({args={-- returns error message index number on error; nil elseid_str=args_t.numberor'',date=args_t.dateor'',error1=1,-- these numbers are indexes into <err_msgs_t> to override snowflake default error messageserror2=2,-- done this way to avoid long string comparison looking forerror3=3-- the undated-pre-twitter-epoch-post message}});if2==err_msg_indexthen-- when no date and posted before twitter epochcite_args_t.date=nil;-- suppress default date because {{cite tweet}} should not claim in its own voice that the undated post was posted 2010-11-04endtable.insert(errors_t,err_msgs_t[err_msg_index]);-- add error messageend--[[--------------------------< M A I N >----------------------------------------------------------------------construct parameter set for {{cite web}} from {{cite tweet}} parameters;  do some error checking]]localfunctionmain(frame)localargs_t=require('Module:Arguments').getArgs(frame);localcite_args_t={title=suppress_url_in_title(frame,args_t.title),['script-title']=suppress_url_in_title(frame,args_t['script-title']),['trans-title']=suppress_url_in_title(frame,args_t['trans-title']),language=args_t.language,last1=args_t.last1orargs_t.last,first1=args_t.first1orargs_t.first,author1=args_t.author1orargs_t.author,['author-link']=args_t['author-link']orargs_t.authorlink,others=args_t.retweetand('Retweeted by '..args_t.retweet),via=args_t.link=='no'and'Twitter'or'[[Twitter]]',type=args_t.link=='no'and'Tweet'or'[[Tweet (social media)|Tweet]]',location=args_t.location,-- why |location=?  tweets are online; there is no publication place['access-date']=args_t['access-date']orargs_t.accessdate,['archive-date']=args_t['archive-date']orargs_t.archivedate,['archive-url']=args_t['archive-url']orargs_t.archiveurl,['url-status']=args_t['url-status'],['url-access']=args_t['url-access'],quote=args_t.quote,ref=args_t.ref,df=args_t.df,mode=args_t.mode}localerrors_t={'<span class="cs1-visible-error citation-comment"> <kbd>{{[[Template:Cite tweet|Cite tweet]]}}</kbd>:'};-- initialize sequence of error messages with style tagdate_number_url_get(args_t,cite_args_t,errors_t);-- add |date=, |number=, |url= to <cite_args_t>localauthor=((cite_args_t.last1andcite_args_t.first1)andcite_args_t.last1..', '..cite_args_t.first1)or-- concatenate |last= with |first= for |author-mask=(cite_args_t.last1andcite_args_t.last1)or-- only |last= for |author-mask=(cite_args_t.author1andcite_args_t.author1:gsub('^%(%((.+)%)%)$','%1'));-- |author= or |author1= stripped of accept-as-written markup for |author-mask=ifauthorandargs_t.userthencite_args_t['author-mask']=author..' [@'..(args_t.useror'')..']'-- concatenate <author> and |user= into |author-mask=elseifargs_t.userthencite_args_t.author1='(('..args_t.user..'))';-- just the user name for cs1|2 metadatacite_args_t['author-mask']='@'..args_t.user;-- make a mask for displayelse-- here when neither <author> nor |user=cite_args_t.author1=nil;-- so unsetendlocalrendering=require('Module:Citation/CS1')._citation(nil,cite_args_t,{CitationClass='web'});---------- error messaging ----------iferrors_t[2]then-- errors_t[2] nil when no errorsifrendering:find('cs1-visible-error',1,true)then-- rendered {{cite web}} with errors will have this stringerrors_t[1]=errors_t[1]:gsub('> <','>; <');-- insert semicolon to terminate cs1|2 error message stringenderrors_t[#errors_t]=errors_t[#errors_t]:gsub(';$',' ([[Template:Cite_tweet#Error_detection|help]])');-- replace trailing semicolon with help linktable.insert(errors_t,'</span>');-- close style span tagifmw.title.getCurrentTitle():inNamespace(0)then-- mainspace onlytable.insert(errors_t,'[[Category:Cite tweet templates with errors]]');-- add error categoryendrendering=rendering..table.concat(errors_t);-- append error messaging, help links and catagoriesendreturnrendering;end--[[--------------------------< E X P O R T S >----------------------------------------------------------------]]return{main=main,-- entry points; {{#invoke:cite tweet|main|...}} is preferred['']=main,-- but {{#invoke:cite tweet||...}} is also acceptable}
Retrieved from "https://en.wikipedia.org/w/index.php?title=Module:Cite_tweet&oldid=1322155807"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp