社区中心
注册
无编辑摘要
无编辑摘要
第54行: 第54行:
 
then
 
then
 
table.insert( code, group( 'Common', frame ) )
 
table.insert( code, group( 'Common', frame ) )
  +
-- ns:0
  +
if mw.title.getCurrentTitle():inNamespace( '' )
  +
then
  +
table.insert( code, group( 'Article', frame ) )
  +
-- ns:2
  +
elseif mw.title.getCurrentTitle():inNamespace( 'User' )
  +
then
  +
table.insert( code, group( 'User', frame ) )
  +
-- ns:4
  +
elseif mw.title.getCurrentTitle():inNamespace( 'Project' )
  +
then
  +
table.insert( code, group( 'Project', frame ) )
  +
-- ns:12
  +
elseif mw.title.getCurrentTitle():inNamespace( 'Help' )
  +
then
  +
table.insert( code, group( 'Help', frame ) )
  +
-- ns:500
  +
elseif mw.title.getCurrentTitle():inNamespace( 'User blog' )
  +
then
  +
table.insert( code, group( 'Blog', frame ) )
  +
-- ns:1202
  +
elseif mw.title.getCurrentTitle():inNamespace( 'Message wall greeting' )
  +
then
  +
table.insert( code, group( 'Greeting', frame ) )
  +
end
 
end
 
end
 
for i = 1, 30 do
 
for i = 1, 30 do

2020年1月15日 (三) 14:36的版本

Documentation icon 模块文档  [创建] [刷新]
-- <nowiki>

local z = {}
local WikitextLC = require( 'Module:WikitextLC' )

function Tcode( args )
	if args.T == nil or args.T == '' then
		return ''
	end
	local div = mw.html.create( 'div' )
		:attr( 'class', 'noteTA-title' )
		:attr( 'data-noteta-code', args.T )
		:wikitext( WikitextLC.title( args.T ) )
	if args.dt ~= nil and args.dt ~= '' then
		div:attr( 'data-noteta-desc', args.dt )
	end
	return tostring( div )
end

function group( name, frame )
	if name == nil or name == '' then
		return ''
	end
	local moduleTitle = mw.title.makeTitle( 'Module', 'CGroup/' .. name )
	if moduleTitle and moduleTitle.exists then
		local data = require( 'Module:CGroup/' .. name )
		local pieces = {}
		if data.content then
			for i, v in ipairs( data.content ) do
				if v.type == 'item' and v.rule then
					table.insert( pieces, '-{H|' .. v.rule .. '}-' )
				end
			end
			return tostring( mw.html.create( 'div' )
				:attr( 'data-noteta-group-source', 'module' )
				:attr( 'data-noteta-group', data.name or name )
				:wikitext( table.concat( pieces ) ) )
		end
	end
	local templateTitle = mw.title.makeTitle( 'Template', 'CGroup/' .. name )
	if templateTitle and templateTitle.exists then
		return frame:expandTemplate{ title = templateTitle }
	end
	return tostring( mw.html.create( 'div' )
			-- :attr( 'id', 'noteTA-group-' .. mw.uri.anchorEncode( name ) )
			:attr( 'data-noteta-group-source', 'none' )
			:attr( 'data-noteta-group', name ) )
end

function Gcode( args, frame )
	local code = {}
	-- Auto Add CGroups (Common + NS)
	if args['aac']
	then
		table.insert( code, group( 'Common', frame ) )
		-- ns:0
		if mw.title.getCurrentTitle():inNamespace( '' )
		then
			table.insert( code, group( 'Article', frame ) )
		-- ns:2
		elseif mw.title.getCurrentTitle():inNamespace( 'User' )
		then
			table.insert( code, group( 'User', frame ) )
		-- ns:4
		elseif mw.title.getCurrentTitle():inNamespace( 'Project' )
		then
			table.insert( code, group( 'Project', frame ) )
		-- ns:12
		elseif mw.title.getCurrentTitle():inNamespace( 'Help' )
		then
			table.insert( code, group( 'Help', frame ) )
		-- ns:500
		elseif mw.title.getCurrentTitle():inNamespace( 'User blog' )
		then
			table.insert( code, group( 'Blog', frame ) )
		-- ns:1202
		elseif mw.title.getCurrentTitle():inNamespace( 'Message wall greeting' )
		then
			table.insert( code, group( 'Greeting', frame ) )
		end
	end
	for i = 1, 30 do
		table.insert( code, group( args['G' .. i], frame ) )
	end
	code = table.concat( code )
	if code ~= '' then
		code = tostring( mw.html.create( 'div' )
				:attr( 'class', 'noteTA-group' )
				:wikitext( code ) )
		if args.G31 ~= nil then
			code = code .. '[[Category:NoteTA模板參數使用數量超過限制的頁面|G]]'
		end
	end
	return code
end

function local_( i, code, desc )
	if code == nil or code == '' then
		return ''
	end
	local div = mw.html.create( 'div' )
		-- :attr( 'id', 'noteTA-local-' .. i )
		:attr( 'data-noteta-code', code )
		:wikitext( WikitextLC.hidden( code ) )
	if desc ~= nil and desc ~= '' then
		div:attr( 'data-noteta-desc', desc )
	end
	return tostring( div )
end

function Lcode( args )
	local code = {}
	for i = 1, 30 do
		table.insert( code, local_( i, args[i], args['d' .. i] ) )
	end
	code = table.concat( code )
	if code ~= '' then
		code = tostring( mw.html.create( 'div' )
				:attr( 'class', 'noteTA-local' )
				:wikitext( code ) )
		if args[31] ~= nil then
			code = code .. '[[Category:NoteTA模板參數使用數量超過限制的頁面|L]]'
		end
	end
	return code
end

function z.main( frame )
	local args
	if frame == mw.getCurrentFrame() then
		-- Being called from {{NoteTA}}
		args = frame:getParent().args
	else
		-- Being called from another module
		args = frame
		frame = mw.getCurrentFrame()
	end
	local Tc = Tcode( args )
	local Gc = Gcode( args, frame )
	local Lc = Lcode( args )
	local code = Tc .. Gc .. Lc
	if code ~= '' then
		local hash = code:len()
		code = tostring( mw.html.create( 'div' )
			:attr( 'id', 'mw-indicator-noteTA-' .. hash )
			:attr( 'class', 'mw-indicator' )
			:attr( 'style', 'position: absolute; right:0; top:0;' )
			:wikitext( '[[File:Zh conversion icon m.svg|35px|title=本頁使用了標題或全文手工轉換|alt=本頁使用了標題或全文手工轉換|link=]]' ) )
		.. tostring( mw.html.create( 'div' )
				:attr( 'id', 'noteTA-' .. hash )
				:attr( 'class', 'noteTA' )
				:wikitext( code ) )
		if code ~= '' then
			code = code .. '[[Category:使用NoteTA的頁面]]'
		end
		if mw.title.getCurrentTitle():inNamespace( 'Template' ) then
			code = code .. '[[Category:使用NoteTA的模板]]'
		end
	end
	return code
end

return z

-- </nowiki>

-- <noinclude>[[Category:模組]]</noinclude>