Mô đun:Military navigation
Giao diện
local p = { }-- Gọi các mô đun phụ thuộc (đã Việt hóa tên)local Navbox = require('Mô đun:Navbox')local Styles = require('Mô đun:WPMILHIST Infobox style')-- Hàm kiểm tra chuỗi rỗnglocal function isblank(s) return (not s) or s == ''end-- Hàm kiểm tra chuỗi có nội dunglocal function isnotblank(s) return s and s ~= ''endfunction p.main(frame) local args = { } local pargs = frame:getParent().args local fargs = frame.args local sargs = {} local tcats = '' -- Hàm sao chép tham số, ưu tiên tham số từ #invoke (fargs) nếu trùng local function copy_args(source_args) for k, v in pairs(source_args) do if v and v ~= '' then args[k] = v end end end -- Sao chép tham số từ bản mẫu mẹ và từ lệnh #invoke copy_args(pargs) copy_args(fargs) -- === PHẦN SỬA LỖI QUAN TRỌNG === -- Tự động gán 'battles' vào 'list1' nếu 'list1' chưa có. -- Điều này giúp bản mẫu hiển thị được nội dung khi dùng tham số |battles= if args['battles'] and isblank(args['list1']) then args['list1'] = args['battles'] end -- ================================ -- Xử lý kiểu dáng (style) và tiêu đề (titlestyle) local style = args['style'] or '' if style == 'wide' then -- Kiểu rộng (ngang màn hình) args['titlestyle'] = Styles['nav_box_wide_header'] args['bodystyle'] = Styles['nav_box_wide'] else -- Kiểu hẹp (cột bên phải - sidebar) args['titlestyle'] = Styles['nav_box_header'] local border = args['border'] or '' if border == 'child' or border == 'subgroup' then args['bodystyle'] = Styles['nav_box_child'] tcats = tcats .. '[[Thể loại:Trang sử dụng các nhóm phụ điều hướng quân sự không có kiểu rộng]]' else -- Lấy width:25.5em từ Style để ép khung không bị tràn args['bodystyle'] = Styles['nav_box'] end end -- Đánh dấu để không bị ghi đè bởi vòng lặp sau này (nếu có logic mở rộng) sargs['titlestyle'] = 1 sargs['bodystyle'] = 1 -- Xử lý các style cho nhóm, trên, dưới args['groupstyle'] = Styles['nav_box_label'] .. (args['groupstyle'] or '') args['abovestyle'] = Styles['nav_box_label'] .. (args['abovestyle'] or '') args['belowstyle'] = Styles['nav_box_label'] .. (args['belowstyle'] or '') -- Xử lý màu sọc xen kẽ (odd/even) args['oddstyle'] = isnotblank(args['odd_color']) and ('background:' .. args['odd_color']) or nil args['evenstyle'] = isnotblank(args['even_color']) and ('background:' .. args['even_color']) or nil -- Xử lý tên bản mẫu (để hiện thanh điều hướng Xem/Thảo luận/Sửa) args['name'] = args['name'] or args['rawname'] if isblank(args['name']) then args['navbar'] = 'plain' end -- Tự động xuống dòng cho tiêu đề dài nếu ở chế độ hẹp (sidebar) if args['title'] and style ~= 'wide' then if not mw.ustring.match(args['title'], '<span class="wrap">') then -- Regex tìm chuỗi dài liên tục để chèn thẻ wrap local m = '[^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|][^%[%]<>|]' m = m .. m .. m -- Khớp 15 ký tự trở lên -- Xử lý link dạng [[Tên bài]] args['title'] = mw.ustring.gsub(args['title'], '%[%[(' .. m .. '[^%[%]<>|]*)%]%]', '[[%1|<span class="wrap">%1</span>]]') -- Xử lý link dạng [[Tên bài|Tên hiển thị]] args['title'] = mw.ustring.gsub(args['title'], '%[%[([^%[%]<>|]*)|(' .. m .. '[^%[%]<>|]*)%]%]', '[[%1|<span class="wrap">%2</span>]]') end end -- Thêm class 'navbox-vertical' nếu là dạng cột dọc if style ~= 'wide' then args['bodyclass'] = 'navbox-vertical' .. (args['bodyclass'] and (' ' .. args['bodyclass']) or '') end -- Gọi Module:Navbox để tạo bảng return tcats .. Navbox._navbox(args)end return p