Mô đun:Suppress categories
Giao diện
| Mô đun này được xếp loại là đã sẵn sàng để sử dụng rộng rãi. Nó đã đạt đến mức độ hoàn thiện, được coi là khá ổn định và không có lỗi, và có thể được sử dụng bất kỳ chỗ nào nếu phù hợp. Nó có thể được nêu trên các trang trợ giúp cũng như các tài liệu Wikipedia khác làm tùy chọn tìm hiểu cho người dùng mới. Để giảm tải tài nguyên máy chủ và tránh tạo đầu ra gây hại, mọi cải tiến nên được thực hiện thông qua việc kiểm thử tại chỗ thử thay vì sửa đổi "thử và sai" lặp đi lặp lại liên tục. |
| Mô đun Lua này được sử dụng ở rất nhiều trang, vì thế những thay đổi đến nó sẽ hiện ra rõ ràng. Vui lòng thử nghiệm các thay đổi ở trang con /sandbox, /testcases của mô đun, hoặc ở chỗ thử mô đun. Cân nhắc thảo luận các thay đổi tại trang thảo luận trước khi áp dụng sửa đổi. |
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
- Wikipedia:Category suppression
-- 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.local p = {}-- 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.local function processCategory( all, submatch ) local beforePipe = mw.ustring.match( submatch, '^(.-)[%s_]*|[%s_]*.-$' ) beforePipe = beforePipe or submatch if mw.ustring.match( beforePipe, '[%[%]<>{}%c\n]' ) then return all else return '' endend-- Preprocess the content if we aren't being called from #invoke,-- and pass it to gsub to remove valid category links.local function suppress( content, isPreprocessed ) if not isPreprocessed then content = mw.getCurrentFrame():preprocess( content ) end content = mw.ustring.gsub( content, '(%[%[[%s_]*[cC][aA][tT][eE][gG][oO][rR][yY][%s_]*:[%s_]*(.-)[%s_]*%]%])', processCategory ) content = mw.ustring.gsub( content, '(%[%[[%s_]*[tT][hH][ểỂ][%s_]*[lL][oO][ạẠ][iI][%s_]*:[%s_]*(.-)[%s_]*%]%])', processCategory ) return contentend-- 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.)function p.main( frame ) local content, isPreprocessed if frame == mw.getCurrentFrame() then content = frame:getParent().args[1] if frame.args[1] then content = frame.args[1] end isPreprocessed = true else content = frame isPreprocessed = false end return suppress( content, isPreprocessed )endreturn p