Module:Namespace detect/doc: Difference between revisions
(→Porting to different wikis: remove redundancy) |
(lua) |
||
(28 intermediate revisions by 16 users not shown) | |||
Line 1: | Line 1: | ||
{{Used in system}} |
|||
{{Module rating|protected}} |
|||
{{Lua|Module:Namespace detect/data|Module:Yesno|Module:Arguments|Module:TableTools}} |
|||
This module allows you to output different text depending on the [[WP:NAMESPACE|namespace]] that a given page is in. It is a [[WP:Lua|Lua]] implementation of the {{tl|namespace detect}} template, with a few improvements: all namespaces and all namespace aliases are supported, and namespace names are detected automatically for the local wiki. |
This module allows you to output different text depending on the [[WP:NAMESPACE|namespace]] that a given page is in. It is a [[WP:Lua|Lua]] implementation of the {{tl|namespace detect}} template, with a few improvements: all namespaces and all namespace aliases are supported, and namespace names are detected automatically for the local wiki. |
||
Line 14: | Line 18: | ||
| user = |
| user = |
||
| wikipedia = |
| wikipedia = |
||
| wp = |
|||
| education program = |
|||
| mediawiki = |
| mediawiki = |
||
| book = |
| book = |
||
Line 29: | Line 31: | ||
| other = <!-- text to return for unspecified namespaces --> |
| other = <!-- text to return for unspecified namespaces --> |
||
| demospace = <!-- namespace to display text for --> |
| demospace = <!-- namespace to display text for --> |
||
| subjectns = <!-- set to "yes" to treat talk pages as the corresponding subject page --> |
|||
}} |
}} |
||
</pre> |
</pre> |
||
Line 34: | Line 38: | ||
== Parameters == |
== Parameters == |
||
⚫ | |||
* '''main''' - text to return if the page is in the main namespace. |
* '''main''' - text to return if the page is in the main namespace. |
||
* '''talk''' - text to return if the page is in a talk namespace. This can be any talk namespace - it will match any of "Talk:", "Wikipedia talk:", "User talk:", etc. |
* '''talk''' - text to return if the page is in a talk namespace. This can be any talk namespace - it will match any of "Talk:", "Wikipedia talk:", "User talk:", etc. |
||
* Subject namespace parameters, e.g. '''wikipedia''', '''user''', '''file'''... - the text to return if the page is in the corresponding namespace. This module accepts all subject namespaces as parameters, including [[Wikipedia:Namespace#Aliases|namespace aliases]] and [[Wikipedia:Namespace#Virtual namespaces|virtual namespaces]]. See below for a list of supported values. |
* Subject namespace parameters, e.g. '''wikipedia''', '''user''', '''file'''... - the text to return if the page is in the corresponding namespace. This module accepts all subject namespaces as parameters, including [[Wikipedia:Namespace#Aliases|namespace aliases]] and [[Wikipedia:Namespace#Virtual namespaces|virtual namespaces]]. See below for a list of supported values. |
||
* '''other''' - text to return if no parameters for the page's namespace were specified. This text is also returned if {{para|demospace}} is set to an invalid namespace value. |
* '''other''' - text to return if no parameters for the page's namespace were specified. This text is also returned if {{para|demospace}} is set to an invalid namespace value. |
||
* '''subjectns''' - if on a talk page, use the corresponding subject page. Can be set with values of "yes", "y", "true" or "1". |
|||
⚫ | |||
* '''demospace''' - force the module to behave as if the page was in the specified namespace. Often used for demonstrations. |
* '''demospace''' - force the module to behave as if the page was in the specified namespace. Often used for demonstrations. |
||
Line 46: | Line 51: | ||
{{#invoke:Namespace detect|table}} |
{{#invoke:Namespace detect|table}} |
||
== Table function == |
|||
Use the following to display a table with the different possible namespace parameters: |
|||
{{#invoke:Namespace detect|table|talk=''yes''}} |
|||
To include the parameter for talk namespaces, use {{para|talk|yes}}. |
|||
== Porting to different wikis == |
== Porting to different wikis == |
||
This module is designed to be portable. To use it on a different wiki, |
This module is designed to be portable. To use it on a different wiki, all you need to do is to change the values in [[Module:Namespace detect/config]]. Instructions are available on that page. |
||
== Technical details == |
|||
The module uses a data page at [[Module:Namespace detect/data]]. This page is loaded with [[mw:Extension:Scribunto/Lua reference manual#mw.loadData|mw.loadData]], which means it is processed once per page rather than once per #invoke. This was done for performance reasons. |
Latest revision as of 14:21, 1 April 2023
![]() | This Lua module is used in system messages, and on approximately 16,000,000 pages, or roughly 27% of all pages. Changes to it can cause immediate changes to the Wikipedia user interface. To avoid major disruption and server load, any changes should be tested in the module's /sandbox or /testcases subpages, or in your own module sandbox. The tested changes can be added to this page in a single edit. Please discuss changes on the talk page before implementing them. |
![]() | This module depends on the following other modules: |
This module allows you to output different text depending on the namespace that a given page is in. It is a Lua implementation of the {{namespace detect}} template, with a few improvements: all namespaces and all namespace aliases are supported, and namespace names are detected automatically for the local wiki.
Usage[edit]
{{#invoke: Namespace detect | main | page = <!-- page to detect namespace for, if not the current page --> | main = <!-- text to return for the main namespace --> | talk = <!-- text to return for talk namespaces --> <!-- text to return for specific subject namespaces --> | portal = | category = | user = | wikipedia = | mediawiki = | book = | timedtext = | template = | special = | media = | file = | image = | help = | module = | other = <!-- text to return for unspecified namespaces --> | demospace = <!-- namespace to display text for --> | subjectns = <!-- set to "yes" to treat talk pages as the corresponding subject page --> }}
Parameters[edit]
- main - text to return if the page is in the main namespace.
- talk - text to return if the page is in a talk namespace. This can be any talk namespace - it will match any of "Talk:", "Wikipedia talk:", "User talk:", etc.
- Subject namespace parameters, e.g. wikipedia, user, file... - the text to return if the page is in the corresponding namespace. This module accepts all subject namespaces as parameters, including namespace aliases and virtual namespaces. See below for a list of supported values.
- other - text to return if no parameters for the page's namespace were specified. This text is also returned if
|demospace=
is set to an invalid namespace value. - subjectns - if on a talk page, use the corresponding subject page. Can be set with values of "yes", "y", "true" or "1".
- demopage - specifies a page to detect the namespace of. If not specified, and if the
|demospace=
parameter is not set, then the module uses the current page. - demospace - force the module to behave as if the page was in the specified namespace. Often used for demonstrations.
Namespace parameters[edit]
Possible values for subject namespace parameters are as follows:
Namespace | Aliases |
---|---|
main
|
|
user
|
|
wikipedia
|
project , wp
|
file
|
image
|
mediawiki
|
|
template
|
|
help
|
|
category
|
|
portal
|
|
draft
|
|
timedtext
|
|
module
|
|
gadget
|
|
gadget definition
|
Table function[edit]
Use the following to display a table with the different possible namespace parameters:
{{#invoke:Namespace detect|table|talk=yes}}
To include the parameter for talk namespaces, use |talk=yes
.
Porting to different wikis[edit]
This module is designed to be portable. To use it on a different wiki, all you need to do is to change the values in Module:Namespace detect/config. Instructions are available on that page.
Technical details[edit]
The module uses a data page at Module:Namespace detect/data. This page is loaded with mw.loadData, which means it is processed once per page rather than once per #invoke. This was done for performance reasons.