Difference between revisions of "Template:Normalized pagename/doc"

From Yugipedia
Jump to: navigation, search
(create)
(Tags: Mobile edit, Mobile web edit)
 
(lang=html on <syntaxhighlight> tags)
Line 7: Line 7:
 
== Technical details ==
 
== Technical details ==
 
=== Characters in page names ===
 
=== Characters in page names ===
Several different characters may be replaced by <code><nowiki>{{FULLPAGENAME}}</nowiki></code> and related magic words. The replacements made for a particular title can be viewed using the code <code class="nowrap"><nowiki>{{ #tag: syntaxhighlight | {{PAGENAME:</nowiki>''Title''<nowiki>}} }}</nowiki></code>; for instance, for the title <code class="nowrap">"We'll Be There" - Rex & Weevil</code>, this code produces <span class="nowrap">{{ #tag: syntaxhighlight | {{PAGENAME:"We'll Be There" - Rex & Weevil}} | inline=yes }}</span>.
+
Several different characters may be replaced by <code><nowiki>{{FULLPAGENAME}}</nowiki></code> and related magic words. The replacements made for a particular title can be viewed using the code <code class="nowrap"><nowiki>{{ #tag: syntaxhighlight | {{PAGENAME:</nowiki>''Title''<nowiki>}} }}</nowiki></code>; for instance, for the title <code class="nowrap">"We'll Be There" - Rex & Weevil</code>, this code produces <span class="nowrap">{{ #tag: syntaxhighlight | {{PAGENAME:"We'll Be There" - Rex & Weevil}} | lang=html | inline=yes }}</span>.
  
 
On this wiki, the following character replacements are made by <code><nowiki>{{FULLPAGENAME}}</nowiki></code> and related magic words. Note that because a lone period (<code>.</code>) is not output (it represents the [[wikipedia:Working directory|working directory]] in Unix-like systems and Microsoft Windows) and a leading colon (<code>:''foo''</code>) is stripped, they are prefixed by a capital "A"; the other characters are also prefixed for consistency. The asterisk (<code>*</code>) is also shown preceding the "A" since when it is the leading character (<code>*''foo''</code>), it gets replaced with a character reference. The characters <code class="nowrap"><nowiki>&lt; &gt; [ ] { | }</nowiki></code> are illegal in page titles in MediaWiki, and the character <code>#</code> introduces the [[wikipedia:Fragment identifier|fragment identifier]] in URLs, so these characters are not listed below (<code><nowiki>{{FULLPAGENAME}}</nowiki></code> and related magic words will strip these characters, or output nothing, when they are passed in).
 
On this wiki, the following character replacements are made by <code><nowiki>{{FULLPAGENAME}}</nowiki></code> and related magic words. Note that because a lone period (<code>.</code>) is not output (it represents the [[wikipedia:Working directory|working directory]] in Unix-like systems and Microsoft Windows) and a leading colon (<code>:''foo''</code>) is stripped, they are prefixed by a capital "A"; the other characters are also prefixed for consistency. The asterisk (<code>*</code>) is also shown preceding the "A" since when it is the leading character (<code>*''foo''</code>), it gets replaced with a character reference. The characters <code class="nowrap"><nowiki>&lt; &gt; [ ] { | }</nowiki></code> are illegal in page titles in MediaWiki, and the character <code>#</code> introduces the [[wikipedia:Fragment identifier|fragment identifier]] in URLs, so these characters are not listed below (<code><nowiki>{{FULLPAGENAME}}</nowiki></code> and related magic words will strip these characters, or output nothing, when they are passed in).
Line 35: Line 35:
 
A` {{PAGENAME: A` }}
 
A` {{PAGENAME: A` }}
 
A~ {{PAGENAME: A~ }}
 
A~ {{PAGENAME: A~ }}
}}
+
| lang=html }}
  
 
=== Replacements ===
 
=== Replacements ===
Line 68: Line 68:
  
 
=== Why not <code>#titleparts</code>? ===
 
=== Why not <code>#titleparts</code>? ===
{{tl|Normalized pagename}} is written using the [[mw:Special:MyLanguage/Extension:StringFunctions##replace:|<code>#replace</code> string function]], even though the [[mw:Special:MyLanguage/Help:Extension:ParserFunctions##titleparts|<code>#titleparts</code> parser function]] can perform the same task without requiring multiple functions: <code class="nowrap"><nowiki>{{ #titleparts: {{PAGENAME:"We'll Be There" - Rex & Weevil}} }}</nowiki></code> → <span class="nowrap">{{ #tag: syntaxhighlight | {{ #titleparts: {{PAGENAME:"We'll Be There" - Rex & Weevil}} }} | inline=yes }}</span>. This is because <code>#titleparts</code> automatically strips any content after a hash (<code>#</code>), including the hash itself. <code><nowiki>{{FULLPAGENAME}}</nowiki></code> and related magic words also strip this content from input, but {{tl|Normalized pagename}} may be passed raw strings directly, without using any magic words, and these strings may contain hashes which should not affect the output. For example, the string <code class="nowrap">Nekogal #2</code> results in the following outputs:
+
{{tl|Normalized pagename}} is written using the [[mw:Special:MyLanguage/Extension:StringFunctions##replace:|<code>#replace</code> string function]], even though the [[mw:Special:MyLanguage/Help:Extension:ParserFunctions##titleparts|<code>#titleparts</code> parser function]] can perform the same task without requiring multiple functions: <code class="nowrap"><nowiki>{{ #titleparts: {{PAGENAME:"We'll Be There" - Rex & Weevil}} }}</nowiki></code> → <span class="nowrap">{{ #tag: syntaxhighlight | {{ #titleparts: {{PAGENAME:"We'll Be There" - Rex & Weevil}} }} | lang=html | inline=yes }}</span>. This is because <code>#titleparts</code> automatically strips any content after a hash (<code>#</code>), including the hash itself. <code><nowiki>{{FULLPAGENAME}}</nowiki></code> and related magic words also strip this content from input, but {{tl|Normalized pagename}} may be passed raw strings directly, without using any magic words, and these strings may contain hashes which should not affect the output. For example, the string <code class="nowrap">Nekogal #2</code> results in the following outputs:
 
* <code><nowiki>{{PAGENAME:Nekogal #2}}</nowiki></code> → {{PAGENAME:Nekogal #2}}
 
* <code><nowiki>{{PAGENAME:Nekogal #2}}</nowiki></code> → {{PAGENAME:Nekogal #2}}
 
* <code><nowiki>{{ #titleparts: Nekogal #2 }}</nowiki></code> → {{ #titleparts: Nekogal #2 }}
 
* <code><nowiki>{{ #titleparts: Nekogal #2 }}</nowiki></code> → {{ #titleparts: Nekogal #2 }}

Revision as of 18:03, 1 September 2018

{{Normalized pagename}} is a template which normalizes a page's name, as returned by {{FULLPAGENAME}} and other page name magic words, by replacing numeric character references and character entity references (collectively, "character references") with the actual character (for instance, &quot; is replaced with "). This is most often useful when using the #ifeq parser function to compare the value of these magic words with values passed into a template via a parameter.

By default, {{Normalized pagename}} uses {{FULLPAGENAME}}, but it accepts an unnamed parameter allowing other values to be used, e.g. {{Normalized pagename|{{PAGENAME}}}}.

Technical details

Characters in page names

Several different characters may be replaced by {{FULLPAGENAME}} and related magic words. The replacements made for a particular title can be viewed using the code {{ #tag: syntaxhighlight | {{PAGENAME:Title}} }}; for instance, for the title "We'll Be There" - Rex & Weevil, this code produces &#34;We&#39;ll Be There&#34; - Rex &#38; Weevil.

On this wiki, the following character replacements are made by {{FULLPAGENAME}} and related magic words. Note that because a lone period (.) is not output (it represents the working directory in Unix-like systems and Microsoft Windows) and a leading colon (:foo) is stripped, they are prefixed by a capital "A"; the other characters are also prefixed for consistency. The asterisk (*) is also shown preceding the "A" since when it is the leading character (*foo), it gets replaced with a character reference. The characters < > [ ] { | } are illegal in page titles in MediaWiki, and the character # introduces the fragment identifier in URLs, so these characters are not listed below ({{FULLPAGENAME}} and related magic words will strip these characters, or output nothing, when they are passed in).

A! A!
A" A&#34;
A$ A$
A% A%
A& A&#38;
A' A&#39;
A( A(
A) A)
A* A*
*A &#42;A
A+ A+
A, A,
A. A.
A/ A/
A: A:
A; A&#59;
A= A&#61;
A? A?
A@ A@
A\ A\
A^ A^
A_ A
A` A`
A~ A~

Replacements

{{Normalized pagename}} performs the following replacements.

Numeric character reference Character entity reference Character
&#34; &quot; "
&#38; &amp; &
&#39; &apos; '
&#59; ;
&#61; =

Why not #titleparts?

{{Normalized pagename}} is written using the #replace string function, even though the #titleparts parser function can perform the same task without requiring multiple functions: {{ #titleparts: {{PAGENAME:"We'll Be There" - Rex & Weevil}} }}"We'll Be There" - Rex & Weevil. This is because #titleparts automatically strips any content after a hash (#), including the hash itself. {{FULLPAGENAME}} and related magic words also strip this content from input, but {{Normalized pagename}} may be passed raw strings directly, without using any magic words, and these strings may contain hashes which should not affect the output. For example, the string Nekogal #2 results in the following outputs:

  • {{PAGENAME:Nekogal #2}} → Nekogal
  • {{ #titleparts: Nekogal #2 }} → Nekogal
  • {{Normalized pagename|Nekogal #2}} → Nekogal #2