Template:Category handler/doc: Difference between revisions

no edit summary
>Rusty.perrin
(Add shortcut)
 
>64.114 etc
No edit summary
Line 1: Line 1:
{{tsh|Cat handler}}
{{documentation subpage}}
{{#ifeq: {{FULLPAGENAME}} | Template:Category handler | {{used in system}}
{{cascade-protected template}} }}
{{lua|Module:Category handler|Module:Namespace_detect/data}}
<!-- PLEASE ADD CATEGORIES AT THE BOTTOM OF THIS PAGE -->
 
This is the {{tl|category handler}} meta-template.
This is the {{tl|category handler}} meta-template.


It helps other templates to automate both categorization and category suppression.  
It helps other templates to automate both categorization and [[Wikipedia:Category suppression|category suppression]].  


Already when used with its default settings this template prevents auto-categorization in some namespaces and on some pages where we usually don't want categorization. Thus even the most basic usage like "<code><nowiki>{{category handler|[[Category:Somecat]]}}</nowiki></code>" sees to that templates don't auto-categorize in the wrong places.
Already when used with its default settings this template prevents auto-categorization in some namespaces and on some pages where we usually don't want categorization. Thus even the most basic usage like "<code><nowiki>{{category handler|[[Category:Somecat]]}}</nowiki></code>" sees to it that templates don't auto-categorize in the wrong places.


This template makes it easy to choose in what namespaces a template should and should not categorize. And it makes it easy to use different categories in different namespaces. And this template uses a central blacklist where we can add pages and page types where templates should not auto-categorize.
This template makes it easy to choose in what namespaces a template should and should not categorize. And it makes it easy to use different categories in different namespaces. And this template uses a central blacklist where we can add pages and page types where templates should not auto-categorize.
Line 14: Line 19:
=== Namespaces ===
=== Namespaces ===


This template detects and groups all the different [[Help:Namespace|namespaces]] used on Powerpedia into several types. These types are used as parameter names in this template.
This template detects and groups all the different [[Wikipedia:Namespace|namespaces]] used on Wikipedia into several types. These types are used as parameter names in this template.


:'''main''' = Main/article space, as in normal Powerpedia articles.
:'''main''' = Main/article space, as in normal Wikipedia articles.
:'''talk''' = Any talk space, such as page names that start with "Talk:", "User talk:", "File talk:" and so on.
:'''talk''' = Any talk space, such as page names that start with "Talk:", "User talk:", "File talk:" and so on.
:'''user, powerpedia, file, mediawiki, template, help, category, portal''' and '''book''' = The other namespaces except the talk pages.
:'''user, wikipedia, file, mediawiki, template, help, category''' and '''portal''' = The other namespaces except the talk pages.
:'''other''' = Any namespaces that were not specified as a parameter to the template. See examples below.
:'''other''' = Any namespaces that were not specified as a parameter to the template. See examples below.


Line 25: Line 30:
This template takes two or more parameters. Here's an example with the full template code for an article message box:
This template takes two or more parameters. Here's an example with the full template code for an article message box:


<pre>
<syntaxhighlight lang="wikitext">
{{ambox
{{Ambox
| text = This is a box used in articles.
| text = This is a box used in articles.
}}{{category handler
}}{{category handler
Line 32: Line 37:
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
}}<noinclude>
}}<noinclude>
 
{{Documentation}}
{{documentation}}
<!--Add categories to the /doc subpage-->
<!--Add categories and interwikis to the /doc subpage-->
</noinclude>
</noinclude>
</pre>
</syntaxhighlight>


The above example uses the default settings for {{tlf|category handler}}. That means the box will categorize on pages in the following namespaces:  
The above example uses the default settings for {{tlf|category handler}}. That means the box will categorize on pages in the following namespaces:  
Line 53: Line 57:
This template takes one or more parameters named after the different page types as listed in section [[#Namespaces|namespaces]] above. By using those parameters you can specify exactly in which namespaces your template should categorize. Like this:
This template takes one or more parameters named after the different page types as listed in section [[#Namespaces|namespaces]] above. By using those parameters you can specify exactly in which namespaces your template should categorize. Like this:


<pre>
<syntaxhighlight lang="wikitext">
{{mbox
{{mbox
| text = This is a box for articles and talk pages.
| text = This is a box for articles and talk pages.
Line 61: Line 65:
| nocat = {{{nocat|}}}  <!--So "nocat=true" works-->
| nocat = {{{nocat|}}}  <!--So "nocat=true" works-->
}}
}}
</pre>
</syntaxhighlight>


The above box will only categorize in main and talk space. But it will not categorize on /archive pages since they are blacklisted. (See section [[#Blacklist|blacklist]] below.) And if you need to demonstrate (discuss) that box on a talkpage, then you can feed "<code>nocat=true</code>" to prevent that template from categorizing. (See section [[#Nocat|nocat]] below.) Like this:
The above box will only categorize in main and talk space. But it will not categorize on /archive pages since they are blacklisted. (See section [[#Blacklist|blacklist]] below.) And if you need to demonstrate (discuss) that box on a talkpage, then you can feed "<code>nocat=true</code>" to prevent that template from categorizing. (See section [[#The_%22nocat%22_parameter|The "nocat" parameter]] below.) Like this:


<pre>
<syntaxhighlight lang="wikitext">
== My new template ==
== My new template ==
Hey guys, have you seen my new template?
Hey guys, have you seen my new template?
Line 71: Line 75:
Nice, isn't it?
Nice, isn't it?
--~~~~
--~~~~
</pre>
</syntaxhighlight>


Sometimes we want to use the same category in several namespaces, then do like this:
Sometimes we want to use the same category in several namespaces, then do like this:


<pre>
<syntaxhighlight lang="wikitext">
{{mbox
{{mbox
| text = This is a box used in several namespaces.
| text = This is a box used in several namespaces.
}}{{category handler
}}{{category handler
| main = [[Category:Somecat1]]
| main = [[Category:Somecat1]]
| 1 = [[Category:Somecat2]]  <!--For help and user space-->
| 1     = [[Category:Somecat2]]  <!--For help and user space-->
| help = 1
| help = 1
| user = 1
| user = 1
| talk =    <!--No categories on talk pages-->
| talk =    <!--No categories on talk pages-->
| other = [[Category:Somecat3]]  <!--For all other namespaces-->
| other = [[Category:Somecat3]]  <!--For all other namespaces-->
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
}}
}}
</pre>
</syntaxhighlight>


In the above example we use a numbered parameter to feed one of the categories, and then we tell this template to use that numbered parameter for both the help and user space.
In the above example we use a numbered parameter to feed one of the categories, and then we tell this template to use that numbered parameter for both the help and user space.
Line 99: Line 103:
This template also has a parameter called '''all'''. It works like this:
This template also has a parameter called '''all'''. It works like this:


<pre>
<syntaxhighlight lang="wikitext" highlight="4">
{{mbox
{{mbox
| text = This is a box used in all namespaces.
| text = This is a box used in all namespaces.
Line 106: Line 110:
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
}}
}}
</pre>
</syntaxhighlight>


The above example will categorize in all namespaces, but not on blacklisted pages. If you want to demonstrate that box on a page, then use "<code>nocat=true</code>" to prevent the template from categorizing.  
The above example will categorize in all namespaces, but not on blacklisted pages. If you want to demonstrate that box on a page, then use "<code>nocat=true</code>" to prevent the template from categorizing.  
Line 114: Line 118:
The all parameter can also be combined with the rest of the parameters. Like this:
The all parameter can also be combined with the rest of the parameters. Like this:


<pre>
<syntaxhighlight lang="wikitext" highlight="4">
{{mbox
{{mbox
| text = This is a box used in all namespaces.
| text = This is a box used in all namespaces.
}}{{category handler
}}{{category handler
| all = [[Category:Somecat1]]  <!--Categorize in all namespaces-->
| all   = [[Category:Somecat1]]  <!--Categorize in all namespaces-->
| main = [[Category:Somecat2]]  <!--And add this in main space-->
| main = [[Category:Somecat2]]  <!--And add this in main space-->
| other = [[Category:Somecat3]]  <!--And add this in all other namespaces-->
| other = [[Category:Somecat3]]  <!--And add this in all other namespaces-->
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
}}
}}
</pre>
</syntaxhighlight>


If the above box is placed on an article, then it will add the categories "Somecat1" and "Somecat2". But on all other types of pages it will instead add "Somecat1" and "Somecat3". As the example shows, the all parameter works independently of the rest of the parameters.
If the above box is placed on an article, then it will add the categories "Somecat1" and "Somecat2". But on all other types of pages it will instead add "Somecat1" and "Somecat3". As the example shows, the all parameter works independently of the rest of the parameters.
Line 131: Line 135:
This template understands the '''subpage''' parameter. Like this:
This template understands the '''subpage''' parameter. Like this:


<pre>
<syntaxhighlight lang="wikitext" highlight="2">
{{category handler
{{category handler
| subpage = no    <!--Don't categorize on subpages-->
| subpage = no    <!--Don't categorize on subpages-->
Line 137: Line 141:
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
}}
}}
</pre>
</syntaxhighlight>


If "<code>subpage=no</code>" then this template will ''not'' categorize on subpages. For the rare occasion you ''only'' want to categorize on subpages, then use "<code>subpage=only</code>". If '''subpage''' is empty or undefined then this template categorizes both on basepages and on subpages.
If "<code>subpage=no</code>" then this template will ''not'' categorize on subpages. For the rare occasion you ''only'' want to categorize on subpages, then use "<code>subpage=only</code>". If '''subpage''' is empty or undefined then this template categorizes both on basepages and on subpages.
Line 143: Line 147:
=== Blacklist ===
=== Blacklist ===


This template has a blacklist of the pages and page types where templates should not auto-categorize. Thus templates that use this meta-template will for instance not categorize on /archive pages and on the subpages of [[Wikipedia:Template messages]].
This template has a blacklist of the pages and page types where templates should not auto-categorize. Thus templates that use this meta-template will for instance not categorize on /archive pages and on the subpages of [[Wikipedia:Template index]].


If you want a template to categorize on a blacklisted page, then feed "<code><nowiki>nocat = false</nowiki></code>" to the template when you place it on the page, thus skipping the blacklist check. Note that this template only categorizes if it has data for the namespace. For instance, if the basic syntax is used (see [[#Basic usage|basic usage]] above), then even if you set "<code>nocat = false</code>" the template will not categorize on a talk page, since it has no data for talk pages. But it has data for help space, so on a blacklisted help page it will categorize.
If you want a template to categorize on a blacklisted page, then feed "<code><nowiki>nocat = false</nowiki></code>" to the template when you place it on the page, thus skipping the blacklist check. Note that this template only categorizes if it has data for the namespace. For instance, if the basic syntax is used (see [[#Basic usage|basic usage]] above), then even if you set "<code>nocat = false</code>" the template will not categorize on a talk page, since it has no data for talk pages. But it has data for help space, so on a blacklisted help page it will categorize.
Line 167: Line 171:
* If "<code>categories = yes</code>" this template categorizes even when on blacklisted pages.
* If "<code>categories = yes</code>" this template categorizes even when on blacklisted pages.


When adding this template to a template that already uses the "<code>categories = no</code>" logic, then you can do like this to not break any existing usage:
When adding this template to a template that already uses the "<code>categories = no</code>" logic, then you can do the following to not break any existing usage:


<pre>
<syntaxhighlight lang="wikitext" highlight="4">
{{category handler
{{category handler
| [[Category:Somecat]]
| [[Category:Somecat]]
Line 175: Line 179:
| categories = {{{categories|}}}  <!--So "categories=no" works-->
| categories = {{{categories|}}}  <!--So "categories=no" works-->
}}
}}
</pre>
</syntaxhighlight>


=== The "category2" parameter ===
=== The "category2" parameter ===
Line 187: Line 191:
When adding this template to a template that already uses the "<code>category =</code>" logic, then you can do like this to not break any existing usage:
When adding this template to a template that already uses the "<code>category =</code>" logic, then you can do like this to not break any existing usage:


<pre>
<syntaxhighlight lang="wikitext" highlight="4">
{{category handler
{{category handler
| [[Category:Somecat]]
| [[Category:Somecat]]
Line 193: Line 197:
| category2 = {{{category|¬}}}  <!--So "category =" works-->
| category2 = {{{category|¬}}}  <!--So "category =" works-->
}}
}}
</pre>
</syntaxhighlight>


Note that the "<code>¬</code>" is necessary, it helps this template to detect if the '''category''' parameter is defined but empty, or undefined.
Note that the "<code>¬</code>" is necessary, it helps this template to detect if the '''category''' parameter is defined but empty, or undefined.
Line 201: Line 205:
Besides from categories, you can feed anything else to this template, for instance some text. Like this:
Besides from categories, you can feed anything else to this template, for instance some text. Like this:


<pre>
<syntaxhighlight lang="wikitext">
{{tmbox
{{tmbox
| text = This is a talk page message box.
| text = This is a talk page message box.
Line 209: Line 213:
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
| nocat = {{{nocat|}}}  <!--So "nocat=true/false" works-->
}}
}}
</pre>
</syntaxhighlight>


When the template above is shown on anything else than a talk page, it will look like this (note the text below the box):
When the template above is shown on anything else than a talk page, it will look like this (note the text below the box):
Line 228: Line 232:
For testing and demonstration purposes this template can take a parameter named '''page'''. Like this:
For testing and demonstration purposes this template can take a parameter named '''page'''. Like this:


<pre>
<syntaxhighlight lang="wikitext" highlight="5">
{{category handler
{{category handler
| main = Category:Some cat
| main = Category:Some cat
Line 235: Line 239:
| page = User talk:Example
| page = User talk:Example
}}
}}
</pre>
</syntaxhighlight>


In the above code we on purpose left out the brackets around the category names so we see the output on the page. No matter on what kind of page the code above is used it will return this:
In the above code we on purpose left out the brackets around the category names so we see the output on the page. No matter on what kind of page the code above is used it will return this:
Line 252: Line 256:
You can make it so your template also understands the '''page''' parameter. That means you can test how your template will categorize on different pages, without having to actually edit those pages. Then do like this:
You can make it so your template also understands the '''page''' parameter. That means you can test how your template will categorize on different pages, without having to actually edit those pages. Then do like this:


<pre>
<syntaxhighlight lang="wikitext" highlight="5">
{{category handler
{{category handler
| main = Category:Some cat
| main = Category:Some cat
Line 259: Line 263:
| page = {{{page|}}}  <!--For testing-->
| page = {{{page|}}}  <!--For testing-->
}}
}}
</pre>
</syntaxhighlight>


=== Parameters ===
=== Parameters ===
Line 265: Line 269:
List of all parameters:
List of all parameters:


<pre>
<syntaxhighlight lang="wikitext">
{{category handler
{{category handler
| [[Category:Somecat]]
| [[Category:Somecat]]
Line 283: Line 287:
| page  = {{{page|}}} / User:Example
| page  = {{{page|}}} / User:Example
}}
}}
</pre>
</syntaxhighlight>


Note that empty values to the "main" ... "other" parameters have special meaning (see examples above). The "all" parameter doesn't understand numbered parameters, since there should never be a need for that.
Note that empty values to the "main" ... "other" parameters have special meaning (see examples above). The "all" parameter doesn't understand numbered parameters, since there should never be a need for that.


=== Technical details ===
=== Technical details ===
The centralised category suppression blacklist is in [[Module:Category handler/blacklist]]. To see or update the blacklist, go there.
For more technical details see the [[Template talk:Category handler|talk page]].


The centralised category suppression blacklist is in the sub-template {{tl|category handler/blacklist}}. To see or update the blacklist, go there.
=== See also ===
* [[Wikipedia:Category suppression]] – The how-to guide.
* [[Wikipedia:WikiProject Category Suppression]] – The WikiProject.
* [[Wikipedia:Namespace]] – Lists all the namespaces.


For its internal parameter processing, this template uses the sub-template {{tl|category handler/numbered}}.
<includeonly>{{Sandbox other||
[[Category:Wikipedia metatemplates]]
}}</includeonly>
Anonymous user