Module:Suppress categories
- Afrikaans
- العربية
- অসমীয়া
- تۆرکجه
- Basa Bali
- বাংলা
- Banjar
- Беларуская (тарашкевіца)
- भोजपुरी
- Dansk
- ދިވެހިބަސް
- فارسی
- Français
- Gaeilge
- 한국어
- Ilokano
- Bahasa Indonesia
- ಕನ್ನಡ
- Lietuvių
- Madhurâ
- मैथिली
- മലയാളം
- मराठी
- Bahasa Melayu
- မြန်မာဘာသာ
- 日本語
- ਪੰਜਾਬੀ
- Português
- Română
- සිංහල
- Simple English
- Slovenščina
- Српски / srpski
- Suomi
- တႆး
- ไทย
- Türkçe
- اردو
- Tiếng Việt
- 粵語
- Jaku Iban
Appearance
From Wikipedia, the free encyclopedia
This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing.
Page template-protected This module is currently protected from editing.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
See the protection policy and protection log for more details. Please discuss any changes on the talk page; you may submit an edit request to ask an administrator to make an edit if it is uncontroversial or supported by consensus. You may also request that this page be unprotected.
Warning This Lua module is used on approximately 6,100 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 is a simple module to strip categories from wikitext. For example, if passed the code "foo[[Category:Some category]]
", it will return only "foo
".
The module properly handles categories escaped with the colon trick, categories whose names include invalid characters such as ">
", and categories that are surrounded with nowiki tags. However, it does not support complex wikitext such as nested links or magic words like __TOC__
. Even so, it should still remove the vast majority of categories from any given wikitext.
Usage
{{#invoke:Suppress categories|main|input text}}
Examples
Code | Output |
---|---|
{{#invoke:Suppress categories|main|foo}}
|
foo |
{{#invoke:Suppress categories|main|foo[[Category:Some category]]}}
|
foo |
{{#invoke:Suppress categories|main|foo[[Category:Some category]]bar[[Category:Another category]]}}
|
foobar |
{{#invoke:Suppress categories|main|foo{{{some_parameter|[[Category:Bar]]}}}}}
|
foo |
{{#invoke:Suppress categories|main|foo[[Category:Bad ca[]tegory link]]}}
|
foo[[Category:Bad ca[]tegory link]] |
{{#invoke:Suppress categories|main|foo[[:Category:Colon trick]]}}
|
fooCategory:Colon trick |
{{#invoke:Suppress categories|main|foo[[Category:Piped link|bar]]}}
|
foo |
{{#invoke:Suppress categories|main|foo[[Category:Piped link|ba[]r]]}}
|
foo |
{{#invoke:Suppress categories|main|foo[[non-category link]]}}
|
foonon-category link |
{{#invoke:Suppress categories|main|foo[[ Category : Some category with spaces ]]}}
|
foo |
See also
The above documentation is transcluded from Module:Suppress categories/doc. (edit | history)
Editors can experiment in this module's sandbox (create | mirror) and testcases (edit | run) pages.
Subpages of this module.
Editors can experiment in this module's sandbox (create | mirror) and testcases (edit | run) pages.
Subpages of this module.
-- This is a simple module to strip categories from wikitext. It does -- not support nested links or magic words like __TOC__, etc. Even so, -- it should still handle most categories. localp={} -- Detects if a category link is valid or not. If it is valid, -- the function returns the blank string. If not, the input -- is returned with no changes. localfunctionprocessCategory(all,submatch) localbeforePipe=mw.ustring.match(submatch,'^(.-)[%s_]*|[%s_]*.-$') beforePipe=beforePipeorsubmatch ifmw.ustring.match(beforePipe,'[%[%]<>{}%c\n]')then returnall else return'' end end -- Preprocess the content if we aren't being called from #invoke, -- and pass it to gsub to remove valid category links. localfunctionsuppress(content,isPreprocessed) ifnotisPreprocessedthen content=mw.getCurrentFrame():preprocess(content) end content=mw.ustring.gsub( content, '(%[%[[%s_]*[cC][aA][tT][eE][gG][oO][rR][yY][%s_]*:[%s_]*(.-)[%s_]*%]%])', processCategory ) returncontent end -- Get the content to suppress categories from, and find -- whether the content has already been preprocessed. (If the -- module is called from #invoke, it has been preprocessed already.) functionp.main(frame) localcontent,isPreprocessed ifframe==mw.getCurrentFrame()then content=frame:getParent().args[1] ifframe.args[1]then content=frame.args[1] end isPreprocessed=true else content=frame isPreprocessed=false end returnsuppress(content,isPreprocessed) end returnp