มอดูล:Cite tweet
มอดูลนี้ได้รับการจัดอันดับว่าพร้อมใช้งานทั่วไป มีความสมบูรณ์แล้วและคิดว่าจะปราศจากข้อผิดพลาดและพร้อมสำหรับการใช้งานตามความเหมาะสม พร้อมจะกล่าวถึงในหน้าช่วยเหลือและแหล่งข้อมูลวิกิพีเดียอื่น ๆ ว่าเป็นตัวเลือกสำหรับผู้ใช้ใหม่ในการเรียนรู้ เพื่อลดภาระของเซิร์ฟเวอร์และเอาต์พุตที่ไม่ดี ควรปรับปรุงโดยการทดสอบที่กระบะทราย แทนที่จะแก้ไขแบบลองผิดลองถูกซ้ำ ๆ |
มอดูลนี้ขึ้นอยู่กับมอดูลอื่น ๆ ดังต่อไปนี้ |
การใช้งาน[แก้]
แม่แบบนี้ใช้โดย {{Cite tweet}} เช่น {{#invoke:Cite tweet|main}}
ในแม่แบบหรือในบทความที่ไม่พอดีกับ WP:PEIS limit อาจเรียกโดยตรงว่า {{#invoke:Cite tweet||normal arguments for cite tweet}}
เหมือนกับ {{Cite tweet}} ทุกประการ ยกเว้นพารามิเตอร์ตัวแรกที่ว่างเปล่า
ในบทความปกติใช้ {{Cite tweet}}
แทนทั้งหมด ตามวิกิพีเดีย:เนมสเปซแม่แบบ#มอดูล
คู่มือการใช้งานที่ปรากฏด้านบนนี้ดึงมาจาก มอดูล:Cite tweet/doc (แก้ | ประวัติ) ผู้เขียนสามารถทำการทดลองได้ที่กระบะทราย (สร้าง | คัดลอก) และชุดทดสอบ (สร้าง) ของมอดูลนี้ หน้าย่อยของมอดูลนี้ |
local p = {}
local TwitterSnowflake = require('มอดูล:TwitterSnowflake')
local CiteWeb = require('มอดูล:Cite web')['']
local function _if(arg)
return arg and arg ~= '' or nil
end
p.main = function(frame)
frame.args = frame:getParent().args
return p[''](frame)
end
p[''] = function(frame)
local args = frame.args
local cite_args = {
url = 'https://twitter.com/' .. ((args.user and args.number) and (args.user .. '/status/' .. args.number) or ''),
title = (args.title or ''):gsub('https*://', ''),
['script-title'] = args['script-title'],
['trans-title'] = args['trans-title'],
language = args.language,
['author-link'] = args['author-link'] or args.authorlink,
others = _if(args.retweet) and ('รีทวีตโดย' .. args.retweet),
via = args.link == 'no' and 'ทวิตเตอร์' or '[[ทวิตเตอร์]]',
type = 'ทวีต',
location = args.location,
['access-date'] = args['access-date'] or args.accessdate,
['archive-date'] = args['archive-date'] or args.archivedate,
['archive-url'] = args['archive-url'] or args.archiveurl,
['url-status'] = args['url-status'] or args['dead-url'] or args.deadurl,
ref = args.ref,
df = args.df
}
if _if(args.last1 or args.last) then
cite_args.author = (args.last1 or args.last) ..
(_if(args.first1 or args.first) and (', ' .. (args.first1 or args.first)) or '') ..
' [@' .. (args.user or '') .. ']'
elseif _if(args.author1 or args.author) then
cite_args.author = (args.author1 or args.author) .. ' [@' .. (args.user or '') .. ']'
elseif _if(args['author-link']) then
cite_args.author = args['author-link'] .. ' [@' .. (args.user or '') .. ']'
else
cite_args.author = '@' .. (args.user or '')
end
if _if(tonumber(args.number)) then
cite_args.date = args.date or (_if(args.number) and TwitterSnowflake.snowflakeToDate{ args = {id_str = args.number} })
else
cite_args.date = args.date
end
frame.args = cite_args
local output = CiteWeb(frame)
frame.args = args
-- Error checking
local error_template = '<span class="cs1-visible-error citation-comment">%s</span>'
local errors = {}
if not (_if(args.title) or _if(args['script-title']) or args.user or args.number or args.date) then
-- No title; error message is provided by CS1 module.
errors[1] = ';'
end
if not _if(args.user) then
errors[1 + #errors] = '<kbd>|user=</kbd>; ไม่พบหรือว่าง '
end
if not _if(args.number) then
errors[1 + #errors] = '<kbd>|number=</kbd>; ไม่พบหรือว่าง '
end
errors[1 + #errors] = TwitterSnowflake.datecheck{ args = {
id_str = args.number or '',
date = args.date or '',
error1 = ' <kbd>|date=</kbd> mismatches calculated date from <kbd>|number=</kbd> by two or more days;',
error2 = ' <kbd>|date=</kbd> ไม่พบหรือว่าง และโพสต์ก่อนวันที่ 4 พฤศจิกายน 2010;;',
error3 = ' พารามิเตอร์ <kbd>|number=</kbd> ไม่ถูกต้อง;'
}}
if errors[1] then
local last = errors[#errors]
errors[#errors] = last:sub(1, #last - 1) .. ' ([[แม่แบบ:Cite_tweet#การตรวจจับข้อผิดพลาด|ช่วยเหลือ]])'
local error_out = error_template:rep(#errors):format(unpack(errors))
if mw.title.getCurrentTitle():inNamespace(0) then
error_out = error_out .. '[[หมวดหมู่:แม่แบบ Cite tweet มีข้อผิดพลาด]]'
end
output = output .. error_out
end
return output
end
return p