"Module:Category handler/doc" ke revisions ke biich ke antar

m
Bot: Replace deprecated <source> tag and "enclose" parameter [https://lists.wikimedia.org/pipermail/wikitech-ambassadors/2020-April/002284.html]
(Panna jisme "{{module rating|beta}} {{high-risk| 5,600,000+ }} This module implements the {{tl|category handler}} template. The category handler template helps other..." hae ke banae dewa gais hae.)
 
m (Bot: Replace deprecated <source> tag and "enclose" parameter [https://lists.wikimedia.org/pipermail/wikitech-ambassadors/2020-April/002284.html])
 
 
For cases where a module only needs to categorise in one of the namespaces main (articles), file (images) or category, then using this module is overkill. Instead, you can simply get a title object using [[rev:https://www.mediawiki.org/wiki/Extension:Scribunto/Lua reference manual#mw.title.getCurrentTitle#mw.title.getCurrentTitle|mw.title.getCurrentTitle]] and check the <code>nsText</code> field. For example:
<sourcesyntaxhighlight lang="lua">
local title = mw.title.getCurrentTitle()
if title.nsText == 'File' then
-- do something
end
</syntaxhighlight>
</source>
However, if your module needs to categorize in any other namespace, then we recommend you use this module, since it provides proper category suppression and makes it easy to select how to categorize in the different namespaces.
 
This module takes two or more parameters. Here's an example using a hello world program:
 
<sourcesyntaxhighlight lang="lua">
p = {}
local categoryHandler = require( 'Module:Category handler' ).main
return p
</syntaxhighlight>
</source>
 
The above example uses the default settings for the category handler module. That means the example module will categorize on pages in the following namespaces:
This module 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:
 
<sourcesyntaxhighlight lang="lua">
p = {}
local categoryHandler = require( 'Module:Category handler' ).main
return p
</syntaxhighlight>
</source>
 
The above module 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) the module on a talkpage, then you can feed "<code>nocat='true'</code>" to prevent that template from categorizing. (See section [[#Nocat|nocat]] below.) Like this:
Sometimes we want to use the same category in several namespaces, then do like this:
 
<sourcesyntaxhighlight lang="lua">
p = {}
local categoryHandler = require( 'Module:Category handler' ).main
return p
</syntaxhighlight>
</source>
 
In the above example we use a numbered parameter to feed one of the categories, and then we tell this module to use that numbered parameter for both the help and user space.
The category handler module also has a parameter called '''all'''. It works like this:
 
<sourcesyntaxhighlight lang="lua">
p = {}
local categoryHandler = require( 'Module:Category handler' ).main
return p
</syntaxhighlight>
</source>
 
The above example will categorize in all namespaces, but not on blacklisted pages. If you want to demonstrate that module on a page, then use "<code>nocat=true</code>" to prevent the template from categorizing.
The all parameter can also be combined with the rest of the parameters. Like this:
 
<sourcesyntaxhighlight lang="lua">
p = {}
local categoryHandler = require( 'Module:Category handler' ).main
return p
</syntaxhighlight>
</source>
 
If the above module 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.
The category handler module understands the '''subpage''' parameter. Like this:
 
<sourcesyntaxhighlight lang="lua">
p = {}
local categoryHandler = require( 'Module:Category handler' ).main
return p
</syntaxhighlight>
</source>
 
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.
Besides from categories, you can feed anything else to this module, for instance some text. Like this:
 
<sourcesyntaxhighlight lang="lua">
p = {}
local categoryHandler = require( 'Module:Category handler' ).main
 
return p
</syntaxhighlight>
</source>
 
When the module code above is used on anything other than a talk page, it will look like this:
For testing and demonstration purposes this module can take a parameter named '''page'''. Like this:
 
<sourcesyntaxhighlight lang="lua">
p = {}
local categoryHandler = require( 'Module:Category handler' ).main
return p
</syntaxhighlight>
</source>
 
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:
You can make it so your module 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:
 
<sourcesyntaxhighlight lang="lua">
p = {}
local categoryHandler = require( 'Module:Category handler' ).main
 
return p
</syntaxhighlight>
</source>
 
=== Parameters ===
13,041

edits