跳转到内容

模組:Special wikitext/Template

本页使用了标题或全文手工转换
被永久保护的模块
维基百科,自由的百科全书

这是本页的一个历史版本,由A2569875留言 | 贡献2021年5月14日 (五) 04:57编辑。这可能和当前版本存在着巨大的差异。

local p={}
--{{#invoke:Special wikitext/Template|contentModel}}
function p.contentModel(frame)
	local page_name = frame.args[1] or frame.args['1'] or ''
	local page_data = (mw.text.trim(page_name)==''and mw.title.getCurrentTitle() or mw.title.new(page_name))
	return (page_data or {}).contentModel or 'wikitext'
end
--{{#invoke:Special wikitext/Template|luaContentFromPage}}
function p.luaContentFromPage(frame)
	local page_name = frame.args[1] or frame.args['1'] or ''
	local page_data = (mw.text.trim(page_name)==''and mw.title.getCurrentTitle() or mw.title.new(page_name))
	local contentModel = mw.ustring.lower((page_data or {}).contentModel or 'wikitext')
	if contentModel == 'scribunto' or contentModel == 'lua' then
		pcall(require, page_data.prefixedText) -- if it fails, we don't care
		local moduleWikitext =  package.loaded["Module:Module wikitext"]
		if moduleWikitext then
			return moduleWikitext.main()
		end
	end
	return ''
end
--{{#invoke:Special wikitext/Template|checkPage}}
function p.checkPage(frame)
	local chk_name = frame.args[1] or frame.args['1'] or ''
	local cur_name = frame.args[2] or frame.args['2'] or ''
	if mw.text.trim(chk_name or '')==''then return '' end
	return p._checkPage(chk_name, cur_name) and '1' or ''
end
function p._checkPage(page, srcpage)
	local chk_page, cur_page = mw.title.new(page), (mw.text.trim(srcpage or '')=='' and mw.title.getCurrentTitle() or mw.title.new(srcpage))
	local chk_name, cur_name = '##:'..chk_page.fullText, '##:'..cur_page.fullText
	local chk_reg = mw.ustring.gsub(chk_name,'([%%\\])','%1%1')
	local chk_regs, cur_names = chk_reg..(mw.ustring.sub(chk_reg,-1,-1)=='/'and''or'/'), cur_name..(mw.ustring.sub(cur_name,-1,-1)=='/'and''or'/')
	local findpos = mw.ustring.find(cur_name, chk_reg)
	if (tonumber(findpos) or -1) > 0 then findpos = mw.ustring.find(cur_names, chk_regs)end
	return (tonumber(findpos) or -1) > 0
end

function p.int(frame)
	local int_name = frame.args[1] or frame.args['1'] or '' 
	local cur_frame = mw.getCurrentFrame()
	local body = mw.text.decode(cur_frame:preprocess("{{msgnw:int:"..int_name.."}}"))
	body = mw.ustring.gsub(body,'#%s*invoke%s*:%s*Special%s+wikitext%|','void|')
	return body
end

return p