Difference between revisions of "Template:Citation/make link"

From blackwiki
Jump to navigation Jump to search
imported>Fullstop
(add check if #titleparts does anything)
imported>Eubulides
(Fix problem with wikilinks to articles whose names do not begin with a letter, e.g., ! (album). See Template:Citation/make link/testcases.)
Line 1: Line 1:
{{#switch:{{#titleparts:{{lcfirst:{{{1|}}}}}|2}}
+
{{#switch:{{#titleparts:x{{{1|}}}|2}}
  |<!--if empty-->|None = {{{2}}}
+
  |X|Xnone|XNone = {{{2}}}
  |Http:/|Https:/|Ftp:/|{{lcfirst:{{{1|}}}}} = [{{{1}}} {{{2}}}]
+
  |Xhttp:/|Xhttps:/|Xftp:/|x{{{1|}}} = [{{{1}}} {{{2}}}]
  |#default             = [[:{{{1}}}|{{{2}}}]]
+
  |#default = [[:{{{1}}}|{{{2}}}]]
 
}}<noinclude>
 
}}<noinclude>
 
<!-- Code notes (here so that people /read/ it)  
 
<!-- Code notes (here so that people /read/ it)  
   1. Parameter #2 is always non-empty when called from {{Citation/core}}.
+
   1. Parameter #2 is always nonempty when called from {{Citation/core}}.
 
   2. It's up to {{Citation/core}} to stop italicized "'foo' & 'bar'" from becoming  
 
   2. It's up to {{Citation/core}} to stop italicized "'foo' & 'bar'" from becoming  
 
     "'''foo' & 'bar'''". Citation/core does this by having a <nowiki></nowiki>  
 
     "'''foo' & 'bar'''". Citation/core does this by having a <nowiki></nowiki>  
 
     at both beginning and end of the call to this template. Since this is only  
 
     at both beginning and end of the call to this template. Since this is only  
     needed once, it's more efficient to do it in citation/core than here.
+
     needed once, it's more efficient to do it in {{Citation/core}} than here.
 
   3. "None" is safe to use as a magic word here, as the Wikipedia article [[None]] is
 
   3. "None" is safe to use as a magic word here, as the Wikipedia article [[None]] is
 
     not about a book or chapter.
 
     not about a book or chapter.
 
   4. The colon in "[[:" prevents images from being expanded.
 
   4. The colon in "[[:" prevents images from being expanded.
   5. The lcfirst checks if #titleparts does anything. That is, if the result
+
   5. The leading "x" checks whether #titleparts rejected the argument as not
     of #titleparts has a lowecase first letter, then #titleparts passed through
+
    being a valid page title. For example, if the argument contains "%" it is
     the parameter unchanged, meaning the string was not a valid article title.
+
     not a valid page title, and #titleparts returns it unchanged instead of
 +
     upper-casing the "x".
 
-->
 
-->
 
{{documentation}}
 
{{documentation}}
 
</noinclude>
 
</noinclude>

Revision as of 05:36, 2 August 2009

{{{2}}}

Template documentation[view] [edit] [history] [purge]

This template is a "subroutine" of {{Citation/core}} used for conditionally making links for the chapter= and title= fields in a citation.

It is invoked as:

{{Citation/make link
| 1 = <value of IncludedWorkURL= or URL= or PMC= parameters>
| 2 = <value of IncludedWorkTitle= or Title= parameters>
}}

It uses the following algorithm:

  1. If the first parameter is empty, it returns the second parameter as plain text.
  2. If the first parameter is a URL, it returns the second parameter wrapped inside an external link to the first.

This "subroutine" is designed for {{Citation/core}} and makes assumptions that may not be valid elsewhere.

Examples:

  • "{{Citation/make link||BBC News front page}}" produces "BBC News front page".
  • "{{Citation/make link|http://news.bbc.co.uk/|BBC News front page}}" produces "BBC News front page".