Nhảy chuyển tới nội dung

Mô tổ:Category see also

本页使用了标题或全文手工转换
被永久保护的模块
Duy cơ bách khoa, tự do bách khoa toàn thư

Tham kiến {{Category see also}}.

-- This module implements {{Category see also}}

localmHatnote=require('Module:Hatnote')

localp={}

localfunctionmakeWikitextError(msg)
returnstring.format(
'<strong class= "error" > sai lầm: %s ( [[Template:Category see also]] ) </strong>',
msg
)
end

-- Gets the length of the sequence seq. Usually this should be done with the #
-- operator, but we need to work with tables that get their values through an
-- __index metamethod.
localfunctiongetSequenceLength(seq)
locallength=0
foriinipairs(seq)do
length=i
end
returnlength
end

-- Given a table of options, returns a function that formats categories for
-- those options.
--
-- Options:
-- project - a project code such as "fr" (for the French Wikipedia)
-- showPrefix - a boolean value for whether to show the "Category:" prefix
-- (and the project prefix if specified)
--
-- This is implemented as a function generator rather than a simple function
-- so that we can just process the options once, instead of every time we
-- generate a category.
localfunctionnewCategoryLinker(options)
localformatString
ifoptions.projectthen
ifoptions.showPrefixthen
formatString=' “[[:'..options.project..':Category:%s]]” '
else
formatString=' “[[:'..options.project..':Category:%s]]” '
end
else
ifoptions.showPrefixthen
formatString=' “[[:Category:%s]]” '
else
formatString=' “[[:Category:%s]]” '
end
end
returnfunction(category)
localtitle=mw.title.new(category)
localpageName,display
ifnottitlethen
-- category is not a valid title, usually because of invalid
-- characters like < or [. Raise an error and suppress the stack
-- level information so that we can catch it and format the error
-- message as wikitext.
error(string.format(
"“%s” không phải hữu hiệu phân loại danh ",
category
),0)
elseiftitle.namespace==14then-- Category namespace
pageName=title.text
display=title.text
else
pageName=title.prefixedText
display=category
end
-- We can get away with using two arguments even when
-- options.showDisplay is false, as string.format ignores extra
-- arguments as long as there is an argument for each flag in the
-- format string.
returnformatString:format(pageName,display)
end
end

functionp._main(args)
localnLinks=getSequenceLength(args)

ifnLinks<1then
returnmakeWikitextError(' ít nhất yêu cầu một cái tham số ')
end

localmakeCategoryLink=newCategoryLinker{
project=args.project,
showPrefix=nLinks==1,
}

locallinks={}
fori,catinipairs(args)do
localsuccess,categoryLink=pcall(makeCategoryLink,cat)
ifsuccessthen
links[i]=categoryLink
else
-- If there was an error, then categoryLink is the error message.
returnmakeWikitextError(categoryLink)
end
end

localformatString
ifnLinks==1then
formatString='%s%s. '
else
formatString='%s%s. '
end

-- Don't output a comma before the "and" if we have only two links.
-- tiếng Trung không cần
localconjunction=' cùng '

localhatnoteText=formatString:format(
args.LABELor' khác thỉnh tham kiến ',
mw.text.listToText(links,'',conjunction)
)
returnmHatnote._hatnote(hatnoteText,{selfref=true})
end

functionp.main(frame)
localargs=require('Module:Arguments').getArgs(frame,{
wrappers='Template:Category see also',
})
returnp._main(args)
end

returnp