十八大什么时候召开的| 免疫抑制剂是什么意思| 为什么明星整牙那么快| 眩晕停又叫什么| 晚上吃什么可以减肥| 重色轻友什么意思| 铁皮石斛能治什么病| 党委常委是什么级别| 教师节什么时候| 婴儿八个月可以吃什么辅食| 开天门是什么意思| 隐翅虫是什么样子| 逝者如斯夫是什么意思| 心脏供血不足吃什么药好| 孕妇梦见老鼠是什么意思| 什么是客单价| 树欲静而风不止什么意思| 卡西欧手表属于什么档次| 795是什么意思| dh什么意思| 2岁打什么疫苗| 逆时针是什么方向| 芙蓉是什么意思| 精神紊乱吃什么药| 吃什么不升血糖| 肌酐偏低有什么危害| 粘纤是什么材料| 早晨起床口干口苦是什么原因| 失眠吃什么食物最有效| 251什么意思| 湿气重是什么意思| 滴度是什么意思| 宫颈病变有什么症状| shake是什么意思| 榴莲吃多了有什么坏处| 性交是什么| 蝉什么时候出现| 吃什么瘦肚子| 痱子用什么药| 属龙的五行属性是什么| 骚扰是什么意思| 孩子高烧不退是什么原因| 五脏是什么| 家五行属性是什么| 什么鸡不能吃| 1950年是什么年| iq是什么意思| 一棵树是什么品牌| 438是什么意思| 盥洗室什么意思| 农历4月14日是什么星座| 退而求其次是什么意思| 怀孕梦到老公出轨预示什么| 金桔什么时候开花结果| 梦见生姜是什么意思| mri检查是什么| 天蝎座后面是什么星座| 门诊号是什么意思| 干咳喝什么止咳糖浆好| 马子什么意思| 上钟什么意思| 月经血是黑色的是什么原因| 一什么千什么| 吃什么可降低胆固醇| 世界上最高的山是什么山| 免疫球蛋白是什么东西| 1月15日什么星座| 脚麻吃什么药有效| 肝炎有什么症状| 切除子宫对身体有什么伤害| 精液长什么样| 树菠萝什么时候成熟| 皮什么结构| 割包皮挂什么科| 什么驱蚊效果最好| 牟利什么意思| 什么香什么鼻| 莫逆之交是什么意思| 6月4号是什么星座| 润滑油是干什么用的| 屁股又叫什么| 进击的巨人真相是什么| 为什么要当兵| 支气管炎是什么症状| 一只眼睛肿了是什么原因| 舌苔白腻吃什么药| 什么东西助眠| 核心是什么意思| 合欢树为什么叫鬼树| 支教回来后有什么待遇| sand是什么颜色| 什么是中产阶级| 手掌发红是什么病| 梦见狗熊是什么预兆| 神经性头疼吃什么药好| 哺乳期吃避孕药对孩子有什么影响| 月字旁的字与什么有关| 陆地上最大的动物是什么| 过敏性紫癜看什么科| 小时的单位是什么| nfc果汁是什么意思| 发烧可以吃什么水果| 心属于五行属什么| 脑残是什么意思| 什么样的伤口需要缝针| 与虎谋皮是什么生肖| 痔疮什么东西不能吃| 孩子是ab型父母是什么血型| 棘突是什么意思| 胃肠功能紊乱是什么意思| 荣字五行属什么| 坤位是什么方向| 巨是什么结构| 手麻是什么原因引起| 明年是什么生肖| 立字五行属什么| 阴道口瘙痒用什么药| 湿气重的人适合吃什么| 氯雷他定什么时候吃| 甲状腺结节不能吃什么| 强扭的瓜不甜什么意思| 胰腺炎吃什么食物| 野生型是什么意思| 西瓜适合什么土壤种植| 送老师什么礼物最好| 男人右眼跳是什么预兆| 坐疮是什么样的图片| 老人出汗多是什么原因| 屈光和近视有什么区别| 血糖低会出现什么症状| 吃鱼油有什么好处| 眼眶发青是什么原因| 黄历中的入宅是什么意思| 丙寅五行属什么| 梦见自己开车是什么意思| 阄是什么意思| 早上吃黄瓜有什么好处| 胆碱酯酶低是什么原因| 老花眼视力模糊有什么办法解决吗| 间谍是什么意思| 梦见盗墓是什么意思| 为什么会有跳蚤| 陈皮治什么病| 什么门比较好| 什么样的人容易得心梗| 博字属于五行属什么| 肝胆胰腺属于什么科| 肉烧什么好吃| 感染性疾病科看什么病| 兵马未动粮草先行是什么意思| 老人流口水是什么原因引起的| OB什么意思| 择日什么意思| 凝血四项是检查什么的| flour是什么意思| 3.13是什么星座| 血管硬化吃什么能软化| 孕妇鼻炎犯了可以用什么药治疗| 更年期失眠吃什么药调理效果好| 打嗝吃什么药效果好| 打脸是什么意思| 妇科假丝酵母菌是什么病| 吃饭是什么意思| 什么是牙槽骨突出图片| 买什么样的老花镜好| 晚上11点到12点是什么时辰| 心服口服的意思是什么| 梦见吃蜂蜜是什么预兆| 化疗后吃什么食物最好| 辛亥革命是什么时候| 十三太保什么意思| 中耳炎挂什么科| 指甲有条纹是什么原因| 风疟病是什么意思| 尿常规白细胞高是什么原因| 手掌疼是什么原因| 香港有什么东西值得买| nfl是什么意思| 央行放水是什么意思| 潘多拉魔盒是什么意思| 赊账是什么意思| 吃紫甘蓝有什么好处| 排骨炖什么汤止咳润肺| 肺部积液吃什么药| 甲胎蛋白是检查什么的| gmp认证是什么意思| 吃桃子对身体有什么好处| 打开图片用什么软件| 青海有什么湖| 喝茶水对身体有什么好处| 为什么会失眠| 狙击蟹吃什么| 喜五行属什么| 什么是姑息治疗| 双币信用卡是什么意思| 摆摊卖什么好| 清新的什么填空| 双肾小结石是什么意思| 上眼皮痒是什么原因| 金为什么克木| 云彩像什么| 吃避孕药对身体有什么影响| 克勤克俭的克是什么意思| 心率过速是什么原因| 全身皮肤瘙痒是什么原因| 唇色深的人适合什么颜色的口红| 线差是什么意思| 身份证带x是什么意思| 过堂是什么意思| 月亮什么颜色| 大腿肿胀是什么原因| 入赘是什么意思| pd950是什么金| cph是什么意思| 左卵巢囊性结构是什么意思| 喝酒后头晕是什么原因| 眼睛出现飞蚊症什么原因怎么办| 是什么有什么| 什么的日子| 怀孕第一个月有什么特征| 阴煞是什么意思| 血糖高什么东西不能吃| 开字加一笔是什么字| 冰心原名叫什么| 光滑念珠菌是什么意思| 闲敲棋子落灯花上一句是什么| 爬山膝盖疼是什么原因| 活好的女人有什么表现| 活碱是什么| 尿隐血是什么原因引起的| 心包填塞三联征是什么| 月经来了头疼是什么原因导致的| 医学五行属什么| 为什么一直流鼻涕| 子时是什么时间| 穷书生是什么生肖| 血浆是什么颜色| 呕吐出血是什么原因| 解表药是什么意思| 胸口疼是什么原因| 南冠指的是什么| 孕妇贫血有什么症状| 大脚趾头疼是什么原因| 什么是美尼尔氏综合症| 7月30日是什么日子| 更年期失眠吃什么药| 卵泡是什么东西| 千里马比喻什么人| 面藕是什么| 红蓝光照射有什么作用| 容易做梦是什么原因引起的| 什么叫会车| 淡奶油是什么| 什么是对称轴| 总是犯困是什么原因| NF什么意思| 贤上腺瘤是什么意思| 切片是什么意思| 倾情是什么意思| 月经老提前是什么原因| 西洋参泡水喝有什么好处| 牛肉跟什么炒好吃| 梦见自己的手机丢了是什么意思| 旺夫脸是什么脸型| 百度Jump to content

执法全留痕 查处更高效

From Wikisource
百度 ”  据了解,晓书馆藏书5万册,分上下两层,包含中国历史、中国文学、世界文学、艺术绘画、哲学宗教、儿童读物等类别。

require('strict');
local getArgs = require ('Module:Arguments').getArgs;


--[[--------------------------< A R G S _ D E F A U L T >------------------------------------------------------

a table to specify initial values.

]]

local args_default = {
	bracket_left = '',
	bracket_right = '',
	bracket_year_left = '',
	bracket_year_right = '',
	postscript = '',
	page = '',
	pages = '',
	location = '',
	page_sep = ", p.&nbsp;",
	pages_sep = ", pp.&nbsp;",
	ref = '',
	template = 'harv',															-- if template name not provided in {{#invoke:}} use this
	};


--[[--------------------------< T A R G E T _ C H E C K >------------------------------------------------------

look for anchor_id (CITEREF name-list and year or text from |ref=) in anchor_id_list

the 'no target' error may be suppressed with |ignore-err=yes when target cannot be found because target is inside
a template that wraps another template; 'multiple targets' error may not be suppressed

]]

local function target_check (anchor_id, args)
	local namespace = mw.title.getCurrentTitle().namespace;
	local anchor_id_list_module = mw.loadData ('Module:Footnotes/anchor_id_list');
	local anchor_id_list = anchor_id_list_module.anchor_id_list;
	local article_whitelist = anchor_id_list_module.article_whitelist;
	local template_list = anchor_id_list_module.template_list;
	
	local whitelist_module = mw.loadData ('Module:Footnotes/whitelist');
	local whitelist = whitelist_module.whitelist;
	local special_patterns = whitelist_module.special_patterns;
	local DNB_special_patterns = whitelist_module.DNB_special_patterns;
	local DNB_template_names = whitelist_module.DNB_template_names;

	if 10 == namespace then
		return '';																-- automatic form of |no-tracking=yes; TODO: is this too broad?
	end

	local tally = anchor_id_list[anchor_id];									-- nil when anchor_id not in list; else a tally
	local msg;
	local category;

	if not tally then
		if args.ignore then
			return '';															-- if ignore is true then no message, no category
		end
		
		if article_whitelist and article_whitelist[anchor_id] then				-- if an article-local whitelist and anchor ID is in it
			return '';															-- done
		end
		
		local wl_anchor_id = anchor_id;											-- copy to be modified to index into the whitelist
		
		if args.year then														-- for anchor IDs created by this template (not in |ref=) that have a date
			if args.year:match ('%d%l$') or										-- use the date value to determine if we should remove the disambiguator
				args.year:match ('n%.d%.%l$') or
				args.year:match ('nd%l$') then
					wl_anchor_id = wl_anchor_id:gsub ('%l$', '');				-- remove the disambiguator
			end
		end		

		local t_tbl = whitelist[wl_anchor_id];									-- get list of templates associated with this anchor ID

		if t_tbl then															-- when anchor ID not whitelisted t_tbl is nil
			for _, t in ipairs (t_tbl) do										-- spin through the list of templates associated with this anchor ID
				if template_list[t] then										-- if associated template is found in the list of templates in the article
					return '';													-- anchor ID is whitlisted and article has matching template so no error
				end
			end
		end

		for _, pattern in ipairs (special_patterns) do							-- spin through the spcial patterns and try to match
			if anchor_id:match (pattern) then
				return '';
			end
		end

		for _, dnb_t in ipairs (DNB_template_names or {}) do					-- getting desparate now, are there any DNB templates? DNB_template_names may be nil; empty table prevents script error
			if template_list[dnb_t] then										-- if the article has this DNB template
				for _, pattern in ipairs (DNB_special_patterns) do				-- spin through the DNB-specifiec wildcard patterns
					if anchor_id:match (pattern) then							-- and attempt a match
						return '';												-- found a match
					end
				end
			end
		end

		msg = 'no target: ' .. anchor_id;										-- anchor_id not found
		category = '[[Category:Harv and Sfn no-target errors]]';

	elseif 1 < tally then
		msg = 'multiple targets (' .. tally .. '×): ' .. anchor_id;				-- more than one anchor_id in this article
		category = 0 == namespace and '[[Category:Harv and Sfn multiple-target errors]]' or '';								-- only categorize in article space
		return '<span class="error harv-error" style="display: inline; font-size:100%"> ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category;
	end

--	category = 0 == namespace and '[[Category:Harv and Sfn template errors]]' or '';	-- only categorize in article space
	category = 0 == namespace and category or '';								-- only categorize in article space

--use this version to show error messages
--	return msg and '<span class="error harv-error" style="display: inline; font-size:100%"> ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';
--use this version to hide error messages
	return msg and '<span class="error harv-error" style="display: none; font-size:100%"> ' .. args.template .. ' error: ' .. msg .. ' ([[:Category:Harv and Sfn template errors|help]])</span>' .. category or '';

end


--[[--------------------------< I S _ Y E A R >----------------------------------------------------------------

evaluates param to see if it is one of these forms with or without lowercase letter disambiguator:
	YYYY
	n.d.
	nd	
	c. YYYY
	YYYY–YYYY	(separator is endash)
	YYYY–YY		(separator is endash)

return true when param has a recognized form; false else

]]

local patterns_date= {
	'^%d%d%d%d?%l?$',
	'^n%.d%.%l?$',
	'^nd%l?$',
	'^c%. %d%d%d%d?%l?$',
	'^%d%d%d%d–%d%d%d%d%l?$',
	'^%d%d%d%d–%d%d%l?$',
	}

local function is_year (param, args)
	args.year = '';																-- used for harv error; 
	
	for _, pattern in ipairs (patterns_date) do
		if mw.ustring.match (param, pattern) then
			args.year = param;													-- used for harv error; 
			return true;
		end
	end
end


--[[--------------------------< C O R E >----------------------------------------------------------------------

returns an anchor link (CITEREF) formed from one to four author names, year, and insource location (|p=, |pp=, loc=)

]]

local function core( args )
	local result;
	local err_msg = ''

	if args.P5 ~= '' then
		if is_year (args.P5, args) then
			result = table.concat ({args.P1, ' et al. ', args.bracket_year_left, args.P5, args.bracket_year_right});
		else
			args.P5 = '';														-- when P5 not a year don't include in anchor
			result = table.concat ({args.P1, ' et al.'});						-- and don't render it
		end

	elseif args.P4 ~= '' then
		if is_year (args.P4, args) then
			result = table.concat ({args.P1, ', ', args.P2, ' &amp; ', args.P3, ' ', args.bracket_year_left, args.P4, args.bracket_year_right});	-- three names and a year
		else
			result = table.concat ({args.P1, ' et al.'});						-- four names
		end

	elseif args.P3 ~= '' then
		if is_year (args.P3, args) then
			result = table.concat ({args.P1, ' &amp; ', args.P2, ' ', args.bracket_year_left, args.P3, args.bracket_year_right});	-- two names and a year
		else
			result = table.concat ({args.P1, ', ', args.P2, ' ', ' &amp; ', args.P3});	-- three names
		end
			
	elseif args.P2 ~= '' then
		if is_year (args.P2, args) then
			result = table.concat ({args.P1, ' ', args.bracket_year_left, args.P2, args.bracket_year_right});	-- one name and year
		else
			result = table.concat ({args.P1, ' &amp; ', args.P2});				-- two names
		end
		
	else
		result = args.P1;														-- one name
	end
																				-- when author-date result ends with a dot (typically when the last positional parameter holds 'n.d.')
																				-- and when no in-source location (no |p=, |pp=, or |loc=)
																				-- and when the first or only character in args.postscript is a dot
																				-- remove the author-date result trailing dot
																				-- the author-date result trailing dot will be replaced later with the content of args.postscript (usually a dot)
	if ('.' == result:sub(-1)) and ('.' == args.postscript:sub(1)) and ('' == args.page) and ('' == args.pages) and ('' == args.location) then
		result = result:gsub ('%.$', '');
	end
	
	if args.ref ~= 'none' then
		local anchor_id;
		if args.ref ~= '' then
			anchor_id = mw.uri.anchorEncode (args.ref);
			err_msg = target_check (anchor_id, args);
			result = table.concat ({'[[#', anchor_id, '|', result, ']]'});
		else
			anchor_id = mw.uri.anchorEncode (table.concat ({'CITEREF', args.P1, args.P2, args.P3, args.P4, args.P5}));
			err_msg = target_check (anchor_id, args);
			result = table.concat ({'[[#', anchor_id, '|', result, ']]'});
		end
	end

	if args.page ~= '' then
		result = table.concat ({result, args.page_sep, args.page});
	elseif args.pages ~= ''then
		result = table.concat ({result, args.pages_sep, args.pages});
	end      

	if args.location ~= '' then
		result = table.concat ({result, ', ', args.location});
	end

	result = table.concat ({args.bracket_left, result, args.bracket_right, args.postscript}):gsub ('%s+', ' ');		-- strip redundant spaces
	return result .. err_msg;
end


--[[--------------------------< H Y P H E N _ T O _ D A S H >--------------------------------------------------

Converts a hyphen to a dash under certain conditions.  The hyphen must separate
like items; unlike items are returned unmodified.  These forms are modified:
	letter - letter (A - B)
	digit - digit (4-5)
	digit separator digit - digit separator digit (4.1-4.5 or 4-1-4-5)
	letterdigit - letterdigit (A1-A5) (an optional separator between letter and
		digit is supported – a.1-a.5 or a-1-a-5)
	digitletter - digitletter (5a - 5d) (an optional separator between letter and
		digit is supported – 5.a-5.d or 5-a-5-d)

any other forms are returned unmodified.

str may be a comma- or semicolon-separated list

This code copied from Module:Citation/CS1.  The only modification is to require Module:Citation/CS1/Utilities
so that it has access to the functions is_set() and has_accept_as_written()

]]

local function hyphen_to_dash( str )
	local utilities = require ('Module:Citation/CS1/Utilities');				-- only modification so that this function has access to is_set() and has_accept_as_written()

	if not utilities.is_set (str) then
		return str;
	end

	local accept; -- Boolean

	str = str:gsub ('&[nm]dash;', {['&ndash;'] = '–', ['&mdash;'] = '—'});		-- replace &mdash; and &ndash; entities with their characters; semicolon mucks up the text.split
	str = str:gsub ('&#45;', '-'); -- replace HTML numeric entity with hyphen character

	str = str:gsub ('&nbsp;', ' '); -- replace &nbsp; entity with generic keyboard space character
	
	local out = {};
	local list = mw.text.split (str, '%s*[,;]%s*');								-- split str at comma or semicolon separators if there are any

	for _, item in ipairs (list) do												-- for each item in the list
		item, accept = utilities.has_accept_as_written (item);					-- remove accept-this-as-written markup when it wraps all of item
		if not accept and mw.ustring.match (item, '^%w*[%.%-]?%w+%s*[%-–—]%s*%w*[%.%-]?%w+$') then	-- if a hyphenated range or has endash or emdash separators
			if item:match ('^%a+[%.%-]?%d+%s*%-%s*%a+[%.%-]?%d+$') or			-- letterdigit hyphen letterdigit (optional separator between letter and digit)
				item:match ('^%d+[%.%-]?%a+%s*%-%s*%d+[%.%-]?%a+$') or			-- digitletter hyphen digitletter (optional separator between digit and letter)
				item:match ('^%d+[%.%-]%d+%s*%-%s*%d+[%.%-]%d+$') or			-- digit separator digit hyphen digit separator digit
				item:match ('^%d+%s*%-%s*%d+$') or								-- digit hyphen digit
				item:match ('^%a+%s*%-%s*%a+$') then							-- letter hyphen letter
					item = item:gsub ('(%w*[%.%-]?%w+)%s*%-%s*(%w*[%.%-]?%w+)', '%1–%2');	-- replace hyphen, remove extraneous space characters
			else
				item = mw.ustring.gsub (item, '%s*[–—]%s*', '–');				-- for endash or emdash separated ranges, replace em with en, remove extraneous whitespace
			end
		end
		table.insert (out, item);												-- add the (possibly modified) item to the output table
	end

	local temp_str = '';														-- concatenate the output table into a comma separated string
	temp_str, accept = utilities.has_accept_as_written (table.concat (out, ', ')); -- remove accept-this-as-written markup when it wraps all of concatenated out
	if accept then
		temp_str = utilities.has_accept_as_written (str);						-- when global markup removed, return original str; do it this way to suppress boolean second return value
		return temp_str;
	else
		return temp_str;														-- else, return assembled temp_str
	end
end


--[[--------------------------< A R G S  _ F E T C H >---------------------------------------------------------

Because all of the templates share a common set of parameters, a single common function to fetch those parameters
from frame and parent frame.

]]

local function args_fetch (frame, ps)
	local args = args_default;													-- create a copy of the default table
	local pframe = frame:getParent();											-- point to the template's parameter table

	for k, v in pairs (frame.args) do											-- override defaults with values provided in the #invoke: if any
		args[k] = v;	   
	end
	
	args.postscript = pframe.args.postscript or pframe.args.ps or ps;
	if 'none' == args.postscript then
		args.postscript = '';
	end
	args.page = pframe.args.p or pframe.args.page or '';
	args.pages = pframe.args.pp or pframe.args.pages or '';
	args.pages = ('' ~= args.pages) and hyphen_to_dash (args.pages) or '';
	args.location = pframe.args.at or pframe.args.loc or '';
	args.ref = pframe.args.ref or pframe.args.Ref or '';
	args.ignore = ('yes' == pframe.args['ignore-false-positive']) or ('yes' == pframe.args['ignore-err']);

	for i, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do						-- loop through the five positional parameters and trim if set else empty string
		args[v] = (pframe.args[i] and mw.text.trim (pframe.args[i])) or '';
	end

	if args.P5 and not is_year (args.P5, args) then
		local i = 6;															-- initialize the indexer to the sixth positional parameter
		while pframe.args[i] do													-- in case there are too many authors loop through the authors looking for a year
			local v = mw.text.trim (pframe.args[i]);							-- trim
			if is_year (v, args) then											-- if a year
				args.P5 = v;													-- overwrite whatever was in args.P5 with year
				break;															-- and abandon the search
			end
			i = i + 1;															-- bump the indexer
		end
	end
	return args;
end


--[[--------------------------< H A R V A R D _ C I T A T I O N >----------------------------------------------

common entry point for:
	{{harvard citation}} aka {{harv}}
	{{Harvard citation no brackets}} aka {{harvnb}}
	{{harvcol}}
	{{harvcolnb}}
	{{harvcoltxt}}
	{{Harvard citation text}} aka {{harvtxt}}
	{{Harvp}}

Distinguishing features (brackets and page separators) are specified in this module's {{#invoke}} in the respective templates.

]]

local function harvard_citation (frame)
	local args = args_fetch (frame, '');										-- get the template and invoke parameters; default postscript is empty string

	return core (args);
end


--[[--------------------------< S T R I P _ U R L >------------------------------------------------------------

used by sfn() and sfnm().  This function fixes an issue with reference tooltip gadget where the tooltip is not displayed
when an insource locator (|p=, |pp=, |loc=) has an external wikilink that contains a # character

strip uri-reserved characters from urls in |p=, |pp-, and |loc= parameters  The researved characters are:
	!#$&'()*+,/:;=?@[]
	
]]

local function strip_url (pages)
	local escaped_uri;
	if not pages or ('' == pages) then
		return pages;
	end
	
	for uri in pages:gmatch ('%[(%a[%w%+%.%-]*://%S+)') do						-- for each external link get the uri
		escaped_uri = uri:gsub ("([%(%)%.%%%+%-%*%?%[%^%$%]])", "%%%1" );		-- save a copy with lua pattern characters escaped
		uri = uri:gsub ("[!#%$&'%(%)%*%+,/:;=%?@%[%]%.%%]", '');				-- remove reserved characters and '%' because '%20' (space character) is a lua 'invalid capture index'
		pages = pages:gsub (escaped_uri, uri, 1);								-- replace original uri with the stripped version
	end
	
	return pages;
end


--[[--------------------------< S F N >------------------------------------------------------------------------

entry point for {{sfn}} and {{sfnp}}

]]

local function sfn (frame)
	local args = args_fetch (frame, '.');										-- get the template and invoke parameters; default postscript is a dot

	local result = core (args);													-- go make a CITEREF anchor
																				-- put it all together and then strip redundant spaces
	local name = table.concat ({'FOOTNOTE', args.P1, args.P2, args.P3, args.P4, args.P5, strip_url (args.page), strip_url (args.pages), strip_url (args.location)}):gsub ('%s+', ' ');

	return frame:extensionTag ({name='ref', args={name=name}, content=result});	

	
end


--[[--------------------------< S F N M >----------------------------------------------------------------------

common entry point for {{sfnm}} and {{sfnmp}}

Distinguishing features (brackets) are specified in this module's {{#invoke}} in the respective templates.

]]

local function sfnm (frame)
	local args = args_default;													-- create a copy of the default table
	local pframe = frame:getParent();											-- point to the template's parameter table
	
	local n = 1;																-- index of source; this is the 'n' in na1, ny, etc
	local first_pnum = 1;														-- first of a pair of positional parameters
	local second_pnum = 2;														-- second of a pair of positional parameters

	local last_ps = 0;															-- index of the last source with |nps= set
	local last_index = 0;														-- index of the last source; these used to determine which of |ps= or |nps= will terminate the whole rendering

	local out = {};																-- table to hold rendered sources
	local footnote = {'FOOTNOTE'};												-- all author, date, insource location stuff becomes part of the reference's footnote id; added as we go

	for k, v in pairs (frame.args) do											-- override defaults with values provided in the #invoke: if any
		args[k] = v;	   
	end
	
	while true do
		if not pframe.args[table.concat ({n, 'a1'})] and not pframe.args[first_pnum] then
			break;																-- no na1 or matching positional parameter so done
		end
		
		if pframe.args[table.concat ({n, 'a1'})] then							-- does this source use named parameters?
			for _, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do				-- initialize for this source
				args[v] = '';
			end

			for i, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do				-- extract author and year parameters for this source
				args[v] = pframe.args[table.concat ({n, 'a', i})] or '';		-- attempt to assign author name
				if '' == args[v] then											-- when there wasn't an author name
					args[v] = pframe.args[table.concat ({n, 'y'})] or '';		-- attempt to assign year
					break;														-- done with author/date for this source
				end
			end

		else																	-- this source uses positional parameters
			args.P1 = mw.text.trim (pframe.args[first_pnum]);					-- yes, only one author supported
			args.P2 = (pframe.args[second_pnum] and mw.text.trim (pframe.args[second_pnum])) or '';	-- when positional author, year must also be positional

			for _, v in ipairs ({'P3', 'P4', 'P5'}) do							-- blank the rest of these for this source
				args[v] = '';
			end

			first_pnum = first_pnum + 2;										-- source must use positional author and positional year
			second_pnum = first_pnum + 1;										-- bump these for possible next positional source
		end
		
		args.postscript = pframe.args[table.concat ({n, 'ps'})] or '';
		if 'none' == args.postscript then										-- this for compatibility with other footnote templates; does nothing
			args.postscript = '';
		end

		args.ref = pframe.args[table.concat ({n, 'ref'})] or '';				-- alternate reference for this source

		args.page = pframe.args[table.concat ({n, 'p'})] or '';					-- insource locations for this source
		args.pages = pframe.args[table.concat ({n, 'pp'})] or '';
		args.pages = ('' ~= args.pages) and hyphen_to_dash (args.pages) or '';
		args.location = pframe.args[table.concat ({n, 'loc'})] or pframe.args[table.concat ({n, 'at'})] or '';
		args.ignore = ('yes' == pframe.args[table.concat ({n, 'ignore-false-positive'})]) or ('yes' == pframe.args[table.concat ({n, 'ignore-err'})]);

		table.insert (out, core (args));										-- save the rendering of this source
		
		for k, v in ipairs ({'P1', 'P2', 'P3', 'P4', 'P5'}) do					-- create the FOOTNOTE id
			if '' ~= args[v] then
				table.insert (footnote, args[v]);
			end
		end
		for k, v in ipairs ({'page', 'pages', 'location'}) do					-- these done separately so that we can strip uri-reserved characters from extlinked page numbers 
			if '' ~= args[v] then
				table.insert (footnote, strip_url (args[v]))
			end
		end
		
		last_index = n;															-- flags used to select terminal postscript from nps or from end_ps
		if '' ~= args.postscript then							
			last_ps = n;
		end
		
		n = n+1;																-- bump for the next one
	end
	
	local name = table.concat (footnote):gsub ('%s+', ' ');						-- put the footnote together and strip redundant space
	
	args.end_ps = pframe.args.postscript or pframe.args.ps or '.';				-- this is the postscript for the whole not for the individual sources
	if 'none' == args.end_ps then												-- not an original sfnm parameter value; added for compatibility with other footnote templates
		args.end_ps = '';
	end

	local result = table.concat ({table.concat (out, '; '), (last_index == last_ps) and '' or  args.end_ps});
	return frame:extensionTag ({name='ref', args={name=name}, content=result});
end


--[[--------------------------< S F N R E F >------------------------------------------------------------------

implements {{sfnref}}

]]

local function sfnref (frame)
	local args = getArgs (frame);
	local out = {};
	
	for i=1, 5 do																-- get the first five args if there are five args
		if args[i] then
			out[i] = args[i];
		else
			break;																-- less than 5 args break out
		end
	end
	
	if 5 == #out then															-- when we have seen five args there may bemore
		local i = 6;															-- initialize the indexer to the sixth positional parameter
		while args[i] do														-- in case there are too many authors loop through the authors looking for a year
			if is_year (args[i], args) then										-- if a year
				out[5] = args[i];												-- overwrite whatever was in args[5] with year
				break;															-- and abandon the search
			end
			i = i + 1;															-- bump the indexer
		end
	end
	
	return mw.uri.anchorEncode ('CITEREF' .. table.concat (out));
end


--[[--------------------------< E X P O R T E D   F U N C T I O N S >------------------------------------------
]]

return {
	harvard_citation = harvard_citation,
	sfn = sfn,
	sfnm = sfnm,
	sfnref = sfnref,
	};
三点水的字大多与什么有关 胃下垂是什么症状 忠武路演员是什么意思 小孩脚后跟疼是什么原因 葵水是什么
实名认证是什么意思 粽子是什么意思 有过之而不及什么意思 味粉是什么调料 白细胞计数偏低是什么原因
为什么会得耳石症 代沟是什么意思 尿比重高是什么意思 苹果枸杞红枣煮水喝有什么功效 百折不挠指什么生肖
什么是动态口令 hpv是什么病毒 轭是什么意思 6月18是什么星座 未时是什么时候
辅食是什么意思520myf.com 检验葡萄糖用什么试剂hcv9jop4ns5r.cn 玉兰油适合什么年龄hcv7jop4ns5r.cn 什么叫体制内hcv8jop3ns9r.cn 什么可以变白皮肤hcv8jop7ns8r.cn
隐血弱阳性是什么意思xinjiangjialails.com 什么不什么身hcv9jop4ns2r.cn 小便浑浊是什么原因hcv8jop5ns7r.cn 医学上ca是什么意思hcv8jop7ns8r.cn 什么方法避孕最安全有效hcv8jop9ns0r.cn
89属什么hcv9jop0ns3r.cn 枸杞与菊花一起泡水喝有什么功效hcv9jop4ns5r.cn 中元节开什么生肖wzqsfys.com 不解什么hcv7jop7ns1r.cn 低压偏低是什么原因hcv8jop0ns0r.cn
一个口一个有念什么hcv7jop5ns6r.cn 公分是什么单位helloaicloud.com 做梦掉粪坑什么征兆helloaicloud.com 尿变红色是什么原因hcv8jop4ns5r.cn 降压药什么时间吃最好96micro.com
百度