| 行 1: |
行 1: |
| | local z = {} | | local z = {} |
| − | local HtmlBuilder = require( 'Module:HtmlBuilder' )
| |
| | local WikitextLC = require( 'Module:WikitextLC' ) | | local WikitextLC = require( 'Module:WikitextLC' ) |
| | | | |
| | function Tcode( args ) | | function Tcode( args ) |
| − | if args.T == nil or args.T == '' then
| + | if args.T == nil or args.T == '' then |
| − | return ''
| + | return '' |
| − | end
| + | end |
| − | local builder = HtmlBuilder.create()
| + | local div = mw.html.create( 'div' ) |
| − | local div = builder.tag( 'div' )
| + | :attr( 'class', 'noteTA-title' ) |
| − | .attr( 'id', 'noteTA-title' )
| + | :attr( 'data-noteta-code', args.T ) |
| − | .attr( 'data-noteta-code', mw.uri.encode( args.T ) )
| + | :wikitext( WikitextLC.title( args.T ) ) |
| − | .wikitext( WikitextLC.title( args.T ) )
| + | if args.dt ~= nil and args.dt ~= '' then |
| − | if args.dt ~= nil and args.dt ~= '' then
| + | div:attr( 'data-noteta-desc', args.dt ) |
| − | div.attr( 'data-noteta-desc', mw.uri.encode( args.dt ) )
| + | end |
| − | end
| + | return tostring( div ) |
| − | return tostring( builder )
| |
| | end | | end |
| | | | |
| | function group( name, frame ) | | function group( name, frame ) |
| − | if name == nil or name == '' then
| + | if name == nil or name == '' then |
| − | return ''
| + | return '' |
| − | end
| + | end |
| − | local title = mw.title.makeTitle( 'Template', 'CGroup/' .. name )
| + | local moduleTitle = mw.title.makeTitle( 'Module', 'CGroup/' .. name ) |
| − | if title.exists then
| + | if moduleTitle and moduleTitle.exists then |
| − | return frame:expandTemplate{ title = title }
| + | local data = mw.loadData( 'Module:CGroup/' .. name ) |
| − | else
| + | local pieces = {} |
| − | return tostring( HtmlBuilder.create()
| + | if data.content then |
| − | .tag( 'div' )
| + | for i, v in ipairs( data.content ) do |
| − | .attr( 'id', 'noteTA-group-' .. mw.uri.anchorEncode( name ) )
| + | if v.type == 'item' and v.rule then |
| − | .attr( 'class', 'noteTA-missing' )
| + | table.insert( pieces, '-{H|' .. v.rule .. '}-' ) |
| − | .attr( 'data-noteta-group', name )
| + | end |
| − | .allDone() )
| + | 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 | | end |
| | | | |
| | function Gcode( args, frame ) | | function Gcode( args, frame ) |
| − | local code = {}
| + | local code = {} |
| − | for i = 1, 30 do
| + | for i = 1, 30 do |
| − | table.insert( code, group( args['G' .. i], frame ) )
| + | table.insert( code, group( args['G' .. i], frame ) ) |
| − | end
| + | end |
| − | code = table.concat( code )
| + | code = table.concat( code ) |
| − | if code ~= '' then
| + | if code ~= '' then |
| − | code = tostring( HtmlBuilder.create()
| + | code = tostring( mw.html.create( 'div' ) |
| − | .tag( 'div' )
| + | :attr( 'class', 'noteTA-group' ) |
| − | .attr( 'id', 'noteTA-group' )
| + | :wikitext( code ) ) |
| − | .wikitext( code )
| + | if args.G31 ~= nil then |
| − | .allDone() )
| + | code = code .. '[[Category:NoteTA模板参数使用数量超过限制的页面|G]]' |
| − | if args.G31 ~= nil then
| + | end |
| − | code = code .. '[[Category:NoteTA模板参数使用数量超过限制的页面|G]]'
| + | end |
| − | end
| + | return code |
| − | end
| |
| − | return code
| |
| | end | | end |
| | | | |
| | function local_( i, code, desc ) | | function local_( i, code, desc ) |
| − | if code == nil or code == '' then
| + | if code == nil or code == '' then |
| − | return ''
| + | return '' |
| − | end
| + | end |
| − | local builder = HtmlBuilder.create()
| + | local div = mw.html.create( 'div' ) |
| − | local div = builder.tag( 'div' )
| + | -- :attr( 'id', 'noteTA-local-' .. i ) |
| − | .attr( 'id', 'noteTA-local-' .. i )
| + | :attr( 'data-noteta-code', code ) |
| − | .attr( 'data-noteta-code', mw.uri.encode( code ) )
| + | :wikitext( WikitextLC.hidden( code ) ) |
| − | .wikitext( WikitextLC.hidden( code ) )
| + | if desc ~= nil and desc ~= '' then |
| − | if desc ~= nil and desc ~= '' then
| + | div:attr( 'data-noteta-desc', desc ) |
| − | div.attr( 'data-noteta-desc', mw.uri.encode( desc ) )
| + | end |
| − | end
| + | return tostring( div ) |
| − | return tostring( builder )
| |
| | end | | end |
| | | | |
| | function Lcode( args ) | | function Lcode( args ) |
| − | local code = {}
| + | local code = {} |
| − | for i = 1, 30 do
| + | for i = 1, 30 do |
| − | table.insert( code, local_( i, args[i], args['d' .. i] ) )
| + | table.insert( code, local_( i, args[i], args['d' .. i] ) ) |
| − | end
| + | end |
| − | code = table.concat( code )
| + | code = table.concat( code ) |
| − | if code ~= '' then
| + | if code ~= '' then |
| − | code = tostring( HtmlBuilder.create()
| + | code = tostring( mw.html.create( 'div' ) |
| − | .tag( 'div' )
| + | :attr( 'class', 'noteTA-local' ) |
| − | .attr( 'id', 'noteTA-local' )
| + | :wikitext( code ) ) |
| − | .wikitext( code )
| + | if args[31] ~= nil then |
| − | .allDone() )
| + | code = code .. '[[Category:NoteTA模板参数使用数量超过限制的页面|L]]' |
| − | if args[31] ~= nil then
| + | end |
| − | code = code .. '[[Category:NoteTA模板参数使用数量超过限制的页面|L]]'
| + | end |
| − | end
| + | return code |
| − | end
| |
| − | return code
| |
| | end | | end |
| | | | |
| | function z.main( frame ) | | function z.main( frame ) |
| − | local args = frame:getParent().args
| + | local args |
| − | local Tc = Tcode( args )
| + | if frame == mw.getCurrentFrame() then |
| − | local Gc = Gcode( args, frame )
| + | -- Being called from {{noteTA}} |
| − | local Lc = Lcode( args )
| + | args = frame:getParent().args |
| − | local code = Tc .. Gc .. Lc
| + | else |
| − | if code ~= '' then
| + | -- Being called from another module |
| − | code = frame:expandTemplate{
| + | args = frame |
| − | title = 'topicon',
| + | frame = mw.getCurrentFrame() |
| − | args = {
| + | end |
| − | id = 'noteTA-topicon',
| + | local Tc = Tcode( args ) |
| − | image = 'Zh conversion icon m.svg',
| + | local Gc = Gcode( args, frame ) |
| − | alt = ' 本页使用了标题或全文手工转换',
| + | local Lc = Lcode( args ) |
| − | title = '本页使用了标题或全文手工转换',
| + | local code = Tc .. Gc .. Lc |
| − | link = '',
| + | if code ~= '' then |
| − | size = '35px',
| + | local hash = require( 'Module:Crc32lua' ).crc32( mw.dumpObject( args ) ) |
| − | },
| + | code = frame:extensionTag{ |
| − | } .. tostring( HtmlBuilder.create()
| + | name = 'indicator', |
| − | .tag( 'div' )
| + | content = '[[File:Zh conversion icon m.svg|35px| 本页使用了标题或全文手工转换|link=]]', |
| − | .attr( 'id', 'noteTA' )
| + | args = { name = string.format( 'noteTA-%x', hash ) }, |
| − | .wikitext( code )
| + | } .. tostring( mw.html.create( 'div' ) |
| − | .allDone() )
| + | :attr( 'id', string.format( 'noteTA-%x', hash ) ) |
| − | if mw.title.getCurrentTitle():inNamespace( 'Template' ) then
| + | :attr( 'class', 'noteTA' ) |
| − | code = code .. '[[Category:放置于模板的noteTA]]'
| + | :wikitext( code ) ) |
| − | end
| + | if mw.title.getCurrentTitle():inNamespace( 'Template' ) then |
| − | end
| + | code = code .. '[[Category:放置于模板的noteTA]]' |
| − | return code
| + | end |
| | + | end |
| | + | return code |
| | end | | end |
| | | | |
| | return z | | return z |