Difference between revisions of "Template:Main talk other flex/doc"

From blackwiki
Jump to navigation Jump to search
test>Davidgothberg
(Added: "(We just discovered that switch cases ''can'' handle empty strings...)" I don't want to spread faulty knowledge.)
test>Davidgothberg
(/ * About the code */ Updating the explanation since the code has changed. (But no change in functionality.))
Line 14: Line 14:
 
=== About the code ===
 
=== About the code ===
  
The lines "<code><nowiki>| x{{NAMESPACE}}</nowiki></code>" and "<code><nowiki>| x =</nowiki></code>" probably needs some explanation. The reason we do like that is because mainspace (articlespace) doesn't have a name, so for mainspace the magic word <nowiki>{{NAMESPACE}}</nowiki> returns an empty string. <s>But switch cases can not handle empty strings.</s> Thus we need to make the string non-empty in some way. The easiest way is to simply add an "x" to it. Thus "x+nothing = x" and namespace then has the name "x" in the switch case. As a side effect all the other namespaces start with an x too. (We just discovered that switch cases ''can'' handle empty strings...)
+
The line "<code><nowiki>| {{lc:{{ns:0}}}} = </nowiki></code>" probably needs some explanation. Currently mainspace (article space) doesn't have a name, so for mainspace the magic word <nowiki>{{NAMESPACE}}</nowiki> returns an empty string. Fortunately MediaWiki switch-cases can handle empty strings. So that line could simply be "<code><nowiki>| = </nowiki></code>". But just in case the mainspace ever gets a name we use the "<code><nowiki>{{ns:0}}</nowiki></code>" which should give the name of namespace 0, that is mainspace. And since we lower case the input then we also have to lower case the value we compare, thus we add "<code><nowiki>{{lc:}}</nowiki></code>". Another reason we use that code is in-case people want to reuse that approach for the other namespaces when they reuse this code elsewhere. It would be especially useful when porting this template to an other language Wikipedia or other Wikimedia project.
 
 
  
 
<includeonly>
 
<includeonly>

Revision as of 19:59, 18 April 2008

This is the {{main talk other flex}} template.

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

Documentation for all these templates are at {{main talk other}}.

This template works exactly the same as the {{main talk other}} template, but it has some minor internal differences. The documentation at {{main talk other}} covers some of the differences, the rest are explained below.

Note! Do not optimise or cut away any "unnecessary" parts of the code in this template. This code serves as an example to copy and paste from and then modify, when one wants to make other templates that detect more complex namespace combinations. That's why the code contains a full list of the Wikipedia namespaces, even for the "other" case.

About the code

The line "| {{lc:{{ns:0}}}} = " probably needs some explanation. Currently mainspace (article space) doesn't have a name, so for mainspace the magic word {{NAMESPACE}} returns an empty string. Fortunately MediaWiki switch-cases can handle empty strings. So that line could simply be "| = ". But just in case the mainspace ever gets a name we use the "{{ns:0}}" which should give the name of namespace 0, that is mainspace. And since we lower case the input then we also have to lower case the value we compare, thus we add "{{lc:}}". Another reason we use that code is in-case people want to reuse that approach for the other namespaces when they reuse this code elsewhere. It would be especially useful when porting this template to an other language Wikipedia or other Wikimedia project.