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

From Yugipedia
Jump to: navigation, search
(lang=html on <syntaxhighlight> tags)
(update to account for the module implementation)
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{Documentation subpage}}
 
{{Documentation subpage}}
 
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
 
<!-- PLEASE ADD CATEGORIES AND INTERWIKIS AT THE BOTTOM OF THIS PAGE -->
 +
{{Lua|Module:Normalized pagename}}
 +
 
{{tl|Normalized pagename}} is a template which [[wikipedia:Data normalization|normalizes]] a page's name, as returned by <code><nowiki>{{FULLPAGENAME}}</nowiki></code> and other [[mw:Special:MyLanguage/Help:Magic words#Page names|page name magic words]], by replacing [[wikipedia:Numeric character reference|numeric character references]] and [[wikipedia:List of XML and HTML character entity references|character entity references]] (collectively, "character references") with the actual character (for instance, <code>&amp;quot;</code> is replaced with <code>"</code>). This is most often useful when using the [[mw:Special:MyLanguage/Help:Extension:ParserFunctions##ifeq|<code>#ifeq</code> parser function]] to compare the value of these magic words with values passed into a template via a parameter.
 
{{tl|Normalized pagename}} is a template which [[wikipedia:Data normalization|normalizes]] a page's name, as returned by <code><nowiki>{{FULLPAGENAME}}</nowiki></code> and other [[mw:Special:MyLanguage/Help:Magic words#Page names|page name magic words]], by replacing [[wikipedia:Numeric character reference|numeric character references]] and [[wikipedia:List of XML and HTML character entity references|character entity references]] (collectively, "character references") with the actual character (for instance, <code>&amp;quot;</code> is replaced with <code>"</code>). This is most often useful when using the [[mw:Special:MyLanguage/Help:Extension:ParserFunctions##ifeq|<code>#ifeq</code> parser function]] to compare the value of these magic words with values passed into a template via a parameter.
  
Line 56: Line 58:
 
| <code>&amp;apos;</code>
 
| <code>&amp;apos;</code>
 
| <code>'</code>
 
| <code>'</code>
 +
|-
 +
| <code>&amp;#42;</code>
 +
| —
 +
| <code>*</code>
 
|-
 
|-
 
| <code>&amp;#59;</code>
 
| <code>&amp;#59;</code>
Line 66: Line 72:
 
|-
 
|-
 
|}
 
|}
 
=== 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}} }} | 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>{{ #titleparts: Nekogal #2 }}</nowiki></code> → {{ #titleparts: Nekogal #2 }}
 
* <code><nowiki>{{Normalized pagename|Nekogal #2}}</nowiki></code> → {{Normalized pagename|Nekogal #2}}
 
  
 
<includeonly>
 
<includeonly>

Revision as of 21:41, 4 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; '
&#42; *
&#59; ;
&#61; =