模組:Cite
外观

![]() | 本模块仅应在条目接近或超过模板展开后长度限制时使用,以缓解引文模板的额外开销造成的压力。除非存在迫切的技术需求,否则应使用常规的CS1系列模板或{{citation}} 模板。 |
![]() | 此模块使用Lua语言: |
{{Cite arXiv}} | arXiv預印本 |
---|---|
{{Cite AV media}} | 影音媒體 |
{{Cite AV media notes}} | 影音媒體內頁說明 |
{{Cite bioRxiv}} | bioRxiv預印本 |
{{Cite book}} | 書籍 |
{{Cite citeseerx}} | CiteSeerX論文 |
{{Cite conference}} | 會議論文 |
{{Cite encyclopedia}} | 引用百科全書的資料 |
{{Cite episode}} | 廣播和電視節目 |
{{Cite interview}} | 訪談 |
{{Cite journal}} | 學術期刊 |
{{Cite magazine}} | 雜誌和期刊 |
{{Cite mailing list}} | 公共郵件列表 |
{{Cite map}} | 地圖 |
{{Cite news}} | 新聞報導 |
{{Cite newsgroup}} | 線上新聞群組 |
{{Cite podcast}} | 播客 |
{{Cite press release}} | 新聞稿 |
{{Cite report}} | 報告 |
{{Cite serial}} | 廣播和電視節目系列 |
{{Cite sign}} | 標誌、匾額、銘牌或徽章 |
{{Cite speech}} | 演講 |
{{Cite ssrn}} | SSRN論文 |
{{Cite techreport}} | 技術報告 |
{{Cite thesis}} | 學位論文 |
{{Cite tweet}} | Twitter推文 |
{{Cite web}} | 上述模板未包含的其他網路資料 |
參見 | |
用法
[编辑]本模块可用于替换接近或超过模板展开后长度限制的条目中的任何CS1/2系列模板。此类使用应仅用于防止条目超出模板限制。必要时,本模块也可用于封装CS1/2模板的模板中。
示例
[编辑]本模块不需要特殊参数,但需要指定CS1模板的规范名称(不带cite
前缀):cite book
→ book
,cite web
→ web
。替换{{citation}}
模板时使用citation
。
模块调用规则:
{{#invoke:cite |<模板名称>|<cs1参数>}}
其中:
#invoke:cite
– 调用本模块|<模板名称>
– 不带cite
前缀的模板规范名称(不区分大小写)|<cs1参数>
–{{cite <模板名称>}}
所需的所有参数
例如从{{cite book}}
转换:
{{cite book |author=作者 |date=1915 |title=标题 |publisher=示例出版社}}
- 作者. 标题. 示例出版社. 1915.
可使用:
{{#invoke:cite |book |author=作者 |date=1915 |title=标题 |publisher=示例出版社}}
- 作者. 标题. 示例出版社. 1915.
-- 源自[[:en:Module:Cite]]的本地化版本。当前基于 https://en.wikipedia.org/w/index.php?title=Module:Cite&oldid=1290436560
-- 本地[[Module:Citation/CS1]]的入口函数citation为全局变量,因此不兼容strict
-- require ('strict');
local cfg = mw.loadData ('Module:Cite/config');
--[[--------------------------< S U B S T I T U T E >----------------------------------------------------------
Substitutes $1, $2, etc in <message> with data from <data_t>. Returns plain-text substituted string when
<data_t> not nil; returns <message> else.
]]
local function substitute (message, data_t)
return data_t and mw.message.newRawMessage (message, data_t):plain() or message;
end
--[[--------------------------< M A K E _ E R R O R _ M S G >--------------------------------------------------
Assembles an error message from module name, message text, help link, and error category.
]]
local function make_error_msg (frame, msg)
local module_name = frame:getTitle(); -- get the module name for prefix and help-link label
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization
local category_link = (0 == namespace) and substitute ('[[Category:$1]]', {cfg.settings_t.err_category}) or '';
return substitute ('<span style="color:#d33">{{[[$1|#invoke:$2]]}}错误:$3 ([[:$4|$5]])</span>$6',
{
module_name, -- the module name with namespace
module_name:gsub ('Module:', ''), -- the module name without namespace
msg, -- the error message
cfg.settings_t.help_text_link, -- help wikilink to text at help page
cfg.settings_t.help, -- help wikilink display text
category_link -- link to error category (for main namespace errors only)
})
end
-- 本地化改动。方法来自[[Module:Cite web]]
local function patch_frame (original_frame, new_args)
local proxyFrame = {
getParent = function(self)
return original_frame
end,
getTitle = function(self)
return 'Module:Citation/CS1'
end,
args = new_args
}
setmetatable(proxyFrame, {
__index = function(t, k)
if type(original_frame[k]) == 'function' then
return function(...)
return original_frame[k](original_frame, select(2, ...))
end
else
return original_frame[k]
end
end
})
return proxyFrame
end
--[[--------------------------< C I T E >---------------------------------------------------------------------
Function to call Module:Citation/CS1/sandbox with appropriate parameters. For use when an article exceeds the
post-expand include size limit.
{{#invoke:cite|book|title=Title}}
]]
local function cite (frame, template)
-- 目前类别参数为英语。若含有非ASCII字符则需改用mw.ustring.lower()
template = template:lower(); -- lowercase for table indexes
if not cfg.known_templates_t[template] then -- do we recognize this template name?
return make_error_msg (frame, substitute (cfg.settings_t.unknown_name, {template})); -- nope; abandon with error message
end
local config_t = {['CitationClass'] = cfg.citation_classes_t[template] or template}; -- set CitationClass value
-- 本地[[Module:Citation/CS1]]与英文维基百科结构不同,只有citation一个入口,且要求传入frame。
-- 它的citation函数会将本层frame的args参数表当作已解析的参数,直接存入内部的config和args变量;
-- 随后再解析并校验parent frame的args参数表(即条目页传给{{cite web}}模板的参数),结果将并入内部的args变量。
-- 考虑到本模块会被用户直接在条目中调用,参数不规范的机会远多于模板作者在模板中预设CS1参数的情形,
-- 因此应当使用Module:Citation/CS1对于{{cite web}}的校验逻辑。
-- 故选择修改frame变量,将本模块的传入参数伪装成parent frame的参数,以复用相关逻辑。
local newFrame = patch_frame(frame, config_t)
return require ('Module:Citation/CS1').citation (newFrame); -- go render the citation
end
--[[--------------------------< E X P O R T S >---------------------------------------------------------------
]]
return setmetatable({}, {__index = -- returns an empty TABLE whose metatable has the __index set so that, for any given KEY, it returns
function(_, template) -- this anonymous function called as function(TABLE, KEY)
return function (frame) return cite (frame, template) end; -- which in turn returns a function that calls cite() with the KEY name
end
})