Mô đun:Cat main

Tài liệu mô đun
-- This module implements {{cat main}}.local mHatnote = require('Mô đun:Hatnote')local yesno = require('Mô đun:Yesno')local mTableTools -- lazily initialiselocal mArguments -- lazily initialiselocal p = {}function p.catMain(frame)mTableTools = require('Mô đun:TableTools')mArguments = require('Mô đun:Arguments')local args = mArguments.getArgs(frame, {wrappers = 'Bản mẫu:Bài chính thể loại'})local pages = mTableTools.compressSparseArray(args)local options = {article = args.article,selfref = args.selfref}return p._catMain(options, unpack(pages))endfunction p._catMain(options, ...)options = options or {}-- Get the links table.local links = mHatnote.formatPages(...)if not links[1] thenlocal page = mw.title.getCurrentTitle().textlinks[1] = mHatnote._formatLink(page)endfor i, link in ipairs(links) dolinks[i] = string.format("'''%s'''", link)end-- Get the pagetype.local pagetypeif yesno(options.article) ~= false thenpagetype = 'Bài viết'elsepagetype = 'Trang'end-- Work out whether we need to be singular or plural.local stringToFormatif #links > 1 thenstringToFormat = '%s chính của [[Wikipedia:Thể loại|thể loại]] này là %s.'elsestringToFormat = '%s chính của [[Wikipedia:Thể loại|thể loại]] này là %s.'end-- Get the text.local text = string.format(stringToFormat,pagetype,mw.text.listToText(links))-- Pass it through to Module:Hatnote.local hnOptions = {}hnOptions.selfref = options.selfrefhnOptions.extraclasses = 'relarticle mainarticle'return mHatnote._hatnote(text, hnOptions)endreturn p