Module:Category see also
- Аԥсшәа
- العربية
- অসমীয়া
- Azərbaycanca
- تۆرکجه
- Basa Bali
- বাংলা
- Bosanski
- Català
- Chavacano de Zamboanga
- ChiTumbuka
- Dagbanli
- डोटेली
- فارسی
- Gaelg
- ગુજરાતી
- 한국어
- हिन्दी
- ಕನ್ನಡ
- کٲشُر
- Ikinyarwanda
- Madhurâ
- മലയാളം
- Malti
- मराठी
- مازِرونی
- Bahasa Melayu
- 日本語
- ਪੰਜਾਬੀ
- پښتو
- ភាសាខ្មែរ
- Sakizaya
- ᱥᱟᱱᱛᱟᱲᱤ
- Scots
- Sesotho
- Shqip
- සිංහල
- Simple English
- Slovenščina
- Soomaaliga
- کوردی
- Tagalog
- తెలుగు
- ไทย
- Türkçe
- Türkmençe
- Tiếng Việt
- 粵語
- 中文
- Kadazandusun
Appearance
From Wikipedia, the free encyclopedia
Warning This Lua module is used on approximately 51,000 pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them.
This module implements {{Category see also }}. It produces see also links to categories which look something like this:
See also: Category:Individual giant pandas
For full documentation, see Template:Category see also.
The above documentation is transcluded from Module:Category see also/doc. (edit | history)
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages.
Subpages of this module.
-- This module implements {{Category see also}} localmHatnote=require('Module:Hatnote') localp={} localfunctionmakeWikitextError(msg) returnstring.format( '<strong class="error">Error: %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|%s]]' end else ifoptions.showPrefixthen formatString='[[:Category:%s]]' else formatString='[[:Category:%s|%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' is not a valid category name", 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('at least one parameter required') 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 the categories %s' end -- Don't output a comma before the "and" if we have only two links. localconjunction ifnLinks==2then conjunction=' and ' else conjunction=', and ' end localhatnoteText=formatString:format( args.LABELorargs.labelor'See also', 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