"模板:Namespace detect/doc" 修訂間的差異

出自 陳富國維基館
前往: 導覽搜尋
(机器人添加:eo:Ŝablono:Determinas nomspacon)
(1個修訂)
行 1: 行 1:
<includeonly><!-- 在這裡加入模板的保護標識 --></includeonly>
+
{{documentation subpage}}
{{Documentation subpage}}
 
{{high-use| 65,000+ }}
 
 
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
 
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
  
行 8: 行 6:
 
It helps other templates detect what type of page they are on.
 
It helps other templates detect what type of page they are on.
  
It detects and groups all the different [[帮助:名字空间#Enumeration|namespaces]] used on Wikipedia into several types:
+
It detects and groups all the different [[Project:Namespaces|namespaces]] used on MediaWiki.org into several types:
  
:'''main''' = Main/article space, as in normal Wikipedia articles.
+
:'''main''' = Main/article space, as in normal MediaWiki.org 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, wikipedia, file, mediawiki, template, help, category''' and '''portal''' = The other namespaces except the talk pages.
+
:'''user, project, file, mediawiki, template, help, category''', and '''book''' = The other namespaces except the talk pages.
 
:'''other''' = Any namespaces that were not specified as a parameter to the template. See explanation below.
 
:'''other''' = Any namespaces that were not specified as a parameter to the template. See explanation below.
  
行 19: 行 17:
 
'''Note!''' For most usage cases it might be better to use the simpler namespace detection templates. (See the [[#See also|see also]] section below.) Since this template is more prone to human errors such as misspelling the parameter names.  
 
'''Note!''' For most usage cases it might be better to use the simpler namespace detection templates. (See the [[#See also|see also]] section below.) Since this template is more prone to human errors such as misspelling the parameter names.  
  
=== 用法 ===
+
=== Usage ===
 
 
 
This template takes one or more parameters named after the different page types as listed above. Like this:
 
This template takes one or more parameters named after the different page types as listed above. Like this:
  
行 81: 行 78:
 
}}
 
}}
  
=== Demospace ===
+
=== Demospace and page ===
 +
For testing and demonstration purposes this template can take two parameters named '''demospace''' and '''page'''.
  
For testing and demonstration purposes this template can take a parameter named '''demospace'''. Demospace understands any of the page type names used by this template, including the '''other''' type. It tells the template to behave like it is on some specific type of page. Like this:
+
Demospace understands any of the page type names used by this template, including the '''other''' type. It tells the template to behave like it is on some specific type of page. Like this:
  
 
<pre>
 
<pre>
行 101: 行 99:
 
}}
 
}}
  
It can be convenient to let your template understand the demospace parameter and send it on to the {{tl|namespace detect}} template. Then do like this:
+
The '''page''' parameter instead takes a normal pagename. It makes this template behave exactly as if on that page. The pagename doesn't have to be an existing page. Like this:
 +
 
 +
<pre>
 +
{{namespace detect
 +
| user  = User page text
 +
| other = Other pages text
 +
| page = User:Example
 +
}}
 +
</pre>
 +
 
 +
No matter on what kind of page the code above is used it will return this:
 +
 
 +
:{{namespace detect
 +
| user  = User page text
 +
| other = Other pages text
 +
| page = User:Example
 +
}}
 +
 
 +
It can be convenient to let your template understand the demospace and/or page parameter and send it on to the {{tl|namespace detect}} template. Then do like this:
  
 
<pre>
 
<pre>
行 108: 行 124:
 
| other = Other pages text
 
| other = Other pages text
 
| demospace = {{{demospace|}}}
 
| demospace = {{{demospace|}}}
 +
| page  = {{{page|}}}
 
}}
 
}}
 
</pre>
 
</pre>
  
If the '''demospace''' parameter is empty or undefined then the template will detect page types as usual.
+
If both the '''demospace''' and '''page''' parameters are empty or undefined then the template will detect page types as usual.
  
 
=== Parameters ===
 
=== Parameters ===
 
 
List of all parameters:
 
List of all parameters:
  
行 123: 行 139:
 
| other =
 
| other =
 
| demospace = {{{demospace|}}} / main / talk / user /  
 
| demospace = {{{demospace|}}} / main / talk / user /  
               wikipedia / file / mediawiki / template /  
+
               project / file / mediawiki / template /  
               help / category / portal / other
+
               help / category / book / other
 +
| page  = {{{page|}}} / User:Example
 
}}
 
}}
 
</pre>
 
</pre>
  
Note: Empty values to the "main" ... "portal" parameters do have special meaning.
+
Note: Empty values to the "main" ... "book" parameters have special meaning.
  
 
=== Technical details ===
 
=== Technical details ===
 
Namespace "Image" was renamed to "File" on 11 December 2008. This template was updated to understand both names well before that, thus it still works fine. For backwards compatibility it still understands "image" both as a parameter name, such as "image = File page text", and as a value "demospace = image".
 
 
 
If you intend to feed tables as content to the numbered parameters of this template, then you need to know this:
 
If you intend to feed tables as content to the numbered parameters of this template, then you need to know this:
  
[[Help:Template|Templates]] do have a problem to handle parameter data that contains pipes "<code>|</code>", unless the pipe is inside another template <code><nowiki>{{name|param1}}</nowiki></code> or inside a piped link <code><nowiki>[[帮助:模板|help]]</nowiki></code>. Thus templates can not handle [[帮助:表格|wikitables]] as input unless you escape them by using the {{tn|!}} template. This makes it hard to use wikitables as parameters to templates. Instead the usual solution is to use "[[Help:HTML in wikitext|HTML wikimarkup]]" for the table code, which is more robust.
+
[[Help:Template|Templates]] do have a problem to handle parameter data that contains pipes "<code>|</code>", unless the pipe is inside another template <code><nowiki>{{name|param1}}</nowiki></code> or inside a piped link <code><nowiki>[[Help:Template|help]]</nowiki></code>. Thus templates can not handle [[Help:Table|wikitables]] as input unless you escape them by using the {{tn|!}} template. This makes it hard to use wikitables as parameters to templates. Instead the usual solution is to use "[[w:Help:HTML in wikitext|HTML wikimarkup]]" for the table code, which is more robust.
 
 
For more technical details such as about "copying to other projects" and "CSS based namespace detection" see {{tl|main talk other}} and its talk page.
 
 
 
=== 參見 ===
 
 
 
{{namespace detect see also}}
 
  
 
<includeonly>
 
<includeonly>
<!-- 本行下加入模板的分類 -->
+
<!-- CATEGORIES AND INTERWIKIS HERE, THANKS -->
[[Category:維基百科元模板]]
+
[[Category:Utility templates]]
 
 
<!-- 本行下加入模板的跨語言鏈接 -->
 
 
 
[[ar:قالب:كشف نطاق]]
 
[[ba:Ҡалып:Namespace detect]]
 
[[be:Шаблон:Namespace detect]]
 
[[be-x-old:Шаблён:Вызначэньне прасторы назваў]]
 
[[bjn:Citakan:Namespace detect]]
 
[[bn:টেমপ্লেট:Namespace detect]]
 
[[ca:Plantilla:Detecta espai de noms]]
 
[[cy:Nodyn:Namespace detect]]
 
[[dsb:Pśedłoga:Namespace detect]]
 
[[dv:ފަންވަތް:Namespace detect]]
 
[[en:Template:Namespace detect]]
 
[[eo:Ŝablono:Determinas nomspacon]]
 
[[fa:الگو:Namespace detect]]
 
[[hi:साँचा:Namespace detect]]
 
[[hif:Template:Namespace detect]]
 
[[hsb:Předłoha:Namespace detect]]
 
[[ko:틀:이름공간 검출]]
 
[[hu:Sablon:Namespace detect]]
 
[[ja:Template:Namespace detect]]
 
[[map-bms:Cithakan:Namespace detect]]
 
[[mhr:Кышкар:Namespace detect]]
 
[[mn:Загвар:Namespace detect]]
 
[[mzn:شابلون:Namespace detect]]
 
[[no:Mal:Namespace detect]]
 
[[pa:ਫਰਮਾ:Namespace detect]]
 
[[pam:Template:Namespace detect]]
 
[[pt:Predefinição:Namespace detect]]
 
[[ru:Шаблон:Namespace detect]]
 
[[sl:Predloga:Namespace detect]]
 
[[sr:Шаблон:Namespace detect]]
 
[[tt:Калып:Namespace detect]]
 
[[uk:Шаблон:Namespace detect]]
 
[[ur:سانچہ:Namespace detect]]
 
 
</includeonly>
 
</includeonly>

於 2013年3月15日 (五) 12:48 的修訂

This is the {{namespace detect}} meta-template.

It helps other templates detect what type of page they are on.

It detects and groups all the different namespaces used on MediaWiki.org into several types:

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

For backwards compatibility this template also understands the old name image for file. But using image is now deprecated.

Note! For most usage cases it might be better to use the simpler namespace detection templates. (See the see also section below.) Since this template is more prone to human errors such as misspelling the parameter names.

Usage

This template takes one or more parameters named after the different page types as listed above. Like this:

{{namespace detect
| main  = Article text
| talk  = Talk page text
| other = Other pages text
}}

If the template is on a main (article) page, it will return this:

Article text

If the template is on any other page than an article or a talk page it will return this:

Other pages text

The example above made the template return something for all page types. But if we don't use the other parameter or leave it empty then it will not return anything for the other page types. Like this:

{{namespace detect
| file     = File page text
| category = Category page text
| other    =
}}

On any pages other than file and category pages the code above will render nothing.

By using an empty parameter you can make it so the template doesn't render anything for some specific page type. Like this:

{{namespace detect
| main  = 
| other = Other pages text
}}

The code above will render nothing when on mainspace (article) pages, but will return this when on other pages:

Other pages text

Demospace and page

For testing and demonstration purposes this template can take two parameters named demospace and page.

Demospace understands any of the page type names used by this template, including the other type. It tells the template to behave like it is on some specific type of page. Like this:

{{namespace detect 
| main  = Article text
| other = Other pages text
| demospace = main
}}

No matter on what kind of page the code above is used it will return this:

Article text

The page parameter instead takes a normal pagename. It makes this template behave exactly as if on that page. The pagename doesn't have to be an existing page. Like this:

{{namespace detect 
| user  = User page text
| other = Other pages text
| page = User:Example
}}

No matter on what kind of page the code above is used it will return this:

Other pages text

It can be convenient to let your template understand the demospace and/or page parameter and send it on to the {{namespace detect}} template. Then do like this:

{{namespace detect 
| main  = Article text
| other = Other pages text
| demospace = {{{demospace|}}}
| page  = {{{page|}}}
}}

If both the demospace and page parameters are empty or undefined then the template will detect page types as usual.

Parameters

List of all parameters:

{{namespace detect
| main  = 
...
| other =
| demospace = {{{demospace|}}} / main / talk / user / 
              project / file / mediawiki / template / 
              help / category / book / other
| page  = {{{page|}}} / User:Example
}}

Note: Empty values to the "main" ... "book" parameters have special meaning.

Technical details

If you intend to feed tables as content to the numbered parameters of this template, then you need to know this:

Templates do have a problem to handle parameter data that contains pipes "|", unless the pipe is inside another template {{name|param1}} or inside a piped link [[Help:Template|help]]. Thus templates can not handle wikitables as input unless you escape them by using the start{{{in}}}end template. This makes it hard to use wikitables as parameters to templates. Instead the usual solution is to use "HTML wikimarkup" for the table code, which is more robust.