Mô tổ:Category see also
Ngoại quan
![文档图示](https://upload.wikimedia.org/wikipedia/commons/thumb/4/43/Test_Template_Info-Icon_-_Version_%282%29.svg/50px-Test_Template_Info-Icon_-_Version_%282%29.svg.png)
Tham kiến {{Category see also}}.
Thượng thuậtVăn đươngKhảm nhậpTựModule:Category see also/doc.(Biên tập|Lịch sử) Biên giả khả dĩ tại bổn mô khối đích sa hạp(Sang kiến|Kính tượng)Hòa trắc thí dạng lệ(Sang kiến)Hiệt diện tiến hành thật nghiệm. Bổn mô khối đích tử hiệt diện. |
-- This module implements {{Category see also}}
localmHatnote=require('Module:Hatnote')
localp={}
localfunctionmakeWikitextError(msg)
returnstring.format(
'<strong class= "error" > thác ngộ: %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” bất thị hữu hiệu đích 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(' chí thiếu nhu yếu nhất cá 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.
-- trung văn bất nhu yếu
localconjunction=' hòa '
localhatnoteText=formatString:format(
args.LABELor' lánh 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